[ACR-1167] Exception handling when path contains symbolic link 24/171024/3 submit/tizen/20180306.091306
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 26 Feb 2018 02:03:51 +0000 (11:03 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 6 Mar 2018 08:07:17 +0000 (08:07 +0000)
Change-Id: I6d68d1edd0df69a4f31eb90260adba4d74bc4349
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/include/media-util-user.h
lib/include/media-util.h
lib/media-util-user.c
src/common/include/media-common-utils.h
src/common/media-common-utils.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner/media-scanner-scan.c

index 9a3e5d5..fd6ffb3 100755 (executable)
@@ -38,6 +38,10 @@ int ms_user_get_root_thumb_store_path(uid_t uid, char **path);
 int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type, char **path);
 int ms_user_get_media_db_path(uid_t uid, char **path);
 
+#ifndef _USE_TVPD_MODE
+int ms_user_get_mediashared_path(uid_t uid, char **path);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 0fc562c..ba5bcc4 100755 (executable)
@@ -38,6 +38,9 @@
 #define MEDIA_ROOT_PATH_EXTERNAL       tzplatform_getenv(TZ_SYS_STORAGE)
 #define MEDIA_ROOT_PATH_SDCARD tzplatform_mkpath(TZ_SYS_STORAGE, "SDCard")
 #define MEDIA_ROOT_PATH_USB            tzplatform_getenv(TZ_SYS_STORAGE)
+#ifndef _USE_TVPD_MODE
+#define MEDIA_SHARE_PATH               tzplatform_getenv(TZ_SYS_MEDIASHARED)
+#endif
 
 #ifdef _USE_SENIOR_MODE
 #define MEDIA_CONTENT_PATH             "content"               /**<  user content folder name*/
index 415feb1..a081d01 100755 (executable)
@@ -35,7 +35,8 @@ typedef enum {
        INTERNAL_ROOT,
        THUMB_ROOT,
        THUMB_INTERNAL,
-       THUMB_EXTERNAL
+       THUMB_EXTERNAL,
+       MEDIA_SHARED
 } ms_user_path_type_e;
 
 #ifdef _USE_SENIOR_MODE
@@ -96,6 +97,9 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
        case THUMB_EXTERNAL:
                result = tzplatform_context_mkpath(context[idx], TZ_USER_SHARE, "media/.thumb/mmc");
                break;
+       case MEDIA_SHARED:
+               result = tzplatform_context_getenv(context[idx], TZ_USER_MEDIASHARED);
+               break;
        default:
                MSAPI_DBG_ERR("Invalid type");
                ret = MS_MEDIA_ERR_INTERNAL;
@@ -217,3 +221,19 @@ int ms_user_get_media_db_path(uid_t uid, char **path)
 
        return ret;
 }
+
+#ifndef _USE_TVPD_MODE
+int ms_user_get_mediashared_path(uid_t uid, char **path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       if (uid == getuid())
+               *path = g_strdup(tzplatform_getenv(TZ_USER_MEDIASHARED));
+       else
+               ret = __ms_user_get_path(MEDIA_SHARED, uid, path);
+
+       //MSAPI_DBG_SLOG("DB path [%s]", *path);
+
+       return ret;
+}
+#endif
index dba8275..bfc07df 100755 (executable)
@@ -42,7 +42,7 @@ bool ms_is_support_senior_mode(void);
 
 int ms_check_file_path(const char *file_path, uid_t uid);
 int ms_check_ignore_dir(const char *full_path, uid_t uid);
-int ms_check_scan_ignore(char * path);
+int ms_check_scan_ignore(char * path, uid_t uid);
 bool ms_storage_mount_status(const char* start_path);
 int ms_set_db_status(ms_db_status_type_t status, ms_user_storage_type_e storage_type);
 int ms_set_power_mode(ms_db_status_type_t status);
index d97d6d5..0447f72 100755 (executable)
@@ -216,7 +216,7 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
        }
 
        while (1) {
-               if (ms_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
+               if (ms_check_scan_ignore(dir_path, uid) != MS_MEDIA_ERR_NONE) {
                        ret = MS_MEDIA_ERR_INVALID_PATH;
                        break;
                }
@@ -253,17 +253,52 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
        return ret;
 }
 
-int ms_check_scan_ignore(char * path)
+int ms_check_scan_ignore(char * path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        const char *ignore_file = ".scan_ignore";
+       char *tmp_path = NULL;
        char ignore_path[MS_FILE_PATH_LEN_MAX] = {0, };
 
+#ifndef _USE_TVPD_MODE
+       char replace[MS_FILE_PATH_LEN_MAX] = {0, };
+       char *mediashared = NULL;
+#endif
+
        if (strstr(path, "/.")) {
                MS_DBG_ERR("hidden path");
                return MS_MEDIA_ERR_INVALID_PATH;
        }
 
+       /* Check for symbolic link */
+       tmp_path = realpath(path, NULL);
+
+#ifdef _USE_TVPD_MODE
+       if (g_strcmp0(tmp_path, path) != 0) {
+               MS_SAFE_FREE(tmp_path);
+               MS_DBG_ERR("symbolic link(directory)");
+               return MS_MEDIA_ERR_INVALID_PATH;
+       }
+#else
+       if (g_str_has_prefix(tmp_path, MEDIA_SHARE_PATH)) {
+               ms_user_get_mediashared_path(uid, &mediashared);
+               snprintf(replace, MS_FILE_PATH_LEN_MAX, "%s%s", mediashared, tmp_path + strlen(MEDIA_SHARE_PATH));
+               MS_SAFE_FREE(mediashared);
+               if (g_strcmp0(replace, path) != 0) {
+                       MS_SAFE_FREE(tmp_path);
+                       MS_DBG_ERR("symbolic link(directory)");
+                       return MS_MEDIA_ERR_INVALID_PATH;
+               }
+       } else {
+               if (g_strcmp0(tmp_path, path) != 0) {
+                       MS_SAFE_FREE(tmp_path);
+                       MS_DBG_ERR("symbolic link(directory)");
+                       return MS_MEDIA_ERR_INVALID_PATH;
+               }
+       }
+#endif
+       MS_SAFE_FREE(tmp_path);
+
        if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
                memset(ignore_path, 0, sizeof(ignore_path));
                snprintf(ignore_path, sizeof(ignore_path), "%s/%s", path, ignore_file);
@@ -527,4 +562,4 @@ int ms_set_vip_process(void)
        close(id);
        return MS_MEDIA_ERR_NONE;
 }
-#endif
\ No newline at end of file
+#endif
index acd06c3..1611a7b 100755 (executable)
@@ -326,7 +326,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                __msc_set_dir_scan_cur_path(current_path);
 
                if (strncmp(current_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) != 0) {
-                       ret = ms_check_scan_ignore(current_path);
+                       ret = ms_check_scan_ignore(current_path, uid);
                        if (ret != MS_MEDIA_ERR_NONE) {
                                MS_DBG_ERR("%s is ignore", current_path);
                                MS_SAFE_FREE(current_path);
@@ -639,7 +639,7 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
 
                __msc_set_storage_scan_cur_path(current_path);
 
-               ret = ms_check_scan_ignore(current_path);
+               ret = ms_check_scan_ignore(current_path, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
                        MS_SAFE_FREE(current_path);
index c3f1443..9d32e6b 100755 (executable)
@@ -78,7 +78,7 @@ static int __msc_dir_scan(void **handle, const char *storage_id, const char*star
                current_path = g_array_index(dir_array , char*, 0);
                g_array_remove_index(dir_array, 0);
 
-               if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
+               if (ms_check_scan_ignore(current_path, uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
                        MS_SAFE_FREE(current_path);
                        continue;
@@ -107,6 +107,12 @@ static int __msc_dir_scan(void **handle, const char *storage_id, const char*star
                                }
 
                                if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+                                       /* Check symbolic link file */
+                                       if (g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
+                                               MS_DBG_WARN("Symbolic link.. Skip this file");
+                                               continue;
+                                       }
+
                                        /* Check content.scanning.others feature */
                                        if (!ms_check_support_media_type(handle, path)) {
                                                MS_DBG("Unsupported media type");
@@ -770,7 +776,7 @@ static int __msc_dir_scan_meta_update(void **handle, const char*start_path, cons
                current_path = g_array_index(dir_array , char*, 0);
                g_array_remove_index(dir_array, 0);
 
-               if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
+               if (ms_check_scan_ignore(current_path, uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
                        MS_SAFE_FREE(current_path);
                        continue;