mirror of git://sourceware.org/git/glibc.git
Properly initialize glob structure with GLOB_BRACE|GLOB_DOOFFS (bug 20707)
This commit is contained in:
parent
93fe09cb5f
commit
44c637ce80
|
@ -1,3 +1,11 @@
|
||||||
|
2016-10-31 Andreas Schwab <schwab@suse.de>
|
||||||
|
|
||||||
|
[BZ #20707]
|
||||||
|
* posix/glob.c (glob): Initialize pglob before checking for
|
||||||
|
GLOB_BRACE. Don't call glob recursively if pattern contains no
|
||||||
|
valid brace expression despite GLOB_BRACE.
|
||||||
|
* posix/globtest.sh: Test it.
|
||||||
|
|
||||||
2016-10-28 Carlos O'Donell <carlos@redhat.com>
|
2016-10-28 Carlos O'Donell <carlos@redhat.com>
|
||||||
|
|
||||||
[BZ #20729]
|
[BZ #20729]
|
||||||
|
|
63
posix/glob.c
63
posix/glob.c
|
@ -312,6 +312,28 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
|
||||||
also makes all the code that uses gl_offs simpler. */
|
also makes all the code that uses gl_offs simpler. */
|
||||||
pglob->gl_offs = 0;
|
pglob->gl_offs = 0;
|
||||||
|
|
||||||
|
if (!(flags & GLOB_APPEND))
|
||||||
|
{
|
||||||
|
pglob->gl_pathc = 0;
|
||||||
|
if (!(flags & GLOB_DOOFFS))
|
||||||
|
pglob->gl_pathv = NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (pglob->gl_offs >= ~((size_t) 0) / sizeof (char *))
|
||||||
|
return GLOB_NOSPACE;
|
||||||
|
|
||||||
|
pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
|
||||||
|
* sizeof (char *));
|
||||||
|
if (pglob->gl_pathv == NULL)
|
||||||
|
return GLOB_NOSPACE;
|
||||||
|
|
||||||
|
for (i = 0; i <= pglob->gl_offs; ++i)
|
||||||
|
pglob->gl_pathv[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & GLOB_BRACE)
|
if (flags & GLOB_BRACE)
|
||||||
{
|
{
|
||||||
const char *begin;
|
const char *begin;
|
||||||
|
@ -359,15 +381,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
|
||||||
{
|
{
|
||||||
onealt = (char *) malloc (pattern_len);
|
onealt = (char *) malloc (pattern_len);
|
||||||
if (onealt == NULL)
|
if (onealt == NULL)
|
||||||
{
|
|
||||||
if (!(flags & GLOB_APPEND))
|
|
||||||
{
|
|
||||||
pglob->gl_pathc = 0;
|
|
||||||
pglob->gl_pathv = NULL;
|
|
||||||
}
|
|
||||||
return GLOB_NOSPACE;
|
return GLOB_NOSPACE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* We know the prefix for all sub-patterns. */
|
/* We know the prefix for all sub-patterns. */
|
||||||
alt_start = mempcpy (onealt, pattern, begin - pattern);
|
alt_start = mempcpy (onealt, pattern, begin - pattern);
|
||||||
|
@ -383,7 +398,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
|
||||||
if (__glibc_unlikely (!alloca_onealt))
|
if (__glibc_unlikely (!alloca_onealt))
|
||||||
#endif
|
#endif
|
||||||
free (onealt);
|
free (onealt);
|
||||||
return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
|
flags &= ~GLOB_BRACE;
|
||||||
|
goto no_brace;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now find the end of the whole brace expression. */
|
/* Now find the end of the whole brace expression. */
|
||||||
|
@ -404,14 +420,6 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
|
||||||
points past the final }. We will accumulate result names from
|
points past the final }. We will accumulate result names from
|
||||||
recursive runs for each brace alternative in the buffer using
|
recursive runs for each brace alternative in the buffer using
|
||||||
GLOB_APPEND. */
|
GLOB_APPEND. */
|
||||||
|
|
||||||
if (!(flags & GLOB_APPEND))
|
|
||||||
{
|
|
||||||
/* This call is to set a new vector, so clear out the
|
|
||||||
vector so we can append to it. */
|
|
||||||
pglob->gl_pathc = 0;
|
|
||||||
pglob->gl_pathv = NULL;
|
|
||||||
}
|
|
||||||
firstc = pglob->gl_pathc;
|
firstc = pglob->gl_pathc;
|
||||||
|
|
||||||
p = begin + 1;
|
p = begin + 1;
|
||||||
|
@ -463,28 +471,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & GLOB_APPEND))
|
no_brace:
|
||||||
{
|
|
||||||
pglob->gl_pathc = 0;
|
|
||||||
if (!(flags & GLOB_DOOFFS))
|
|
||||||
pglob->gl_pathv = NULL;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (pglob->gl_offs >= ~((size_t) 0) / sizeof (char *))
|
|
||||||
return GLOB_NOSPACE;
|
|
||||||
|
|
||||||
pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
|
|
||||||
* sizeof (char *));
|
|
||||||
if (pglob->gl_pathv == NULL)
|
|
||||||
return GLOB_NOSPACE;
|
|
||||||
|
|
||||||
for (i = 0; i <= pglob->gl_offs; ++i)
|
|
||||||
pglob->gl_pathv[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
oldcount = pglob->gl_pathc + pglob->gl_offs;
|
oldcount = pglob->gl_pathc + pglob->gl_offs;
|
||||||
|
|
||||||
/* Find the filename. */
|
/* Find the filename. */
|
||||||
|
|
|
@ -794,6 +794,22 @@ if test $failed -ne 0; then
|
||||||
result=1
|
result=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Test GLOB_BRACE and GLIB_DOOFFS with malloc checking
|
||||||
|
failed=0
|
||||||
|
${test_wrapper_env} \
|
||||||
|
MALLOC_PERTURB_=65 \
|
||||||
|
${test_via_rtld_prefix} \
|
||||||
|
${common_objpfx}posix/globtest -b -o "$testdir" "file{1,2}" > $testout || failed=1
|
||||||
|
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
|
||||||
|
`abc'
|
||||||
|
`file1'
|
||||||
|
`file2'
|
||||||
|
EOF
|
||||||
|
if test $failed -ne 0; then
|
||||||
|
echo "GLOB_BRACE+GLOB_DOOFFS test failed" >> $logfile
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
|
|
||||||
if test $result -eq 0; then
|
if test $result -eq 0; then
|
||||||
chmod 777 $testdir/noread
|
chmod 777 $testdir/noread
|
||||||
rm -fr $testdir $testout
|
rm -fr $testdir $testout
|
||||||
|
|
Loading…
Reference in New Issue