[PATCH v2] posix: Avoid a stack overflow when glob is given many trailing slashes [BZ #30635]
Collin Funk
collin.funk1@gmail.com
Wed Oct 8 15:03:11 GMT 2025
Florian Weimer <fweimer@redhat.com> writes:
> * 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.
I'll change it locally.
Thanks,
Collin
More information about the Libc-alpha
mailing list