Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20221022002649.GO29905@brightrain.aerifal.cx>
Date: Fri, 21 Oct 2022 20:26:49 -0400
From: Rich Felker <dalias@...c.org>
To: James Y Knight <jyknight@...gle.com>
Cc: musl@...ts.openwall.com, Ismael Luceno <ismael@...ev.co.uk>
Subject: Re: [RFC PATCH] implement strndupa

On Fri, Oct 21, 2022 at 06:09:42PM -0400, James Y Knight wrote:
> >
> >  #define        strdupa(x)      strcpy(alloca(strlen(x)+1),x)
> > +#define        strndupa(x, n)  strlcpy(alloca(strnlen((x), (n)), (x), (n))
> 
> 
> This causes the parameters to be evaluated multiple times -- and that is
> also a problem with the existing strdupa. Unfortunately it's impossible to
> implement these macros without multiple-evaluation, unless you use the GCC
> statement-expression language extension (as glibc does).
> 
> IMO, musl should either use that extension, despite the general policy of
> avoiding such non-standard language extensions, or simply not implement
> these functions at all. Implementing them, but having them incorrectly
> multiply-evaluate the parameters seems like the worst of the options...

These interfaces are basically *always a vuln* where used, and my
leaning would be that we should remove strdupa and not add strndupa so
as to get things using them fixed. The fact that they're macros and
not ABI makes this doable.

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.