From e3ee682b8d523dd015437eb176931f2a9fbdaa51 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 12 Aug 2021 12:46:07 +0900 Subject: [PATCH] Add a file check This patch adds to check whether the file is a regular file or not. If it's not a regular file, the mime_type_get_mime_type_for_file() funtion returns a negative error value. Change-Id: I832fea354bc01561db7030a5a6f75b7f92644ebe Signed-off-by: Hwankyu Jhun --- mime-type/mime_type.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mime-type/mime_type.cc b/mime-type/mime_type.cc index f179c65..1d80921 100644 --- a/mime-type/mime_type.cc +++ b/mime-type/mime_type.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include +#include #include #include @@ -128,6 +130,18 @@ EXPORT int mime_type_get_mime_type_for_file(const char* file_path, return MIME_TYPE_ERROR_IO_ERROR; } + struct stat statbuf; + int ret = stat(file_path, &statbuf); + if (ret != 0) { + _E("stat() is failed. path(%s), errno(%d)", file_path, errno); + return MIME_TYPE_ERROR_IO_ERROR; + } + + if (!S_ISREG(statbuf.st_mode)) { + _E("%s is not regular file", file_path); + return MIME_TYPE_ERROR_INVALID_PARAMETER; + } + auto xdg_mime_type = content::XdgMime::GetMimeTypeForFile(file_path); if (xdg_mime_type.empty()) { _E("GetMimeTypeForFile(%s) is failed", file_path); -- 2.7.4