From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4444 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: musl & strndupa? Date: Wed, 1 Jan 2014 14:54:11 -0500 Message-ID: <20140101195411.GP24286@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1388606057 14381 80.91.229.3 (1 Jan 2014 19:54:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Jan 2014 19:54:17 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4448-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 01 20:54:25 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1VyRs1-0005QS-GA for gllmg-musl@plane.gmane.org; Wed, 01 Jan 2014 20:54:25 +0100 Original-Received: (qmail 14269 invoked by uid 550); 1 Jan 2014 19:54:24 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 14261 invoked from network); 1 Jan 2014 19:54:24 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4444 Archived-At: 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