Use snprintf instead of sprintf 33/230933/3
authorYunjin Lee <yunjin-.lee@samsung.com>
Thu, 16 Apr 2020 06:02:29 +0000 (15:02 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Thu, 16 Apr 2020 06:35:09 +0000 (15:35 +0900)
- Fix to use snprintf() instead of sprintf() and add return value check
- Return NULL if there's no string to return and if there's no proper
string to display then terminate popup app.

Change-Id: Id7261923f632c7278103c63ab9859f1f10c35ea2
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
ui/src/popup.c

index 7812e27..8643725 100644 (file)
@@ -63,7 +63,7 @@ static char* __get_privacy_display(const char* privacy)
        else
                LOGE("privilege_info_get_privacy_display() failed. ret = %d, privacy = %s", ret, privacy);
 
-       return "";
+       return NULL;
 }
 
 static char* __accessible_content_name_cb(void *data, Evas_Object *obj)
@@ -74,6 +74,9 @@ static char* __accessible_content_name_cb(void *data, Evas_Object *obj)
 
 static char* __make_message(const char* format, const char* pkg_label, const char* privacy)
 {
+       if (pkg_label == NULL || privacy == NULL)
+               return NULL;
+
        char* message = NULL;
        int ret = 0;
 
@@ -85,7 +88,7 @@ static char* __make_message(const char* format, const char* pkg_label, const cha
                LOGD("message : %s", message);
                return message;
        }
-       return "";
+       return NULL;
 }
 
 static char* __get_pkg_label(const char* pkgid)
@@ -105,13 +108,13 @@ static char* __get_pkg_label(const char* pkgid)
        if (label != NULL)
                pkg_label = strdup(label);
 
+       if (pkg_label == NULL)
+               LOGE("strdup() of pkg_label failed.");
+
        if (handle != NULL)
                pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
 
-       if (pkg_label != NULL)
-               return pkg_label;
-
-       return "";
+       return pkg_label;
 }
 
 static char* __get_message(const char* pkgid, const char* privacy)
@@ -120,10 +123,12 @@ static char* __get_message(const char* pkgid, const char* privacy)
        char* pkg_label = __get_pkg_label(pkgid);
        char* privacy_display = __get_privacy_display(privacy);
        char* message = __make_message(MSG_POPUP_TEXT, pkg_label, privacy_display);
-       if (strlen(pkg_label) > 0)
+       if (pkg_label != NULL)
                free(pkg_label);
-       if (strlen(privacy_display) > 0)
+       if (privacy_display != NULL)
                free(privacy_display);
+       if (message == NULL)
+               ui_app_exit();
        return message;
 }
 static void __set_popup_contents(app_data_s *ad)
@@ -136,9 +141,13 @@ static void __set_popup_contents(app_data_s *ad)
                free(message);
        if (!strcmp(ad->launch_type, "multi")) {
                char counter[COUNTER_LEN];
-               int ret = sprintf(counter, "%d / %d", (ad->privacy_idx) + 1, ad->privacy_num);
-               LOGD("counter %s", counter);
-               elm_object_part_text_set(ad->layout, "elm.privilege_counter", counter);
+               int ret = snprintf(counter, COUNTER_LEN, "%d / %d", (ad->privacy_idx) + 1, ad->privacy_num);
+               if (ret < 0 || ret >= COUNTER_LEN) {
+                       LOGE("snprintf() for counter failed. ret = %d", ret);
+               } else {
+                       LOGD("counter %s", counter);
+                       elm_object_part_text_set(ad->layout, "elm.privilege_counter", counter);
+               }
        }
 }