FIx handling of unterminated [ expression in fnmatch.

This commit is contained in:
Ulrich Drepper 2011-01-14 08:06:22 -05:00
parent 68dc949774
commit 794c3ad3a4
7 changed files with 43 additions and 16 deletions

View File

@ -1,3 +1,14 @@
2011-01-14 Ulrich Drepper <drepper@gmail.com>
[BZ #12378]
* posix/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.
* posix/testfnm.c: Adjust test result.
* posix/globtest.sh: Adjust test result. Add new test.
* posix/tst-fnmatch.input: Likewise.
* posix/tst-fnmatch2.c: Add new test.
2010-12-28 Andreas Schwab <schwab@linux-m68k.org> 2010-12-28 Andreas Schwab <schwab@linux-m68k.org>
* elf/Makefile (check-execstack): Revert last change. Depend on * elf/Makefile (check-execstack): Revert last change. Depend on

4
NEWS
View File

@ -1,4 +1,4 @@
GNU C Library NEWS -- history of user-visible changes. 2011-1-13 GNU C Library NEWS -- history of user-visible changes. 2011-1-14
Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc. Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc.
See the end for copying conditions. See the end for copying conditions.
@ -12,7 +12,7 @@ Version 2.13
3268, 7066, 10085, 10484, 10851, 11149, 11155, 11611, 11640, 11655, 11701, 3268, 7066, 10085, 10484, 10851, 11149, 11155, 11611, 11640, 11655, 11701,
11840, 11856, 11883, 11903, 11904, 11968, 11979, 12005, 12037, 12067, 11840, 11856, 11883, 11903, 11904, 11968, 11979, 12005, 12037, 12067,
12077, 12078, 12092, 12093, 12107, 12108, 12113, 12140, 12159, 12167, 12077, 12078, 12092, 12093, 12107, 12108, 12113, 12140, 12159, 12167,
12191, 12194, 12201, 12204, 12205, 12207, 12348, 12394, 12397 12191, 12194, 12201, 12204, 12205, 12207, 12348, 12378, 12394, 12397
* New Linux interfaces: prlimit, prlimit64, fanotify_init, fanotify_mark * New Linux interfaces: prlimit, prlimit64, fanotify_init, fanotify_mark

View File

@ -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. Free Software Foundation, Inc.
This file is part of the GNU C Library. 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('['): case L('['):
{ {
/* Nonzero if the sense of the character class is inverted. */ /* Nonzero if the sense of the character class is inverted. */
CHAR *p_init = p;
CHAR *n_init = n;
register int not; register int not;
CHAR cold; CHAR cold;
UCHAR fn; UCHAR fn;
@ -445,8 +447,13 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
} }
#endif #endif
else if (c == L('\0')) 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 else
{ {
int is_range = 0; int is_range = 0;

View File

@ -722,21 +722,24 @@ ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -c "$testdir" \ ${common_objpfx}posix/globtest -c "$testdir" \
'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \ '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]' \ '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 sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`di*r4[a/file2'
`dir*6/file1[a'
`dir*6/file1[ab]' `dir*6/file1[ab]'
`dir1/file1_1' `dir1/file1_1'
`dir1/file\1_9' `dir1/file\1_9'
`dir2/' `dir2/'
`dir3*/file1' `dir3*/file1'
`dir3\*/file2' `dir3\*/file2'
`dir4[a/fil*1' `dir4[a/file1'
`dir4[a/file2'
`dir5[ab]/file[12]' `dir5[ab]/file[12]'
`dir6/fi*l[ab]' `dir6/fi*l[ab]'
`dir6/fil*[a' `dir6/file1[a'
`dir6/file1[a'
`dir6/file1[a'
`dir6/file1[ab]'
`nondir\/' `nondir\/'
EOF EOF
HOME="$testdir" \ HOME="$testdir" \

View File

@ -26,7 +26,7 @@ struct {
{ "*/b", "\\*/b", 0, 0 }, { "*/b", "\\*/b", 0, 0 },
{ "a/b", "\\?/b", 0, FNM_NOMATCH }, { "a/b", "\\?/b", 0, FNM_NOMATCH },
{ "?/b", "\\?/b", 0, 0 }, { "?/b", "\\?/b", 0, 0 },
{ "[/b", "[/b", 0, FNM_NOMATCH }, { "[/b", "[/b", 0, 0 },
{ "[/b", "\\[/b", 0, 0 }, { "[/b", "\\[/b", 0, 0 },
{ "aa/b", "?""?/b", 0, 0 }, { "aa/b", "?""?/b", 0, 0 },
{ "aa/b", "?""?""?b", 0, 0 }, { "aa/b", "?""?""?b", 0, 0 },

View File

@ -1,5 +1,5 @@
# Tests for fnmatch. # 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. # This file is part of the GNU C Library.
# Contributes by Ulrich Drepper <drepper@redhat.com>. # Contributes by Ulrich Drepper <drepper@redhat.com>.
# #
@ -65,10 +65,10 @@ C "a" "[!abc]" NOMATCH
C "]" "[][abc]" 0 C "]" "[][abc]" 0
C "abc]" "[][abc]" NOMATCH C "abc]" "[][abc]" NOMATCH
C "[]abc" "[][]abc" NOMATCH C "[]abc" "[][]abc" NOMATCH
C "]" "[!]]" NOMATCH C "]" "[!]]" NOMATCH
C "aa]" "[!]a]" NOMATCH C "aa]" "[!]a]" NOMATCH
C "]" "[!a]" 0 C "]" "[!a]" 0
C "]]" "[!a]]" 0 C "]]" "[!a]]" 0
# B.6 012(C) # B.6 012(C)
C "a" "[[.a.]]" 0 C "a" "[[.a.]]" 0
@ -340,7 +340,8 @@ C "/.a/.b" "/*b" NOMATCH PATHNAME
# B.6 031(C) # B.6 031(C)
C "/$" "\\/\\$" 0 C "/$" "\\/\\$" 0
C "/[" "\\/\\[" 0 C "/[" "\\/\\[" 0
C "/[" "\\/[" NOMATCH C "/[" "\\/[" 0
C "/[]" "\\/\\[]" 0
# B.6 032(C) # B.6 032(C)
C "/$" "\\/\\$" NOMATCH NOESCAPE C "/$" "\\/\\$" NOMATCH NOESCAPE

View File

@ -28,6 +28,11 @@ do_test (void)
puts ("Fourth fnmatch didn't return 0"); puts ("Fourth fnmatch didn't return 0");
return 1; return 1;
} }
if (fnmatch ("[", "[", 0) != 0)
{
puts ("Fifth fnmatch didn't return 0");
return 1;
}
return 0; return 0;
} }