diff options
author | Jan Janssen <medhefgo@web.de> | 2022-06-01 13:35:29 +0200 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2022-06-10 11:50:13 +0200 |
commit | 72bd3458e53bbdea2d96fd61271dbea2c4aee5bf (patch) | |
tree | 74ebb59873a3d3237e0ad51503ffc55e87c61eff /src/boot/efi/test-efi-string.c | |
parent | Merge pull request #23688 from yuwata/boot-efi-string-efi_fnmatch-fix-over-flow (diff) | |
download | systemd-72bd3458e53bbdea2d96fd61271dbea2c4aee5bf.tar.xz systemd-72bd3458e53bbdea2d96fd61271dbea2c4aee5bf.zip |
boot: Add parse_number8/16
Diffstat (limited to '')
-rw-r--r-- | src/boot/efi/test-efi-string.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/boot/efi/test-efi-string.c b/src/boot/efi/test-efi-string.c index 178ad766cb..0bfb564e3d 100644 --- a/src/boot/efi/test-efi-string.c +++ b/src/boot/efi/test-efi-string.c @@ -371,6 +371,60 @@ TEST(efi_fnmatch) { TEST_FNMATCH_ONE("?a*b[.-0]c", "/a/b/c", true); } +TEST(parse_number8) { + uint64_t u; + const char *tail; + + assert_se(!parse_number8(NULL, &u, NULL)); + assert_se(!parse_number8("", &u, NULL)); + assert_se(!parse_number8("a1", &u, NULL)); + assert_se(!parse_number8("1a", &u, NULL)); + assert_se(!parse_number8("-42", &u, NULL)); + assert_se(!parse_number8("18446744073709551616", &u, NULL)); + + assert_se(parse_number8("0", &u, NULL)); + assert_se(u == 0); + assert_se(parse_number8("1", &u, NULL)); + assert_se(u == 1); + assert_se(parse_number8("999", &u, NULL)); + assert_se(u == 999); + assert_se(parse_number8("18446744073709551615", &u, NULL)); + assert_se(u == UINT64_MAX); + assert_se(parse_number8("42", &u, &tail)); + assert_se(u == 42); + assert_se(streq8(tail, "")); + assert_se(parse_number8("54321rest", &u, &tail)); + assert_se(u == 54321); + assert_se(streq8(tail, "rest")); +} + +TEST(parse_number16) { + uint64_t u; + const char16_t *tail; + + assert_se(!parse_number16(NULL, &u, NULL)); + assert_se(!parse_number16(u"", &u, NULL)); + assert_se(!parse_number16(u"a1", &u, NULL)); + assert_se(!parse_number16(u"1a", &u, NULL)); + assert_se(!parse_number16(u"-42", &u, NULL)); + assert_se(!parse_number16(u"18446744073709551616", &u, NULL)); + + assert_se(parse_number16(u"0", &u, NULL)); + assert_se(u == 0); + assert_se(parse_number16(u"1", &u, NULL)); + assert_se(u == 1); + assert_se(parse_number16(u"999", &u, NULL)); + assert_se(u == 999); + assert_se(parse_number16(u"18446744073709551615", &u, NULL)); + assert_se(u == UINT64_MAX); + assert_se(parse_number16(u"42", &u, &tail)); + assert_se(u == 42); + assert_se(streq16(tail, u"")); + assert_se(parse_number16(u"54321rest", &u, &tail)); + assert_se(u == 54321); + assert_se(streq16(tail, u"rest")); +} + TEST(efi_memcmp) { assert_se(efi_memcmp(NULL, NULL, 0) == 0); assert_se(efi_memcmp(NULL, NULL, 1) == 0); |