fix svace issues 35/160135/1 submit/tizen_3.0/20171115.125254
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 12 Oct 2017 14:27:23 +0000 (16:27 +0200)
committerKamil Lipiszko <k.lipiszko@samsung.com>
Tue, 14 Nov 2017 13:15:23 +0000 (14:15 +0100)
Fix WGID: 260763, 260343, 170556, 170555.
Add util_strlcpy function to handle possible 'no null-terminated'
string issues

Change-Id: I4818fe4053942587de3ab37748e2b54e0cbc2fb3

inc/util.h
src/modules/clock/clock.c
src/modules/connection/connection.c
src/util.c

index 98e6dab3e81567c31ea7dc7f4957a656104c9539..89a7ee1edcc7cf4c9a0d39a5fe4af9d1cd1e1ced 100644 (file)
@@ -273,6 +273,18 @@ int util_runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_change
  */
 void util_runtime_info_unset_changed_cb(runtime_info_key_e key, runtime_info_changed_cb cb);
 
+/**
+ * @brief Copy src string to dest and null-termianates dest string.
+ *
+ * @param dest destination string
+ * @param src source string
+ * @param dest_size size of dest buffer
+ *
+ * @return number of chars copied to dest buffer or value <= 0 if no characters
+ * has been copied.
+ */
+int util_strlcpy(char *dest, const char *src, size_t dest_size);
+
 /**
  * @}
  */
index 3275b9f3a1006c35b73c6279e34655c2727ae8dc..455f890596b9ac1c3fa3b492f1a48572c49bedf9 100644 (file)
@@ -80,8 +80,8 @@ static int wake_up_cb(void *data);
 #define ICON_PRIORITY  INDICATOR_PRIORITY_FIXED8
 #define MODULE_NAME            "clock"
 
-static void indicator_get_apm_by_region(char* output, void* data);
-static void indicator_get_time_by_region(char* output, void* data);
+static void indicator_get_apm_by_region(char* output, size_t output_size);
+static void indicator_get_time_by_region(char* output, size_t output_size);
 
 icon_s sysclock = {
        .type = INDICATOR_TXT_ICON,
@@ -185,8 +185,8 @@ static Eina_Bool indicator_clock_changed_cb(void *data)
                _E("Fail to add timer !");
        }
 
-       indicator_get_apm_by_region(icu_apm,data);
-       indicator_get_time_by_region(time_buf,data);
+       indicator_get_apm_by_region(icu_apm, CLOCK_STR_LEN);
+       indicator_get_time_by_region(time_buf, CLOCK_STR_LEN);
 
 
        if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
@@ -405,13 +405,10 @@ static char *_string_replacer(const char *src, const char *pattern, const char *
        return result;
 }
 
-
-
-void indicator_get_apm_by_region(char* output,void *data)
+void indicator_get_apm_by_region(char* output, size_t output_size)
 {
        int ret = -1;
        char *locale = NULL;
-       retm_if(data == NULL, "Data parameter is NULL");
        retm_if(output == NULL, "output parameter is NULL");
 
        i18n_uchar u_custom_skeleton[CLOCK_STR_LEN] = { 0, };
@@ -500,23 +497,17 @@ void indicator_get_apm_by_region(char* output,void *data)
        i18n_ustring_copy_au(s_formatted, u_formatted);
        apm_length = i18n_ustring_get_length(u_formatted);
 
-       if (strlen(s_formatted) < CLOCK_STR_LEN) {
-               strncpy(output, s_formatted, strlen(s_formatted));
-       }
-       else {
-               strncpy(output, s_formatted, CLOCK_STR_LEN - 1);
-       }
+       util_strlcpy(output, s_formatted, output_size);
 
        return;
 }
 
 
 
-void indicator_get_time_by_region(char* output,void *data)
+void indicator_get_time_by_region(char* output, size_t output_size)
 {
        int ret = -1;
        char *locale;
-       retm_if(data == NULL, "Data parameter is NULL");
        retm_if(output == NULL, "output parameter is NULL");
 
        i18n_uchar u_custom_skeleton[CLOCK_STR_LEN] = { 0, };
@@ -632,12 +623,7 @@ void indicator_get_time_by_region(char* output,void *data)
                return;
        }
 
-       if (strlen(s_convert_formatted) < CLOCK_STR_LEN) {
-               strncpy(output, s_convert_formatted, strlen(s_convert_formatted));
-       }
-       else {
-               strncpy(output, s_convert_formatted, CLOCK_STR_LEN - 1);
-       }
+       util_strlcpy(output, s_convert_formatted, output_size);
 
        free(s_convert_formatted);
 
index 5c8f5f48b186ab248a0a940c62554d66b7153728..ce91f2b2f070b607e1f37e9a3a59a98a3ac4605e 100644 (file)
@@ -197,7 +197,7 @@ static void _view_icon_update_ps_network(telephony_network_ps_type_e ps_type, vo
 {
        icon_e icon = _icon_level_for_ps_network_type(ps_type);
 
-       if (icon < LEVEL_LAST && icon >= LEVEL_MIN) {
+       if (icon < LEVEL_LAST) {
                show_image_icon(icon);
                show_connection_transfer_icon(data);
        } else
@@ -212,7 +212,7 @@ static void _view_icon_update_network(telephony_network_service_state_e state,
        switch (state) {
                case TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE:
                        icon = _icon_level_for_network_type(network_type);
-                       if (icon < LEVEL_LAST && icon >= LEVEL_MIN) {
+                       if (icon < LEVEL_LAST) {
                                show_image_icon(icon);
                                show_connection_transfer_icon(data);
                        } else
index 0f689278caf11b194bdbf9654552ccabd3d7fb6b..3f224e8bf16b519aa5434941f0756b84be11f1af 100644 (file)
@@ -19,6 +19,7 @@
 #include <app_common.h>
 #include <Eina.h>
 #include <system_settings.h>
+#include <string.h>
 
 #include "common.h"
 #include "indicator.h"
@@ -444,4 +445,16 @@ void util_runtime_info_unset_changed_cb(runtime_info_key_e key, runtime_info_cha
 
 }
 
+int util_strlcpy(char *dest, const char *src, size_t size)
+{
+       int dlen = strlen(src);
+       dlen = dlen >= size ? size - 1 : dlen;
+       if (dlen >= 0)
+       {
+               strncpy(dest, src, dlen);
+               dest[dlen] = '\0';
+       }
+       return dlen;
+}
+
 /* End of file */