mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: musl & strndupa?
Date: Wed, 1 Jan 2014 14:54:11 -0500	[thread overview]
Message-ID: <20140101195411.GP24286@brightrain.aerifal.cx> (raw)
In-Reply-To: <CACCP0GrZ=enRGBc_ct3KjyLNJ826G3AjYW5mVv8OVAb-e1u9+A@mail.gmail.com>

On Wed, Jan 01, 2014 at 07:42:47PM +0000, Raphael Cohn wrote:
> Hi,
> 
> I'm trying to compile 'audit' (aka libaudit, auditd, etc - from
> http://people.redhat.com/sgrubb/audit/index.html version 2.3.2). Using musl
> 0.9.14.
> 
> The file 'src/ausearch-lol.c' uses a reference to 'strndupa', which I
> presume is an alloca version of strndup, and presumably a _GNU_SOURCE
> feature. I can't seem to see a definition for it in musl, although strdupa
> exists in string.h (Indeed, http://linux.die.net/man/3/strdup suggests as
> much).
> 
> Is this intentional? If so, what would anyone suggest as a work around? My
> guess would be  #define strndupa(x, t) strncpy(alloca(strlen(x)+1),x,t)
> but I'd like a second opinion...

That's roughly the way to do it, but you need strnlen, not strlen, and
there are various other details like properly parenthesizing macro
arguments. In addition, there's no way to avoid multiple-evaluations
of arguments unless you use the GNU C statement-expressions extension.

It should be noted that almost any use of alloca is either a bug
(potentially exploitable stack overflow) or useless (because the size
is bounded and thus could/should just be replaced by a fixed-size
array). This is the main reason I've been hesitant to go to the
trouble of providing this and dealing with the multiple-evaluation or
#ifdef __GNUC__ issue -- really, any software using alloca (and by
extension, strdupa or strndupa) should be fixed.

Rich


  reply	other threads:[~2014-01-01 19:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-01 19:42 Raphael Cohn
2014-01-01 19:54 ` Rich Felker [this message]
2014-01-01 20:07   ` Raphael Cohn
2014-01-01 20:18     ` 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=20140101195411.GP24286@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --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).