Skip to content

Commit

Permalink
Check size of pattern in wide character representation in fnmatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Mar 18, 2011
1 parent ccfe366 commit 8126d90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2011-03-18 Ulrich Drepper <drepper@gmail.com>

* posix/fnmatch.c (fnmatch): Check size of pattern in wide
character representation.
Partly based on a patch by Tomas Hoger <thoger@redhat.com>.

2011-03-16 Ryan S. Arnold <rsa@us.ibm.com>

* sysdeps/powerpc/powerpc32/power6/fpu/s_isnanf.S (isnanf): Fix
Expand Down
13 changes: 12 additions & 1 deletion posix/fnmatch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2007,2010
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2007,2010,2011
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Expand Down Expand Up @@ -375,6 +375,11 @@ fnmatch (pattern, string, flags)
XXX Do we have to set `errno' to something which mbsrtows hasn't
already done? */
return -1;
if (__builtin_expect (n >= (size_t) -1 / sizeof (wchar_t), 0))
{
__set_errno (ENOMEM);
return -2;
}
wpattern_malloc = wpattern
= (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
assert (mbsinit (&ps));
Expand Down Expand Up @@ -419,6 +424,12 @@ fnmatch (pattern, string, flags)
XXX Do we have to set `errno' to something which mbsrtows hasn't
already done? */
goto free_return;
if (__builtin_expect (n >= (size_t) -1 / sizeof (wchar_t), 0))
{
free (wpattern_malloc);
__set_errno (ENOMEM);
return -2;
}

wstring_malloc = wstring
= (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
Expand Down

0 comments on commit 8126d90

Please sign in to comment.