]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot/efi-string: check the end of haystack before testing remaining pattern 23688/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 10 Jun 2022 02:43:00 +0000 (11:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 10 Jun 2022 03:05:38 +0000 (12:05 +0900)
Fixes buffer-overflow reported at https://github.com/systemd/systemd/pull/23589#issuecomment-1151820341.

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

index 80ef0ff076f9c5b582ac029d0b7be90b60d684ec..b9ef1548ca24494fe21ab6b1c460905a60aebc97 100644 (file)
@@ -170,15 +170,11 @@ static bool efi_fnmatch_internal(const char16_t *p, const char16_t *h, int max_d
                         while (*p == '*')
                                 p++;
 
-                        do {
+                        for (; *h != '\0'; h++)
                                 /* Try matching haystack with remaining pattern. */
                                 if (efi_fnmatch_internal(p, h, max_depth - 1))
                                         return true;
 
-                                /* Otherwise, we match one char here. */
-                                h++;
-                        } while (*h != '\0');
-
                         /* End of haystack. Pattern needs to be empty too for a match. */
                         return *p == '\0';
 
index 5aaa1f713fd43b2a5b4fcb25ecf95d3a3ec1c4fe..178ad766cb460675aff6ceb065351fc89cc77ebb 100644 (file)
@@ -344,6 +344,7 @@ TEST(efi_fnmatch) {
         TEST_FNMATCH_ONE("*", "123", true);
         TEST_FNMATCH_ONE("**", "abcd", true);
         TEST_FNMATCH_ONE("*b*", "abcd", true);
+        TEST_FNMATCH_ONE("abc*d", "abc", false);
         TEST_FNMATCH_ONE("*.conf", "arch.conf", true);
         TEST_FNMATCH_ONE("debian-*.conf", "debian-wheezy.conf", true);
         TEST_FNMATCH_ONE("debian-*.*", "debian-wheezy.efi", true);