From 19553f73e1efd17c6f036f8b688bfe436a93d447 Mon Sep 17 00:00:00 2001 From: yinjiaming Date: Tue, 7 Jun 2022 08:08:51 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=B8=AD=E9=83=A8=E5=88=86=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E3=80=90=E8=83=8C=E6=99=AF=E3=80=91=20A=E6=A0=B8?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E4=B8=AD=E6=9C=89=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=95=8F=E6=84=9F=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 将敏感的字符串改为随机生成 【影响】 对现有的产品编译不会有影响。 re #I5ALBS Signed-off-by: yinjiaming Change-Id: Ib9b023ace6be1d58248c993f7b9919a96afbea96 --- .../libc/io/full/IO_test_dcgettext_001.cpp | 22 +++++++++++++++-- .../unittest/libc/sys/smoke/sys_test_017.cpp | 16 ++++++++++--- .../net/resolv/smoke/net_resolv_test_002.cpp | 24 +++++++++++++------ .../net/resolv/smoke/net_resolv_test_003.cpp | 24 +++++++++++++------ .../net/resolv/smoke/net_resolv_test_006.cpp | 17 +++++++++++-- .../net/resolv/smoke/net_resolv_test_007.cpp | 18 ++++++++++++-- 6 files changed, 98 insertions(+), 23 deletions(-) diff --git a/testsuites/unittest/libc/io/full/IO_test_dcgettext_001.cpp b/testsuites/unittest/libc/io/full/IO_test_dcgettext_001.cpp index 57367c17..c5ea39da 100644 --- a/testsuites/unittest/libc/io/full/IO_test_dcgettext_001.cpp +++ b/testsuites/unittest/libc/io/full/IO_test_dcgettext_001.cpp @@ -32,18 +32,36 @@ #include #include +const int domain_name_length = 10; +const int buffer_size = 50; + static UINT32 testcase(VOID) { char *s = ""; + char domain[buffer_size], tmp[domain_name_length]; + srand(time(NULL)); + for (int i = 0, r = 0; i < domain_name_length; i++) { + r = rand() % 36; // 36: 0-9 and a-z + if (r < 10) { // 10: 0-9 + tmp[i] = '0' + r; + } else { + tmp[i] = 'a' + r; + } + } + int ret = sprintf_s(domain, sizeof(domain), "www.%s.com", tmp); + if (ret == 0) { + printf("sprinf_s failed\n"); + return LOS_NOK; + } setlocale(LC_ALL, ""); textdomain("gettext_demo"); bindtextdomain("gettext_demo", "."); bind_textdomain_codeset("gettext_demo", "UTF-8"); - printf(dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES)); + printf(dcgettext(domain, "TestString1\n", LC_MESSAGES)); - s = dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES); + s = dcgettext(domain, "TestString1\n", LC_MESSAGES); printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s); ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1\n", s); setlocale(LC_ALL, "C"); diff --git a/testsuites/unittest/libc/sys/smoke/sys_test_017.cpp b/testsuites/unittest/libc/sys/smoke/sys_test_017.cpp index 28c0d173..224c4531 100644 --- a/testsuites/unittest/libc/sys/smoke/sys_test_017.cpp +++ b/testsuites/unittest/libc/sys/smoke/sys_test_017.cpp @@ -30,7 +30,7 @@ */ #include "It_test_sys.h" -#define TEST_PASSWORD (char *)"test1234" +const int password_length = 10; static UINT32 TestCase(VOID) { @@ -39,14 +39,24 @@ static UINT32 TestCase(VOID) char *key = NULL; char slat[2]; int ret; + char test_password[password_length]; + srand(time(NULL)); + for (int i = 0, r = 0; i < password_length; i++) { + r = rand() % 36; // 36: 0-9 and a-z + if (r < 10) { // 10: 0-9 + test_password[i] = '0' + r; + } else { + test_password[i] = 'a' + r; + } + } - key = TEST_PASSWORD; + key = test_password; slat[0] = key[0]; slat[1] = key[1]; passwd1 = crypt(key, slat); ICUNIT_GOTO_NOT_EQUAL(passwd1, NULL, passwd1, EXIT); - key = TEST_PASSWORD; + key = test_password; slat[0] = passwd1[0]; slat[1] = passwd1[1]; passwd2 = crypt(key, slat); diff --git a/testsuites/unittest/net/resolv/smoke/net_resolv_test_002.cpp b/testsuites/unittest/net/resolv/smoke/net_resolv_test_002.cpp index 0419b615..4e570199 100644 --- a/testsuites/unittest/net/resolv/smoke/net_resolv_test_002.cpp +++ b/testsuites/unittest/net/resolv/smoke/net_resolv_test_002.cpp @@ -32,21 +32,31 @@ #include +const int buffer_size = 20; + static int EtherAtonTest(void) { struct ether_addr *eaddr = ether_aton("01::EF"); ICUNIT_ASSERT_EQUAL(eaddr, NULL, -1); - eaddr = ether_aton("2C:9D:1E:4A:41:55"); + char mac_addr[buffer_size], *tmp = mac_addr; + int r[ETH_ALEN]; + srand(time(NULL)); + for (int i = 0; i < ETH_ALEN; i++) { + r[i] = rand() % 0xff; + } + // 0, 1, 2, 3, 4, 5: 6 elements of mac address. + (void)sprintf_s(mac_addr, sizeof(mac_addr), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]); + eaddr = ether_aton(mac_addr); ICUNIT_ASSERT_NOT_EQUAL(eaddr, NULL, -1); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], 0x2C, eaddr->ether_addr_octet[0]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], 0x9D, eaddr->ether_addr_octet[1]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], 0x1E, eaddr->ether_addr_octet[2]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], 0x4A, eaddr->ether_addr_octet[3]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], 0x41, eaddr->ether_addr_octet[4]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], 0x55, eaddr->ether_addr_octet[5]); + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], r[0], eaddr->ether_addr_octet[0]); + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], r[1], eaddr->ether_addr_octet[1]); + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], r[2], eaddr->ether_addr_octet[2]); // 2: compare r[2] with eaddr + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], r[3], eaddr->ether_addr_octet[3]); // 3: compare r[3] with eaddr + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], r[4], eaddr->ether_addr_octet[4]); // 4: compare r[4] with eaddr + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], r[5], eaddr->ether_addr_octet[5]); // 5: compare r[5] with eaddr return ICUNIT_SUCCESS; } diff --git a/testsuites/unittest/net/resolv/smoke/net_resolv_test_003.cpp b/testsuites/unittest/net/resolv/smoke/net_resolv_test_003.cpp index eeb8eeb9..85929a8b 100644 --- a/testsuites/unittest/net/resolv/smoke/net_resolv_test_003.cpp +++ b/testsuites/unittest/net/resolv/smoke/net_resolv_test_003.cpp @@ -32,6 +32,8 @@ #include +const int buffer_size = 20; + static int EtherAtonrTest(void) { struct ether_addr addr; @@ -39,15 +41,23 @@ static int EtherAtonrTest(void) ICUNIT_ASSERT_EQUAL(eaddr, NULL, -1); - eaddr = ether_aton_r("2c:9d:1e:4A:41:55", &addr); + char mac_addr[buffer_size], *tmp = mac_addr; + int r[ETH_ALEN]; + srand(time(NULL)); + for (int i = 0; i < ETH_ALEN; i++) { + r[i] = rand() % 0xff; + } + // 0, 1, 2, 3, 4, 5: 6 elements of mac address. + (void)sprintf_s(mac_addr, sizeof(mac_addr), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]); + eaddr = ether_aton_r(mac_addr, &addr); ICUNIT_ASSERT_EQUAL(eaddr, &addr, -1); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], 0x2c, eaddr->ether_addr_octet[0]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], 0x9d, eaddr->ether_addr_octet[1]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], 0x1e, eaddr->ether_addr_octet[2]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], 0x4a, eaddr->ether_addr_octet[3]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], 0x41, eaddr->ether_addr_octet[4]); - ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], 0x55, eaddr->ether_addr_octet[5]); + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], r[0], eaddr->ether_addr_octet[0]); + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], r[1], eaddr->ether_addr_octet[1]); + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], r[2], eaddr->ether_addr_octet[2]); // 2: compare r[2] with eaddr + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], r[3], eaddr->ether_addr_octet[3]); // 3: compare r[3] with eaddr + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], r[4], eaddr->ether_addr_octet[4]); // 4: compare r[4] with eaddr + ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], r[5], eaddr->ether_addr_octet[5]); // 5: compare r[5] with eaddr return ICUNIT_SUCCESS; } diff --git a/testsuites/unittest/net/resolv/smoke/net_resolv_test_006.cpp b/testsuites/unittest/net/resolv/smoke/net_resolv_test_006.cpp index d60d950a..7625ada9 100644 --- a/testsuites/unittest/net/resolv/smoke/net_resolv_test_006.cpp +++ b/testsuites/unittest/net/resolv/smoke/net_resolv_test_006.cpp @@ -32,13 +32,26 @@ #include +const int buffer_size = 20; + static int EtherNtoaTest(void) { - struct ether_addr addr = {{11,12,13,14,15,16}}, *eaddr = &addr; + struct ether_addr addr, *eaddr = &addr; + srand(time(NULL)); + int r[ETH_ALEN]; + for (int i = 0; i < ETH_ALEN; i++) { + r[i] = rand() % 16; // 16: 0x0-0xf + eaddr->ether_addr_octet[i] = r[i]; + } char *buf = ether_ntoa(eaddr); + char str1[buffer_size], str2[buffer_size]; + // 0, 1, 2, 3, 4, 5: 6 elements of mac address. + (void)sprintf_s(str1, sizeof(str1), "%x:%x:%x:%x:%x:%x", r[0], r[1], r[2], r[3], r[4], r[5]); + // 0, 1, 2, 3, 4, 5: 6 elements of mac address. + (void)sprintf_s(str2, sizeof(str2), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]); ICUNIT_ASSERT_NOT_EQUAL(buf, 0, -1); - ICUNIT_ASSERT_EQUAL((stricmp("b:c:d:e:f:10", buf) == 0 || stricmp("0b:0c:0d:0e:0f:10", buf) == 0), 1, printf("%s\n", buf)); + ICUNIT_ASSERT_EQUAL((stricmp(str1, buf) == 0 || stricmp(str2, buf) == 0), 1, printf("%s\n", buf)); return ICUNIT_SUCCESS; } diff --git a/testsuites/unittest/net/resolv/smoke/net_resolv_test_007.cpp b/testsuites/unittest/net/resolv/smoke/net_resolv_test_007.cpp index a509c97a..d6508c21 100644 --- a/testsuites/unittest/net/resolv/smoke/net_resolv_test_007.cpp +++ b/testsuites/unittest/net/resolv/smoke/net_resolv_test_007.cpp @@ -31,13 +31,27 @@ #include +const int buffer_size = 20; + static int EtherNtoarTest(void) { - struct ether_addr addr = {{11,12,13,4,15,16}}, *eaddr = &addr; + struct ether_addr addr, *eaddr = &addr; + srand(time(NULL)); + int r[ETH_ALEN]; + for (int i = 0; i < ETH_ALEN; i++) { + r[i] = rand() % 16; // 16: 0x0-0xf + eaddr->ether_addr_octet[i] = r[i]; + } char buf[100], *p = ether_ntoa_r(eaddr, buf); + char str1[buffer_size], str2[buffer_size]; + // 0, 1, 2, 3, 4, 5: 6 elements of mac address. + (void)sprintf_s(str1, sizeof(str1), "%x:%x:%x:%x:%x:%x", r[0], r[1], r[2], r[3], r[4], r[5]); + // 0, 1, 2, 3, 4, 5: 6 elements of mac address. + (void)sprintf_s(str2, sizeof(str2), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]); + ICUNIT_ASSERT_EQUAL(p, buf, (intptr_t)p); - ICUNIT_ASSERT_EQUAL((stricmp("b:c:d:4:f:10", buf) == 0 || stricmp("0b:0c:0d:04:0f:10", buf) == 0), 1, printf("%s\n", p)); + ICUNIT_ASSERT_EQUAL((stricmp(str1, buf) == 0 || stricmp(str2, buf) == 0), 1, printf("%s\n", p)); return ICUNIT_SUCCESS; } -- GitLab