mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] fix strdupa evaulating expression twice
Date: Sun, 28 Aug 2016 11:08:16 -0400	[thread overview]
Message-ID: <20160828150816.GF15995@brightrain.aerifal.cx> (raw)
In-Reply-To: <CADtAWjDn6K+rt=WcgeB1qqA06_DUo2QXY2-x-QLztw1ixkHOtw@mail.gmail.com>

On Sun, Aug 28, 2016 at 10:59:26AM +0000, Noam Meltzer wrote:
> 

> From bf23b7b8fd39eaca6a05173eaf543e1bce3319ab Mon Sep 17 00:00:00 2001
> From: Noam Meltzer <tsnoam@gmail.com>
> Date: Sun, 28 Aug 2016 13:53:24 +0300
> Subject: [PATCH] fix strdupa evaulating expression twice
> 
> calling strdupa with va_arg as its expression caused unexpected
> behaviour. now the expression is evaulated only once.
> ---
>  include/string.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/include/string.h b/include/string.h
> index ff9badb..976faaf 100644
> --- a/include/string.h
> +++ b/include/string.h
> @@ -85,7 +85,10 @@ size_t strlcpy (char *, const char *, size_t);
>  #endif
>  
>  #ifdef _GNU_SOURCE
> -#define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> +#define	strdupa(x) (__extension__ ({ \
> +		const char *__xval = x; \
> +		strcpy(alloca(strlen(__xval)+1),__xval); \
> +	}))
>  int strverscmp (const char *, const char *);
>  int strcasecmp_l (const char *, const char *, locale_t);
>  int strncasecmp_l (const char *, const char *, size_t, locale_t);

The intent of the form as written is to be actual C (modulo use of
alloca) rather than "GNU C". Aside from that, strdupa is essentially
always-unsafe and should probably be removed or at least made into a
warning...

Rich


  reply	other threads:[~2016-08-28 15:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-28 10:59 Noam Meltzer
2016-08-28 15:08 ` Rich Felker [this message]
2016-08-28 16:53   ` Noam Meltzer
2016-08-28 17:04     ` Bobby Bingham
2016-08-29  5:40       ` Noam Meltzer
2016-08-30 21:03         ` Rich Felker

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=20160828150816.GF15995@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).