fnmatch: sync glibc change fixing Bugzilla bug #12378
authorJames Youngman <jay@gnu.org>
Thu, 12 May 2011 21:14:11 +0000 (22:14 +0100)
committerEric Blake <eblake@redhat.com>
Sat, 14 May 2011 03:06:50 +0000 (21:06 -0600)
* lib/fnmatch_loop.c (FCT): When matching '[' keep track of
beginning and fall back to matching as normal character if the
string ends before the matching ']' is found.  This is what POSIX
requires.

ChangeLog
lib/fnmatch_loop.c

index a174518..f5e33cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-05-11  Ulrich Drepper  <drepper@gmail.com>
+
+       Sync glibc change fixing Bugzilla bug #12378.
+       * lib/fnmatch_loop.c (FCT): When matching '[' keep track of
+       beginning and fall back to matching as normal character if the
+       string ends before the matching ']' is found.  This is what POSIX
+       requires.
+
 2011-05-13  Eric Blake  <eblake@redhat.com>
 
        getcwd-lgpl: relax test for FreeBSD
index ed760dd..1fb246f 100644 (file)
@@ -200,6 +200,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 bool not;
             CHAR cold;
             UCHAR fn;
@@ -410,8 +412,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
                   {
                     bool is_range = false;