From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout-kit-02.scc.kit.edu (scc-mailout-kit-02.scc.kit.edu [129.13.231.82]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id a958d78d; for ; Fri, 20 Mar 2015 10:45:18 -0500 (EST) Received: from asta-nat.asta.uni-karlsruhe.de ([172.22.63.82] helo=hekate.usta.de) by scc-mailout-kit-02.scc.kit.edu with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (envelope-from ) id 1YYz6q-0003Wj-2P; Fri, 20 Mar 2015 16:45:17 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1YYz6p-00078E-Tc; Fri, 20 Mar 2015 16:45:15 +0100 Received: from athene.usta.de ([172.24.96.10]) by donnerwolke.usta.de with esmtp (Exim 4.80) (envelope-from ) id 1YYz6p-0003sC-Oi; Fri, 20 Mar 2015 16:45:15 +0100 Received: from localhost (1031@localhost [local]); by localhost (OpenSMTPD) with ESMTPA id 3eaa8ff7; Fri, 20 Mar 2015 16:45:15 +0100 (CET) Date: Fri, 20 Mar 2015 16:45:15 +0100 From: Ingo Schwarze To: Christian Neukirchen Cc: tech@mdocml.bsd.lv Subject: Re: compat_vasprintf.c: use va_copy Message-ID: <20150320154515.GC27243@athene.usta.de> References: <87vbhv7n26.fsf@gmail.com> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87vbhv7n26.fsf@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Hi Christian, Christian Neukirchen wrote on Fri, Mar 20, 2015 at 03:36:49PM +0100: > When building CVS HEAD on Linux x86_64/glibc, the vasprintf check > fails when -D_GNU_SOURCE is not passed, and mdocml falls back to > compat_vasprintf.c. This version of vasprintf.c segfaults on glibc, > because the same va_list is used twice. Probably affects other > architectures too. > > The solution is to use va_copy to get a second va_list. I have put this in, it can hardly do harm. Besides, i have added _GNU_SOURCE to test-vasprintf.c, you are right that it was missing, see the patch below. Note that the other files using vasprintf() don't need it because config.h already defines it. Thanks, Ingo > --- compat_vasprintf.c > +++ compat_vasprintf.c > @@ -38,9 +38,13 @@ vasprintf(char **ret, const char *format, va_list ap) > { > char buf[2]; > int sz; > + va_list ap2; > > - if ((sz = vsnprintf(buf, sizeof(buf), format, ap)) != -1 && > - (*ret = malloc(sz + 1)) != NULL) { > + va_copy(ap2, ap); > + sz = vsnprintf(buf, sizeof(buf), format, ap2); > + va_end(ap2); > + > + if (sz != -1 && (*ret = malloc(sz + 1)) != NULL) { > if (vsnprintf(*ret, sz + 1, format, ap) == sz) > return(sz); > free(*ret); Log Message: ----------- vasprintf(3) needs _GNU_SOURCE on Linux; pointed out by Christian Neukirchen . Modified Files: -------------- mdocml: test-vasprintf.c Revision Data ------------- Index: test-vasprintf.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/test-vasprintf.c,v retrieving revision 1.1 retrieving revision 1.2 diff -Ltest-vasprintf.c -Ltest-vasprintf.c -u -p -r1.1 -r1.2 --- test-vasprintf.c +++ test-vasprintf.c @@ -15,6 +15,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if defined(__linux__) || defined(__MINT__) +#define _GNU_SOURCE /* vasprintf() */ +#endif + #include #include #include -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv