Fix prevent issue 27/49627/1 accepted/tizen/mobile/20151016.043749 accepted/tizen/tv/20151016.043821 accepted/tizen/wearable/20151016.043828 submit/tizen/20151016.024332
authorMinje Ahn <minje.ahn@samsung.com>
Fri, 16 Oct 2015 02:34:01 +0000 (11:34 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 16 Oct 2015 02:34:01 +0000 (11:34 +0900)
Change-Id: I0da7fbf08691fc8a262584d0e4f8edbfbd809b45
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/libmedia-thumbnail.spec
server/include/thumb-server-internal.h
server/thumb-server-internal.c
src/media-thumb-internal.c
src/util/media-thumb-util.c

index e6a25a9..25792dd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-thumbnail
 Summary:    Media thumbnail service library for multimedia applications
-Version: 0.1.86
+Version: 0.1.87
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 7869fe3..e3caa99 100755 (executable)
@@ -27,8 +27,6 @@
 #ifndef _THUMB_DAEMON_INTERNAL_H_
 #define _THUMB_DAEMON_INTERNAL_H_
 
-#define SAFE_FREE(src)      { if(src) {free(src); src = NULL;}}
-
 typedef enum {
        MEDIA_SERVER_PID = 1,
        OTHERS_PID = 0,
index eaf1745..dd282a0 100755 (executable)
@@ -46,6 +46,7 @@
 #define THUMB_DEFAULT_HEIGHT 240
 #define THUMB_BLOCK_SIZE 512
 #define THUMB_ROOT_UID "0"
+#define THUMB_COMM_SOCK_PATH "/var/run/media-server/media_ipc_thumbcomm.socket"
 
 static __thread char **arr_path;
 static __thread uid_t *arr_uid;
@@ -486,7 +487,7 @@ static gboolean __thumb_server_send_msg_to_agent(int msg_type)
 
        sock = sock_info.sock_fd;
        serv_addr.sun_family = AF_UNIX;
-       strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcomm.socket");
+       strncpy(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, strlen(THUMB_COMM_SOCK_PATH));
 
 
        /* Connecting to the thumbnail server */
@@ -546,6 +547,7 @@ gboolean _thumb_server_prepare_socket(int *sock_fd)
 
        if (ms_cynara_enable_credentials_passing(sock) != MS_MEDIA_ERR_NONE) {
                thumb_err("ms_cynara_enable_credentials_passing failed");
+               close(sock);
                return FALSE;
        }
 
@@ -559,7 +561,8 @@ static char* _media_thumb_get_default_path(uid_t uid)
        char *result_psswd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
-               result_psswd = strdup(THUMB_DEFAULT_PATH);
+               if (THUMB_DEFAULT_PATH != NULL)
+                       result_psswd = strndup(THUMB_DEFAULT_PATH, strlen(THUMB_DEFAULT_PATH));
                grpinfo = getgrnam("users");
                if (grpinfo == NULL) {
                        thumb_err("getgrnam(users) returns NULL !");
@@ -757,7 +760,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
        thumb_h = req_msg->thumb_height;
        thumb_path = res_msg->dst_path;
        thumb_path[0] = '\0';
-       max_length = sizeof(res_msg->dst_path);
+       max_length = sizeof(res_msg->dst_path) -1;
 
        if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
                thumb_err("origin_path does not exist in file system.");
index af8f593..8ea9637 100755 (executable)
@@ -1287,7 +1287,8 @@ static char* _media_thumb_mmc_get_path(uid_t uid)
        char *result_psswd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
-               result_psswd = strdup(THUMB_MMC_PATH);
+               if (THUMB_MMC_PATH != NULL)
+                       result_psswd = strndup(THUMB_MMC_PATH, strlen(THUMB_MMC_PATH));
                grpinfo = getgrnam("users");
                if (grpinfo == NULL) {
                        thumb_err("getgrnam(users) returns NULL !");
@@ -1322,7 +1323,8 @@ static char* _media_thumb_phone_get_path(uid_t uid)
        char *result_psswd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
-               result_psswd = strdup(THUMB_PHONE_PATH);
+               if (THUMB_PHONE_PATH != NULL)
+                       result_psswd = strndup(THUMB_PHONE_PATH, strlen(THUMB_PHONE_PATH));
                grpinfo = getgrnam("users");
                if (grpinfo == NULL) {
                        thumb_err("getgrnam(users) returns NULL !");
@@ -1358,6 +1360,7 @@ int _media_thumb_get_hash_name(const char *file_full_path,
        char *hash_name = NULL;
        /*char *thumb_dir = NULL;*/
        char file_ext[255] = { 0 };
+       char *get_path = NULL;
        int ret_len = 0;
        media_thumb_store_type store_type = -1;
 
@@ -1384,13 +1387,21 @@ int _media_thumb_get_hash_name(const char *file_full_path,
        }
 
        if (store_type == THUMB_PHONE) {
-               ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_phone_get_path(uid), file_ext, hash_name);
+               get_path = _media_thumb_phone_get_path(uid);
+               if (get_path != NULL)
+                       ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", get_path, file_ext, hash_name);
        } else if (store_type == THUMB_MMC) {
-               ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_mmc_get_path(uid), file_ext, hash_name);
+               get_path = _media_thumb_mmc_get_path(uid);
+               if (get_path != NULL)
+                       ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", get_path, file_ext, hash_name);
        } else {
-               ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_phone_get_path(uid), file_ext, hash_name);
+               get_path = _media_thumb_phone_get_path(uid);
+               if (get_path != NULL)
+                       ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", get_path, file_ext, hash_name);
        }
 
+       SAFE_FREE(get_path);
+
        if ((ret_len < 0) || (ret_len > (int)max_thumb_path)) {
                thumb_err("invalid hash path ret_len[%d]", ret_len);
                return MS_MEDIA_ERR_INTERNAL;
index c487b6e..9d16281 100755 (executable)
@@ -90,7 +90,7 @@ _media_thumb_get_file_type(const char *file_full_path)
 
 int _media_thumb_get_store_type_by_path(const char *full_path)
 {
-       if (full_path != NULL) {
+       if (full_path != NULL && THUMB_PATH_PHONE != NULL && THUMB_PATH_MMC != NULL) {
                if (strncmp(full_path, THUMB_PATH_PHONE, strlen(THUMB_PATH_PHONE)) == 0) {
                        return THUMB_PHONE;
                } else if (strncmp(full_path, THUMB_PATH_MMC, strlen(THUMB_PATH_MMC)) == 0) {