ping//Re: [PATCH v2] io:nftw/ftw:fix stack overflow when large nopenfd [BZ #26353]
Xiaoming Ni
nixiaoming@huawei.com
Mon Aug 24 08:31:29 GMT 2020
On 2020/8/23 2:09, Paul Eggert wrote:
> On 8/21/20 8:27 PM, Xiaoming Ni wrote:
>> How do I determine whether data.maxdir is too large for alloca?
>
> __libc_use_alloca. Also see include/scratch_buffer.h, which is designed
> for this sort of situation.
>
> .
is that ?
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -645,6 +645,13 @@ ftw_startup (const char *dir, int is_nftw, void
*func, int descriptors,
}
data.maxdir = descriptors < 1 ? 1 : descriptors;
+ if ((__glibc_unlikely (data.maxdir > SIZE_MAX / sizeof (struct
dir_data *)))
+ || (! __libc_use_alloca (data.maxdir * sizeof (struct dir_data *))))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
data.actdir = 0;
data.dirstreams = (struct dir_data **) alloca (data.maxdir
* sizeof (struct
dir_data *));
Whether to use malloc or return an error message when the input is too
large?
I still don't understand why libc uses alloca so much.
Is it for performance?
Thanks
Xiaoming Ni
More information about the Libc-alpha
mailing list