From 3590dc9744f16653458415397f76fa396fe2c343 Mon Sep 17 00:00:00 2001 From: JinWang An Date: Tue, 22 Jun 2021 13:50:04 +0900 Subject: [PATCH] Change copy size to avoid buffer overflow Change-Id: If408b67c44aa1ad93c31670c0a73cb815ebbddc0 Signed-off-by: JinWang An --- i18ninfo/i18ninfo.cpp | 6 +++--- tests/utc-capi-base-utils-udatepg.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/i18ninfo/i18ninfo.cpp b/i18ninfo/i18ninfo.cpp index f283c05..7a37d01 100644 --- a/i18ninfo/i18ninfo.cpp +++ b/i18ninfo/i18ninfo.cpp @@ -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. */ diff --git a/tests/utc-capi-base-utils-udatepg.c b/tests/utc-capi-base-utils-udatepg.c index 943fd29..bfb2654 100644 --- a/tests/utc-capi-base-utils-udatepg.c +++ b/tests/utc-capi-base-utils-udatepg.c @@ -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])); -- 2.7.4