From: Lukasz Stanislawski Date: Thu, 12 Oct 2017 14:27:23 +0000 (+0200) Subject: fix svace issues X-Git-Tag: accepted/tizen/unified/20171017.204709^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ac10bd3a6e72b2734ce4375dec684b017926ace2;p=profile%2Fmobile%2Fapps%2Fnative%2Findicator.git fix svace issues Fix WGID: 260763, 260343, 170556, 170555. Add util_strlcpy function to handle possible 'no null-terminated' string issues Change-Id: I4818fe4053942587de3ab37748e2b54e0cbc2fb3 --- diff --git a/inc/util.h b/inc/util.h index 74f330b..a153738 100644 --- a/inc/util.h +++ b/inc/util.h @@ -372,6 +372,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); + +/** * @} */ diff --git a/src/modules/clock/clock.c b/src/modules/clock/clock.c index 23526bc..e89eb85 100644 --- a/src/modules/clock/clock.c +++ b/src/modules/clock/clock.c @@ -83,8 +83,8 @@ static int register_clock_tts(void *data,int win_type); #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); #ifdef _SUPPORT_SCREEN_READER static void ICU_set_timezone(const char *timezone); @@ -192,8 +192,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) { @@ -417,13 +417,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, }; @@ -512,23 +509,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, }; @@ -644,12 +635,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); diff --git a/src/modules/connection/connection.c b/src/modules/connection/connection.c index 5f796b1..ce2faea 100644 --- a/src/modules/connection/connection.c +++ b/src/modules/connection/connection.c @@ -200,7 +200,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 @@ -215,7 +215,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 diff --git a/src/util.c b/src/util.c index 5876357..d18492b 100644 --- a/src/util.c +++ b/src/util.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "common.h" #include "indicator.h" @@ -743,4 +744,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 */