From: Rich Felker <dalias@libc.org>
To: Alexey Izbyshev <izbyshev@ispras.ru>, musl@lists.openwall.com
Subject: Re: [musl] [PATCH v2] MT fork
Date: Wed, 11 Nov 2020 09:56:03 -0500 [thread overview]
Message-ID: <20201111145603.GK534@brightrain.aerifal.cx> (raw)
In-Reply-To: <20201111112500.GI1370092@port70.net>
On Wed, Nov 11, 2020 at 12:25:00PM +0100, Szabolcs Nagy wrote:
> * Alexey Izbyshev <izbyshev@ispras.ru> [2020-11-11 09:35:22 +0300]:
> > On 2020-11-11 03:52, Rich Felker wrote:
> > > Here's a proposed first patch in series, getting rid of getdelim/stdio
> > > usage in ldso. I think that suffices to set the stage for adding
> > > __libc_malloc, __libc_free, __libc_calloc, __libc_realloc and having
> > > ldso use them.
> > >
>
> if we don't have to replicate a lot of code in ldso then this sounds good.
Indeed the ldso part of the patch it just:
+#define malloc __libc_malloc
+#define calloc __libc_calloc
+#define realloc __libc_realloc
+#define free __libc_free
That's the minimal needed to make it work. Assuming we adopt and keep
this I might also remove a bunch of ugly code in dynlink.c that
special-cases whether it's running with replaced malloc or not.
> > > +static ssize_t read_loop(int fd, void *p, size_t n)
> > > +{
> > > + unsigned char *b = p;
> > > + for (size_t l, i=0; i<n; i+=l) {
> > > + l = read(fd, b+i, n-i);
> > > + if (l<0) {
> > > + if (errno==EINTR) continue;
> > This increments `i` by a negative `l`.
Thanks Alexey for catching that!
> it's worse: l cannot be negative so the error check is ineffective.
>
> maybe it should be ssize_t? or check == -1
Yes, there are multiple problems and this was the original motivation
for using stdio -- not having to write this ugly error-prone code. But
it only has to be written and reviewed once so it shouldn't be too bad
to get it right. ssize_t should be fine. I mainly did ridiculous stuff
trying to be clever with scope of the vars.
> > > + if (fd>=0) {
> > > + size_t n = 0;
> > > + if (!fstat(fd, &st)) n = st.st_size;
> > > + sys_path = malloc(n+1);
> > > + sys_path[n] = 0;
> > `sys_path` can be NULL here.
Thanks, I meant to put that in if ((sys_path = malloc(n+1))) or
something. Will fix.
Rich
next prev parent reply other threads:[~2020-11-11 14:56 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 0:50 [musl] Status report and " Rich Felker
2020-10-26 0:59 ` Rich Felker
2020-10-26 3:29 ` Rich Felker
2020-10-26 18:44 ` Érico Nogueira
2020-10-26 19:52 ` Rich Felker
2020-10-26 20:11 ` Érico Nogueira
2020-10-27 21:17 ` Rich Felker
2020-10-28 18:56 ` [musl] [PATCH v2] " Rich Felker
2020-10-28 23:06 ` Milan P. Stanić
2020-10-29 16:13 ` Szabolcs Nagy
2020-10-29 16:20 ` Rich Felker
2020-10-29 20:55 ` Milan P. Stanić
2020-10-29 22:21 ` Szabolcs Nagy
2020-10-29 23:00 ` Milan P. Stanić
2020-10-29 23:27 ` Rich Felker
2020-10-30 0:13 ` Rich Felker
2020-10-30 7:47 ` Milan P. Stanić
2020-10-30 18:52 ` Milan P. Stanić
2020-10-30 18:57 ` Rich Felker
2020-10-30 21:31 ` Ariadne Conill
2020-10-31 3:31 ` Rich Felker
2020-11-06 3:36 ` Rich Felker
2020-11-08 16:12 ` Szabolcs Nagy
2020-11-09 17:07 ` Rich Felker
2020-11-09 18:01 ` Érico Nogueira
2020-11-09 18:44 ` Rich Felker
2020-11-09 18:54 ` Érico Nogueira
2020-11-09 21:59 ` Szabolcs Nagy
2020-11-09 22:23 ` Rich Felker
2020-11-11 0:52 ` Rich Felker
2020-11-11 6:35 ` Alexey Izbyshev
2020-11-11 11:25 ` Szabolcs Nagy
2020-11-11 14:56 ` Rich Felker [this message]
2020-11-11 16:35 ` Rich Felker
2020-10-31 7:22 ` Timo Teras
2020-10-31 13:29 ` Szabolcs Nagy
2020-10-31 13:35 ` Timo Teras
2020-10-31 14:41 ` Ariadne Conill
2020-10-31 14:49 ` Rich Felker
2020-10-31 14:48 ` Rich Felker
2020-10-31 14:47 ` Rich Felker
2020-10-29 23:32 ` Szabolcs Nagy
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=20201111145603.GK534@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=izbyshev@ispras.ru \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).