]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: don't unquote an empty value in line_get_key_value()
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 26 Jun 2026 18:41:31 +0000 (19:41 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 3 Jul 2026 14:19:39 +0000 (15:19 +0100)
de0da85d41b switched the unquote check to strchr8(QUOTES, value[0]),
which is not equivalent to the old explicit comparison for an empty
value: strchr8(), like strchr(3), returns a pointer to the haystack's
terminating NUL when the needle is '\0', so strchr8(QUOTES, '\0') is
non-NULL. For a line whose separator is the last byte (e.g. "ID=") the
split leaves value[0] == '\0' and line[linelen - 1] == '\0' too, so both
conjuncts hold and value++ steps one byte past the value's terminator.

Follow-up for de0da85d41b207b850aa0f68bb2436525389cf2b

src/boot/efi-string.c
src/boot/test-efi-string.c

index 306446386271acfdd6710d284ba56a2e3398c7c5..efe1553696ddfa65ecdd609c90a545616c8ecbe3 100644 (file)
@@ -500,7 +500,7 @@ char* line_get_key_value(char *s, const char *sep, size_t *pos, char **ret_key,
                         value++;
 
                 /* unquote */
-                if (strchr8(QUOTES, value[0]) && line[linelen - 1] == value[0]) {
+                if (value[0] != '\0' && strchr8(QUOTES, value[0]) && line[linelen - 1] == value[0]) {
                         value++;
                         line[linelen - 1] = '\0';
                 }
index 7633534dd4c07847ff645f968e76eeb78285609f..5805cb302412d006fb8e7b69dd22b4b164d81bb0 100644 (file)
@@ -590,6 +590,7 @@ TEST(line_get_key_value) {
                     "  also\tused  \r\n"
                     "for \"the conf\"\n"
                     "format\t !!";
+        char s3[] = "ID=";
         size_t pos = 0;
         char *key, *value;
 
@@ -611,6 +612,11 @@ TEST(line_get_key_value) {
         ASSERT_TRUE(streq8(value, " stripping  # with comments"));
         ASSERT_NULL(line_get_key_value(s1, "=", &pos, &key, &value));
 
+        pos = 0;
+        ASSERT_NOT_NULL(line_get_key_value(s3, "=", &pos, &key, &value));
+        ASSERT_TRUE(streq8(key, "ID"));
+        ASSERT_TRUE(streq8(value, ""));
+
         pos = 0;
         ASSERT_NOT_NULL(line_get_key_value(s2, " \t", &pos, &key, &value));
         ASSERT_TRUE(streq8(key, "this"));