fix: Fix coverity issue 76/275676/2 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.061113 accepted/tizen/7.0/unified/hotfix/20221116.104609 accepted/tizen/unified/20220607.135114 submit/tizen/20220531.034400 tizen_7.0_m2_release
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 30 May 2022 02:55:57 +0000 (11:55 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 30 May 2022 22:32:44 +0000 (07:32 +0900)
Fix Out-of-bounds access (OVERRUN) issue

Change-Id: I2df6af4a5bbe4c5312cb11db45c49eb84be31668

i18ninfo/i18ninfo.cpp

index 7a37d01..be0080b 100644 (file)
@@ -377,8 +377,8 @@ static char *_date_basic_format_convert(const char *input_pattern, int i, const
        ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
        CHECK_ERROR("i18n_udate_format_date", ret);
 
-       char *s = (char *)malloc(BUF_SIZE * sizeof(char));
-       i18n_ustring_copy_au(s, result);
+       char *s = (char *)calloc((BUF_SIZE + 1), sizeof(char));
+       i18n_ustring_copy_au_n(s, result, BUF_SIZE);
        i18n_udate_destroy(format_h);
        free(result);
 
@@ -579,8 +579,8 @@ static int __get_date_and_time(char *input_time)
                        ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
                        CHECK_ERROR("i18n_udate_format_date", ret);
 
-                       char s[BUF_SIZE];
-                       i18n_ustring_copy_au(s, result);
+                       char s[BUF_SIZE +1];
+                       i18n_ustring_copy_au_n(s, result, BUF_SIZE);
                        free(result);
 
                        char *time_str, *date_str;
@@ -650,8 +650,8 @@ static int __get_number_format(const char *input_number)
                i18n_unumber_format_double(num_format, my_number, formatted_number, BUF_SIZE, NULL);
 
                /* Display the formatting result. */
-               char string[BUF_SIZE];
-               i18n_ustring_copy_au(string, formatted_number);
+               char string[BUF_SIZE + 1];
+               i18n_ustring_copy_au_n(string, formatted_number, BUF_SIZE);
 
                char *number_str;
                number_str = __print_i18n_type_string("number_format", i);
@@ -690,8 +690,8 @@ static int __get_symbol()
                CHECK_ERROR("18n_unumber_get_symbol", ret);
 
                /* Display the formatted symbol. */
-               char string[BUF_SIZE];
-               i18n_ustring_copy_au(string, u_buffer);
+               char string[BUF_SIZE +1];
+               i18n_ustring_copy_au_n(string, u_buffer, BUF_SIZE);
 
                char *symbol_str;
                symbol_str = __print_i18n_type_string("symbol", i+1);
@@ -749,8 +749,8 @@ static int __get_language_info()
        int ret =
                i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len);
        CHECK_ERROR("i18n_ulocale_get_display_name", ret);
-       char name_ch[BUF_SIZE];
-       i18n_ustring_copy_au(name_ch, name);
+       char name_ch[BUF_SIZE +1];
+       i18n_ustring_copy_au_n(name_ch, name, BUF_SIZE);
        printf("| Language display name  | %s\n", name_ch);
 
 
@@ -758,8 +758,8 @@ static int __get_language_info()
        i18n_ulocale_get_display_language(default_locale, default_locale, lang, BUF_SIZE);
 
        /* Get the string representation of the obtained language. */
-       char language[BUF_SIZE];
-       i18n_ustring_copy_au(language, lang);
+       char language[BUF_SIZE +1];
+       i18n_ustring_copy_au_n(language, lang, BUF_SIZE);
        printf("| Full name                              | %s\n", language);
 
        /* Get the obtained language code. */
@@ -845,8 +845,8 @@ static int __manage_string_iteration(char *input_string)
                }
                result[end - start] = '\0';
                i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
-               char str[BUF_SIZE];
-               i18n_ustring_copy_au(str, result);
+               char str[BUF_SIZE +1];
+               i18n_ustring_copy_au_n(str, result, BUF_SIZE);
                free(result);
 
                iter_type =  __print_i18n_type_string("iter_type", i);
@@ -873,8 +873,8 @@ static int __manage_string_iteration(char *input_string)
                }
                result[end - start] = '\0';
                i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
-               char str[BUF_SIZE];
-               i18n_ustring_copy_au(str, result);
+               char str[BUF_SIZE +1];
+               i18n_ustring_copy_au_n(str, result, BUF_SIZE);
                free(result);
 
                iter_type =  __print_i18n_type_string("iter_type", i);
@@ -924,20 +924,20 @@ static int __analyze_string(char *custom_string)
        i18n_ustring_to_upper(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
        CHECK_ERROR("i18n_ustring_to_upper", error_code);
 
-       char s[BUF_SIZE];
-       i18n_ustring_copy_au(s, dest);
+       char s[BUF_SIZE + 1];
+       i18n_ustring_copy_au_n(s, dest, BUF_SIZE);
        printf("| TO UPPER      | %s\n", s);
 
        /* To lower */
        i18n_ustring_to_lower(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
        CHECK_ERROR("i18n_ustring_to_lower", error_code);
-       i18n_ustring_copy_au(s, dest);
+       i18n_ustring_copy_au_n(s, dest, BUF_SIZE);
        printf("| to lower      | %s\n", s);
 
        /* To title */
        i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, NULL);
        CHECK_ERROR("i18n_ustring_to_title_new", error_code);
-       i18n_ustring_copy_au(s, dest);
+       i18n_ustring_copy_au_n(s, dest, BUF_SIZE);
        printf("| To Title      | %s\n", s);
 
        PRINT_ASCIIDOC_LOG("|===\n");
@@ -1026,8 +1026,8 @@ static int __get_timezone_info(char *timezone_id)
        ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
        CHECK_ERROR("i18n_udate_format_date", ret);
 
-       char s[BUF_SIZE] = {0, };
-       i18n_ustring_copy_au(s, result);
+       char s[BUF_SIZE +1] = {0, };
+       i18n_ustring_copy_au_n(s, result, BUF_SIZE);
        printf("| Current time                   | %s\n", s);
 
        /* Get the selected timezone ID. */
@@ -1140,8 +1140,8 @@ static int __show_ubidi(char *input_text)
                                        dst, &output_length);
                        CHECK_ERROR("i18n_ubidi_write_reordered", ret);
 
-                       char buffer[BUF_SIZE];
-                       i18n_ustring_copy_au(buffer, dst);
+                       char buffer[BUF_SIZE +1];
+                       i18n_ustring_copy_au_n(buffer, dst, BUF_SIZE);
                        printf("| %-46.46s | %-34.34s | %s \n", reordering_modes[i].display_name, reordering_options[j].display_name, buffer);
                }
                free(src);
@@ -1294,8 +1294,8 @@ static int __convert_number(char *custom_number)
                        free(number_to_convert);
                        return 0;
                }
-               char p_string[BUF_SIZE] = {0, };
-               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE - 1);
+               char p_string[BUF_SIZE+1] = {0, };
+               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
                printf(" Convert number : %s\n", p_string);
                free(str);
                PRINT_ASCIIDOC_LOG("|===\n");
@@ -1313,8 +1313,8 @@ static int __convert_number(char *custom_number)
                        free(number_to_convert);
                        return 0;
                }
-               char p_string[BUF_SIZE];
-               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE - 1);
+               char p_string[BUF_SIZE+1];
+               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
                printf(" Convert number : %s\n", p_string);
                free(str);
                PRINT_ASCIIDOC_LOG("|===\n");
@@ -1606,8 +1606,8 @@ static int __test_plural_rules(char *input_number)
        error_code = i18n_plural_rules_select_double(rules, input, BUF_SIZE, buffer, &output_length);
        CHECK_ERROR("i18n_plural_rules_select_double", error_code);
 
-       char output_buffer[BUF_SIZE] = { 0 };
-       i18n_ustring_copy_au_n(output_buffer, buffer, BUF_SIZE - 1);
+       char output_buffer[BUF_SIZE +1] = { 0 };
+       i18n_ustring_copy_au_n(output_buffer, buffer, BUF_SIZE);
        printf("Matched rule: %s \n", output_buffer);
 
        /* Release the rules as it is not needed anymore. */