From: Daan De Meyer Date: Mon, 30 Jan 2023 15:22:10 +0000 (+0100) Subject: efi-string: Fix strchr() null byte handling X-Git-Tag: v254-rc1~1172^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbef5a9617e91b4b1bc30266eb9dcbda395a8c61;p=thirdparty%2Fsystemd.git efi-string: Fix strchr() null byte handling strchr() should be able to search for the terminating null byte, our implementation doesn't, let's fix that. --- diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c index ee3dc1c4a95..dd71123e9f0 100644 --- a/src/boot/efi/efi-string.c +++ b/src/boot/efi/efi-string.c @@ -112,7 +112,7 @@ DEFINE_STRCPY(char16_t, strcpy16); s++; \ } \ \ - return NULL; \ + return c ? NULL : (type *) s; \ } DEFINE_STRCHR(char, strchr8); diff --git a/src/boot/efi/test-efi-string.c b/src/boot/efi/test-efi-string.c index c26973d8bd1..c7e42c7b940 100644 --- a/src/boot/efi/test-efi-string.c +++ b/src/boot/efi/test-efi-string.c @@ -229,6 +229,8 @@ TEST(strchr8) { assert_se(strchr8(str, 'a') == &str[0]); assert_se(strchr8(str, 'c') == &str[2]); assert_se(strchr8(str, 'B') == &str[4]); + + assert_se(strchr8(str, 0) == str + strlen8(str)); } TEST(strchr16) { @@ -240,6 +242,8 @@ TEST(strchr16) { assert_se(strchr16(str, 'a') == &str[0]); assert_se(strchr16(str, 'c') == &str[2]); assert_se(strchr16(str, 'B') == &str[4]); + + assert_se(strchr16(str, 0) == str + strlen16(str)); } TEST(xstrndup8) {