about summary refs log tree commit diff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/fnmatch_loop.c13
-rwxr-xr-xposix/globtest.sh13
-rw-r--r--posix/testfnm.c2
-rw-r--r--posix/tst-fnmatch.input11
-rw-r--r--posix/tst-fnmatch2.c5
5 files changed, 30 insertions, 14 deletions
diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c
index 6b0224ea2c..5c15f46fd9 100644
--- a/posix/fnmatch_loop.c
+++ b/posix/fnmatch_loop.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1993,1996-2001,2003-2005,2007,2010
+/* Copyright (C) 1991-1993,1996-2001,2003-2005,2007,2010,2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -235,6 +235,8 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
 	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;
@@ -445,8 +447,13 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
 		  }
 #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;
diff --git a/posix/globtest.sh b/posix/globtest.sh
index aadac87796..9b9021d690 100755
--- a/posix/globtest.sh
+++ b/posix/globtest.sh
@@ -722,21 +722,24 @@ ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
 ${common_objpfx}posix/globtest -c "$testdir" \
 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
-'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' |
+'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' \
+'dir6/file1[[.a.]*' |
 sort > $testout
 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
-`di*r4[a/file2'
-`dir*6/file1[a'
 `dir*6/file1[ab]'
 `dir1/file1_1'
 `dir1/file\1_9'
 `dir2/'
 `dir3*/file1'
 `dir3\*/file2'
-`dir4[a/fil*1'
+`dir4[a/file1'
+`dir4[a/file2'
 `dir5[ab]/file[12]'
 `dir6/fi*l[ab]'
-`dir6/fil*[a'
+`dir6/file1[a'
+`dir6/file1[a'
+`dir6/file1[a'
+`dir6/file1[ab]'
 `nondir\/'
 EOF
 HOME="$testdir" \
diff --git a/posix/testfnm.c b/posix/testfnm.c
index f3165324e9..7a04d2a912 100644
--- a/posix/testfnm.c
+++ b/posix/testfnm.c
@@ -26,7 +26,7 @@ struct {
   { "*/b", "\\*/b", 0, 0 },
   { "a/b", "\\?/b", 0, FNM_NOMATCH },
   { "?/b", "\\?/b", 0, 0 },
-  { "[/b", "[/b", 0, FNM_NOMATCH },
+  { "[/b", "[/b", 0, 0 },
   { "[/b", "\\[/b", 0, 0 },
   { "aa/b", "?""?/b", 0, 0 },
   { "aa/b", "?""?""?b", 0, 0 },
diff --git a/posix/tst-fnmatch.input b/posix/tst-fnmatch.input
index 9061d19945..a799097768 100644
--- a/posix/tst-fnmatch.input
+++ b/posix/tst-fnmatch.input
@@ -1,5 +1,5 @@
 # Tests for fnmatch.
-# Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2004, 2011 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 # Contributes by Ulrich Drepper <drepper@redhat.com>.
 #
@@ -65,10 +65,10 @@ C		 "a"			"[!abc]"	       NOMATCH
 C		 "]"			"[][abc]"	       0
 C		 "abc]"			"[][abc]"	       NOMATCH
 C		 "[]abc"		"[][]abc"	       NOMATCH
-C		 "]"		        "[!]]"		       NOMATCH
+C		 "]"			"[!]]"		       NOMATCH
 C		 "aa]"			"[!]a]"		       NOMATCH
-C		 "]"		        "[!a]"		       0
-C		 "]]"		        "[!a]]"		       0
+C		 "]"			"[!a]"		       0
+C		 "]]"			"[!a]]"		       0
 
 # B.6 012(C)
 C		 "a"			"[[.a.]]"	       0
@@ -340,7 +340,8 @@ C		 "/.a/.b"		"/*b"		       NOMATCH PATHNAME
 # B.6 031(C)
 C		 "/$"			"\\/\\$"	       0
 C		 "/["			"\\/\\["	       0
-C		 "/["			"\\/["		       NOMATCH
+C		 "/["			"\\/["		       0
+C		 "/[]"			"\\/\\[]"	       0
 
 # B.6 032(C)
 C		 "/$"			"\\/\\$"	       NOMATCH NOESCAPE
diff --git a/posix/tst-fnmatch2.c b/posix/tst-fnmatch2.c
index 28a0871c1c..e66a01f592 100644
--- a/posix/tst-fnmatch2.c
+++ b/posix/tst-fnmatch2.c
@@ -28,6 +28,11 @@ do_test (void)
       puts ("Fourth fnmatch didn't return 0");
       return 1;
     }
+  if (fnmatch ("[", "[", 0) != 0)
+    {
+      puts ("Fifth fnmatch didn't return 0");
+      return 1;
+    }
   return 0;
 }