summaryrefslogtreecommitdiff
path: root/lib/fnmatch_loop.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-10-17 08:28:13 +0000
committerJim Meyering <jim@meyering.net>2003-10-17 08:28:13 +0000
commit777cf19af38df5a459cae1ce8dcd082409560719 (patch)
tree6482dccb8144bc33f49adb820257e9c569c123dc /lib/fnmatch_loop.c
parent48cfcdf50126c181f9ff5892ab3e049aa26f0593 (diff)
downloadcoreutils-777cf19af38df5a459cae1ce8dcd082409560719.tar.xz
Update from gnulib.
Diffstat (limited to 'lib/fnmatch_loop.c')
-rw-r--r--lib/fnmatch_loop.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c
index a83dd9616..1a1e9cfb2 100644
--- a/lib/fnmatch_loop.c
+++ b/lib/fnmatch_loop.c
@@ -1042,16 +1042,23 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (level-- == 0)
{
/* This means we found the end of the pattern. */
+#define ALLOCA_LIMIT 8000
#define NEW_PATTERN \
struct patternlist *newp; \
size_t plen; \
+ size_t plensize; \
+ size_t newpsize; \
\
plen = (opt == L('?') || opt == L('@') \
? pattern_len \
: p - startp + 1); \
- newp = (struct patternlist *) \
- alloca (offsetof (struct patternlist, str) \
- + (plen * sizeof (CHAR))); \
+ plensize = plen * sizeof (CHAR); \
+ newpsize = offsetof (struct patternlist, str) + plensize; \
+ if ((size_t) -1 / sizeof (CHAR) < plen \
+ || newpsize < offsetof (struct patternlist, str) \
+ || ALLOCA_LIMIT <= newpsize) \
+ return -1; \
+ newp = (struct patternlist *) alloca (newpsize); \
*((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L('\0'); \
newp->next = NULL; \
*lastp = newp; \