mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: James Y Knight <jyknight@google.com>
Cc: musl@lists.openwall.com, Ismael Luceno <ismael@iodev.co.uk>
Subject: Re: [musl] [RFC PATCH] implement strndupa
Date: Fri, 21 Oct 2022 20:26:49 -0400	[thread overview]
Message-ID: <20221022002649.GO29905@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAA2zVHpQ3iuq_UydEJ0E3G-pvTvtu6v7KHeo8MSGw5JEb4JS8Q@mail.gmail.com>

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

      reply	other threads:[~2022-10-22  0:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 21:17 Ismael Luceno
2022-10-21 22:09 ` James Y Knight
2022-10-22  0:26   ` Rich Felker [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=20221022002649.GO29905@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=ismael@iodev.co.uk \
    --cc=jyknight@google.com \
    --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).