From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Xiaoming Ni <nixiaoming@huawei.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 1/3] stdlib: Use fixed buffer size for realpath (BZ #26241)
Date: Thu, 13 Aug 2020 17:29:29 -0300 [thread overview]
Message-ID: <ce6fa716-de33-dbeb-1bcc-084f61fe1b67@linaro.org> (raw)
In-Reply-To: <eb51b9f2-ad44-69de-e987-3754477af93b@linaro.org>
On 12/08/2020 20:04, Adhemerval Zanella wrote:
>
>
> On 11/08/2020 22:38, Xiaoming Ni wrote:
> With something like below we can make the realpath uses a stack of about
> ~1024 and ~2048 if the path contains symbolic link:
>
> @@ -163,35 +204,19 @@ __realpath (const char *name, char *resolved)
>
> if (S_ISLNK (st.st_mode))
> {
> - char *buf = __alloca (path_max);
> - size_t len;
> -
> if (++num_links > __eloop_threshold ())
> {
> __set_errno (ELOOP);
> goto error;
> }
>
> - n = __readlink (rpath, buf, path_max - 1);
> - if (n < 0)
> + if (! realpath_readlink (rpath, end, path_max, st.st_size,
> + &extra_buf))
Scratch that, unfortunately some Linux filesystems do not return the symlink
target file size with a lstat call (procfs and sysfs for instance). So
we need to either issue multiple readlink with different increasing buffers
or assume PATH_MAX (as current algorithms does).
I will send a v3 of my patch to use a scratch buffer. What I am not sure is
if the Linux optimization is worth if the idea is use a small stack as possible
for common cases since it trades some syscall by a higher stack usage.
prev parent reply other threads:[~2020-08-13 20:29 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-10 20:48 Adhemerval Zanella
2020-08-10 20:48 ` [PATCH 2/3] stdlib: Enforce PATH_MAX on allocated realpath buffer Adhemerval Zanella
2020-08-11 8:26 ` Florian Weimer
2020-08-11 9:54 ` Andreas Schwab
2020-08-11 10:24 ` Florian Weimer
2020-08-11 15:05 ` Adhemerval Zanella
2020-08-11 15:37 ` Paul Eggert
2020-08-11 18:29 ` Florian Weimer
2020-08-11 9:48 ` Andreas Schwab
2020-08-10 20:48 ` [PATCH 3/3] linux: Optimize realpath stack usage Adhemerval Zanella
2020-08-10 21:25 ` Paul Eggert
2020-08-11 14:14 ` Adhemerval Zanella
2020-08-11 15:18 ` Adhemerval Zanella
2020-08-11 15:52 ` Paul Eggert
2020-08-11 19:01 ` Adhemerval Zanella
2020-08-11 16:46 ` Andreas Schwab
2020-08-17 14:00 ` Dmitry V. Levin
2020-08-17 15:13 ` Andreas Schwab
2020-08-17 16:17 ` Dmitry V. Levin
2020-08-11 9:46 ` Andreas Schwab
2020-08-11 0:32 ` [PATCH 1/3] stdlib: Use fixed buffer size for realpath (BZ #26241) Matt Turner
2020-08-11 3:00 ` Xiaoming Ni
2020-08-11 14:57 ` Adhemerval Zanella
2020-08-12 1:38 ` Xiaoming Ni
2020-08-12 23:04 ` Adhemerval Zanella
2020-08-13 20:29 ` Adhemerval Zanella [this message]
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=ce6fa716-de33-dbeb-1bcc-084f61fe1b67@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=nixiaoming@huawei.com \
/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).