From: Xiaoming Ni <nixiaoming@huawei.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: <libc-alpha@sourceware.org>
Subject: Re: ping//Re: [PATCH v2] io:nftw/ftw:fix stack overflow when large nopenfd [BZ #26353]
Date: Mon, 24 Aug 2020 16:31:29 +0800 [thread overview]
Message-ID: <93ac7fed-d7e9-eb46-f8fd-407bd606eb52@huawei.com> (raw)
In-Reply-To: <c6bd72ec-7791-7166-4500-a9b37210e7b4@cs.ucla.edu>
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
next prev parent reply other threads:[~2020-08-24 8:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-15 7:08 Xiaoming Ni
2020-08-22 2:23 ` ping//Re: " Xiaoming Ni
2020-08-22 2:51 ` Paul Eggert
2020-08-22 3:27 ` Xiaoming Ni
2020-08-22 18:09 ` Paul Eggert
2020-08-24 8:31 ` Xiaoming Ni [this message]
2020-08-24 14:32 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93ac7fed-d7e9-eb46-f8fd-407bd606eb52@huawei.com \
--to=nixiaoming@huawei.com \
--cc=eggert@cs.ucla.edu \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).