Skip to contentSkip to conversation

lib: glob.c: added null check for character class

PATCH Applied Alok Swaminathan 1 participant 1 message Aug 26, 2024 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: glob.c: added null check for character class

Added 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 str.

---
 lib/glob.c | 2 ++
 1 file changed, 2 insertions(+)
lib/glob.c +2 -0
index 15b73f490720..aa57900d2062 100644
@@ -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++;
Signature · 1 line
2.46.0