From 031d4eef8d055fbdae8d2fe4f59047e83601a15d Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Fri, 25 Nov 2016 20:55:22 +0100 Subject: Fix handling of unterminated [ expression in fnmatch. Originally fixed in GNU libc by: commit 794c3ad3a405697e2663b00f616e319383b9bb7d Author: Ulrich Drepper Date: Fri Jan 14 08:06:22 2011 -0500 Reported-by: Denys Vlasenko via busybox mailinglist. --- libc/misc/fnmatch/fnmatch_loop.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libc/misc/fnmatch/fnmatch_loop.c b/libc/misc/fnmatch/fnmatch_loop.c index 6d037f8f9..a09cfbb11 100644 --- a/libc/misc/fnmatch/fnmatch_loop.c +++ b/libc/misc/fnmatch/fnmatch_loop.c @@ -204,6 +204,8 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, case L('['): { /* Nonzero if the sense of the character class is inverted. */ + CHAR *p_init = p; + CHAR *n_init = n; register int not; CHAR cold; UCHAR fn; @@ -409,8 +411,13 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, } #endif else if (c == L('\0')) - /* [ (unterminated) loses. */ - return FNM_NOMATCH; + { + /* [ unterminated, treat as normal character. */ + p = p_init; + n = n_init; + c = L('['); + goto normal_match; + } else { int is_range = 0; -- cgit v1.2.3