Change g_strdup() to strndup() (fix for free issue) 31/66031/1 submit/tizen/20160418.071806
authorMinje Ahn <minje.ahn@samsung.com>
Fri, 15 Apr 2016 01:23:20 +0000 (10:23 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 15 Apr 2016 01:23:20 +0000 (10:23 +0900)
Change-Id: I95f9165b9e5eed9bb82330f74bcbe4f36345a565
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/media-util-db.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner/media-scanner-scan.c
src/server/media-server-main.c

index 5bb7277..3ccb635 100755 (executable)
@@ -65,6 +65,7 @@ static int __media_db_busy_handler(void *pData, int count)
 
 static char* __media_get_media_DB(uid_t uid)
 {
+       int len = 0;
        char *result_passwd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
@@ -92,8 +93,9 @@ static char* __media_get_media_DB(uid_t uid)
                        MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
                        return NULL;
                }
-               snprintf(passwd_str, sizeof(passwd_str), "%s/.applications/dbspace/.media.db", userinfo->pw_dir);
-               result_passwd = g_strdup(passwd_str);
+               len = snprintf(passwd_str, sizeof(passwd_str), "%s/.applications/dbspace/.media.db", userinfo->pw_dir);
+               if (len > 0)
+                       result_passwd = strndup(passwd_str, len);
        }
 
        return result_passwd;
index e81efe5..e6dec13 100755 (executable)
@@ -131,6 +131,7 @@ static int __msc_remove_dir_scan_cb()
 
 static char* __msc_get_path(uid_t uid)
 {
+       int len = 0;
        char *result_passwd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
@@ -159,8 +160,9 @@ static char* __msc_get_path(uid_t uid)
                        return NULL;
                }
 
-               snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
-               result_passwd = g_strdup(passwd_str);
+               len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+               if (len > 0)
+                       result_passwd = strndup(passwd_str, len);
        }
 
        return result_passwd;
index ad9fe6c..09b49ba 100755 (executable)
@@ -87,6 +87,7 @@ static char* __msc_get_path(uid_t uid);
 
 static char* __msc_get_path(uid_t uid)
 {
+       int len = 0;
        char *result_passwd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
@@ -115,8 +116,9 @@ static char* __msc_get_path(uid_t uid)
                        return NULL;
                }
 
-               snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
-               result_passwd = g_strdup(passwd_str);
+               len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+               if (len > 0)
+                       result_passwd = strndup(passwd_str, len);
        }
 
        return result_passwd;
index d40c08a..ae7025e 100644 (file)
@@ -61,6 +61,7 @@ static char *priv_lang = NULL;
 
 static char* __ms_get_path(uid_t uid)
 {
+       int len = 0;
        char *result_passwd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
@@ -89,8 +90,9 @@ static char* __ms_get_path(uid_t uid)
                        return NULL;
                }
 
-               snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
-               result_passwd = g_strdup(passwd_str);
+               len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+               if (len > 0)
+                       result_passwd = strndup(passwd_str, len);
        }
 
        return result_passwd;