Fix issue detected by static analysis tool 47/229547/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 2 Apr 2020 01:26:57 +0000 (10:26 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 2 Apr 2020 01:28:01 +0000 (10:28 +0900)
Dereference null return value (NULL_RETURNS)
dereference: Dereferencing a pointer that might be null conv_path when calling snprintf.

Change-Id: I47cfa1bded3b313a2fb982c5975a2e7a79f3a83c
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
client/sticker_dbus.c

index 318782b..5460c71 100644 (file)
@@ -690,11 +690,12 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
         if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
             len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
             conv_path = (char *)calloc(len, sizeof(char));
-            snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
+            if (conv_path)
+                snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
         } else
             conv_path = strdup(sticker_data->uri);
 
-        if (strcmp(conv_path, origin_data->uri) != 0) {
+        if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
             LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
             int is_exist = 0;
             ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
@@ -736,17 +737,21 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
     if (sticker_data->thumbnail) {
         int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
         char *conv_path = (char *)calloc(len, sizeof(char));
-        snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
-        if (strcmp(conv_path, origin_data->thumbnail) != 0) {
-            LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
-            ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
-            if (ret != STICKER_CLIENT_ERROR_NONE) {
-                LOGE("failed to update sticker thumbnail");
-                free(conv_path);
-                goto cleanup;
+        if (conv_path) {
+            snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
+            if (strcmp(conv_path, origin_data->thumbnail) != 0)
+            {
+                LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
+                ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
+                if (ret != STICKER_CLIENT_ERROR_NONE)
+                {
+                    LOGE("failed to update sticker thumbnail");
+                    free(conv_path);
+                    goto cleanup;
+                }
             }
+            free(conv_path);
         }
-        free(conv_path);
     }
 
     if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {