|
|
Message-ID: <20261129145941.GC5716@brightrain.aerifal.cx>
Date: Sun, 29 Nov 2026 09:59:41 -0500
From: Rich Felker <dalias@...c.org>
To: 吴尚哲 <wushangzhe26@....pku.edu.cn>
Cc: musl <musl@...ts.openwall.com>
Subject: Re: Bug in wordexp(): getword() leaks a buffer when
getdelim() reaches EOF
On Thu, Nov 26, 2026 at 05:38:54PM +0800, 吴尚哲 wrote:
> Hello,
>
> We found a memory leak in wordexp() in musl 1.2.5. getword() reads one
> NUL-terminated word:
> static char *getword(FILE *f)
> {
> char *s = 0;
> return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s;
> }
> getdelim() can allocate a buffer and still return -1. With *n == 0 and
Thanks. I'd overlooked this thinking it was a duplicate of the bug
fixed in 38e044472edcaf186a5c11f1f0e99d8136149b81. But indeed it's
distinct.
> Checking for EOF before growing the buffer inside getdelim() would also
> work, but that changes a shared loop; the caller-side fix stays inside
> wordexp().
That is not possible. In general getdelim cannot see into the future
to know whether it will hit EOF before encontering a newline, and
can't throw away input, so it needs to allocate output storage before
knowing if it will succeed.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.