From d09bbffceb2babe51000ff3042c09febc3afaa09 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 16 Oct 2015 11:34:01 +0900 Subject: [PATCH] Fix prevent issue Change-Id: I0da7fbf08691fc8a262584d0e4f8edbfbd809b45 Signed-off-by: Minje Ahn --- packaging/libmedia-thumbnail.spec | 2 +- server/include/thumb-server-internal.h | 2 -- server/thumb-server-internal.c | 9 ++++++--- src/media-thumb-internal.c | 21 ++++++++++++++++----- src/util/media-thumb-util.c | 2 +- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec index e6a25a9..25792dd 100644 --- a/packaging/libmedia-thumbnail.spec +++ b/packaging/libmedia-thumbnail.spec @@ -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 diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h index 7869fe3..e3caa99 100755 --- a/server/include/thumb-server-internal.h +++ b/server/include/thumb-server-internal.h @@ -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, diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c index eaf1745..dd282a0 100755 --- a/server/thumb-server-internal.c +++ b/server/thumb-server-internal.c @@ -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."); diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c index af8f593..8ea9637 100755 --- a/src/media-thumb-internal.c +++ b/src/media-thumb-internal.c @@ -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; diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c index c487b6e..9d16281 100755 --- a/src/util/media-thumb-util.c +++ b/src/util/media-thumb-util.c @@ -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) { -- 2.7.4