[4/6] posix: Use malloc instead of alloca for the glob brace expansion
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
The last alloca in __glob is the buffer holding one expansion of a
brace expression. As with the directory and user names, the stack it
takes is not bounded by the call itself.
Use malloc unconditionally. __glob no longer uses alloca; glob_in_dir
still does, so the accounting stays for now.
Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.
---
posix/glob.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
Comments
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> The last alloca in __glob is the buffer holding one expansion of a
> brace expression. As with the directory and user names, the stack it
> takes is not bounded by the call itself.
>
> Use malloc unconditionally. __glob no longer uses alloca; glob_in_dir
> still does, so the accounting stays for now.
>
> Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.
> ---
> posix/glob.c | 22 +++++++---------------
> 1 file changed, 7 insertions(+), 15 deletions(-)
This one looks good as well.
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
I'll review the other two patches tomorrow or Friday. Since they are a
bit more complicated, I want to make sure I have time to give them a
good look over.
Thanks,
Collin
@@ -483,15 +483,10 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
size_t rest_len;
char *onealt;
size_t pattern_len = strlen (pattern) - 1;
- int alloca_onealt = glob_use_alloca (alloca_used, pattern_len);
- if (alloca_onealt)
- onealt = alloca_account (pattern_len, alloca_used);
- else
- {
- onealt = malloc (pattern_len);
- if (onealt == NULL)
- return GLOB_NOSPACE;
- }
+
+ onealt = malloc (pattern_len);
+ if (onealt == NULL)
+ return GLOB_NOSPACE;
/* We know the prefix for all sub-patterns. */
alt_start = mempcpy (onealt, pattern, begin - pattern);
@@ -503,8 +498,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
{
/* It is an invalid expression. */
illegal_brace:
- if (__glibc_unlikely (!alloca_onealt))
- free (onealt);
+ free (onealt);
flags &= ~GLOB_BRACE;
goto no_brace;
}
@@ -545,8 +539,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
/* If we got an error, return it. */
if (result && result != GLOB_NOMATCH)
{
- if (__glibc_unlikely (!alloca_onealt))
- free (onealt);
+ free (onealt);
if (!(flags & GLOB_APPEND))
{
globfree (pglob);
@@ -564,8 +557,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
assert (next != NULL);
}
- if (__glibc_unlikely (!alloca_onealt))
- free (onealt);
+ free (onealt);
if (pglob->gl_pathc != firstc)
/* We found some entries. */