Browse Source

Fix handling of unterminated [ expression in fnmatch.

Originally fixed in GNU libc by:

commit 794c3ad3a405697e2663b00f616e319383b9bb7d
Author: Ulrich Drepper <drepper@gmail.com>
Date:   Fri Jan 14 08:06:22 2011 -0500

Reported-by: Denys Vlasenko <vda.linux@googlemail.com>

via busybox mailinglist.
Waldemar Brodkorb 8 years ago
parent
commit
031d4eef8d
1 changed files with 9 additions and 2 deletions
  1. 9 2
      libc/misc/fnmatch/fnmatch_loop.c

+ 9 - 2
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;