[PATCH v2] posix: Avoid a stack overflow when glob is given many trailing slashes [BZ #30635]
Florian Weimer
fweimer@redhat.com
Wed Oct 8 12:23:39 GMT 2025
* Andreas Schwab:
> On Okt 07 2025, Collin Funk wrote:
>
>> diff --git a/posix/glob.c b/posix/glob.c
>> index a7c7dd1ebe..82ee873d80 100644
>> --- a/posix/glob.c
>> +++ b/posix/glob.c
>> @@ -596,6 +596,10 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
>> flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
>> }
>> }
>> + /* Prevent stack overflows with many trailing '/' characters. */
>> + for (char *p = &dirname[dirlen - 1];
>> + dirname < p && p[0] == '/' && p[-1] == '/'; --p)
> p > dirname
See <https://www.enyo.de/fw/notes/style-guide-conditions.html>
for some background.
Thanks,
Florian
More information about the Libc-alpha
mailing list