]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib: glob.c: added null check for character class
authorAlok Swaminathan <swaminathanalok@gmail.com>
Mon, 26 Aug 2024 15:57:09 +0000 (11:57 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 9 Sep 2024 23:47:41 +0000 (16:47 -0700)
Add null check for character class.  Previously, an inverted character
class could result in a nul byte being matched and lead to the function
reading past the end of the inputted string.

Link: https://lkml.kernel.org/r/20240826155709.12383-1-swaminathanalok@gmail.com
Signed-off-by: Alok Swaminathan <swaminathanalok@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/glob.c

index 15b73f490720c002afa393d1864da9d88a02ad36..aa57900d2062c0d8082522fc0768287b1d6ae738 100644 (file)
@@ -68,6 +68,8 @@ bool __pure glob_match(char const *pat, char const *str)
                        back_str = --str;       /* Allow zero-length match */
                        break;
                case '[': {     /* Character class */
+                       if (c == '\0')  /* No possible match */
+                               return false;
                        bool match = false, inverted = (*pat == '!');
                        char const *class = pat + inverted;
                        unsigned char a = *class++;