Change copy size to avoid buffer overflow 09/260209/1 accepted/tizen/6.5/unified/20211028.094557 accepted/tizen/unified/20210623.125320 submit/tizen/20210622.084327 submit/tizen_6.5/20211028.161701 tizen_6.5.m2_release
authorJinWang An <jinwang.an@samsung.com>
Tue, 22 Jun 2021 04:50:04 +0000 (13:50 +0900)
committerJinWang An <jinwang.an@samsung.com>
Tue, 22 Jun 2021 04:50:04 +0000 (13:50 +0900)
Change-Id: If408b67c44aa1ad93c31670c0a73cb815ebbddc0
Signed-off-by: JinWang An <jinwang.an@samsung.com>
i18ninfo/i18ninfo.cpp
tests/utc-capi-base-utils-udatepg.c

index f283c05..7a37d01 100644 (file)
@@ -1295,7 +1295,7 @@ static int __convert_number(char *custom_number)
                        return 0;
                }
                char p_string[BUF_SIZE] = {0, };
-               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
+               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE - 1);
                printf(" Convert number : %s\n", p_string);
                free(str);
                PRINT_ASCIIDOC_LOG("|===\n");
@@ -1314,7 +1314,7 @@ static int __convert_number(char *custom_number)
                        return 0;
                }
                char p_string[BUF_SIZE];
-               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
+               i18n_ustring_copy_au_n(p_string, str, BUF_SIZE - 1);
                printf(" Convert number : %s\n", p_string);
                free(str);
                PRINT_ASCIIDOC_LOG("|===\n");
@@ -1607,7 +1607,7 @@ static int __test_plural_rules(char *input_number)
        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);
+       i18n_ustring_copy_au_n(output_buffer, buffer, BUF_SIZE - 1);
        printf("Matched rule: %s \n", output_buffer);
 
        /* Release the rules as it is not needed anymore. */
index 943fd29..bfb2654 100644 (file)
@@ -20,7 +20,7 @@
 static i18n_udatepg_h dtpg = NULL;
 static int ret = I18N_ERROR_NONE;
 
-#define I18N_ret_LEN         100
+#define I18N_RET_LEN         100
 #define SKELETON_LEN            6
 #define BEST_PATTERN_CAPACITY   12
 
@@ -110,12 +110,12 @@ int utc_capi_base_utils_i18n_udatepg_get_best_pattern_p(void)
     const char *b_skeleton = "MMMM";
     i18n_uchar skeleton[SKELETON_LEN] = { 0, };
     i18n_uchar bskeleton[SKELETON_LEN] = { 0, };
-    i18n_uchar best_pattern[I18N_ret_LEN] = { 0, };
+    i18n_uchar best_pattern[I18N_RET_LEN] = { 0, };
     int skeleton_len;
     int best_pattern_len;
     int capacity;
 
-    i18n_ustring_copy_ua(skeleton, a_skeleton);
+    i18n_ustring_copy_ua_n(skeleton, a_skeleton, SKELETON_LEN - 1);
     skeleton_len = i18n_ustring_get_length(skeleton);
     capacity = (int)(sizeof(best_pattern)/sizeof(best_pattern[0]));
 
@@ -123,7 +123,7 @@ int utc_capi_base_utils_i18n_udatepg_get_best_pattern_p(void)
         capacity, &best_pattern_len);
     assert_eq(ret, I18N_ERROR_NONE);
 
-    i18n_ustring_copy_ua(bskeleton, b_skeleton);
+    i18n_ustring_copy_ua_n(bskeleton, b_skeleton, SKELETON_LEN - 1);
     skeleton_len = i18n_ustring_get_length(bskeleton);
     capacity = (int)(sizeof(best_pattern)/sizeof(best_pattern[0]));