From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout.scc.kit.edu (scc-mailout.scc.kit.edu [129.13.185.201]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p2C1xKii013320 for ; Fri, 11 Mar 2011 20:59:22 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-01.scc.kit.edu with esmtp (Exim 4.72 #1) id 1PyE6t-0005aC-K7; Sat, 12 Mar 2011 02:59:18 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1PyE6t-0001nP-LQ; Sat, 12 Mar 2011 02:59:15 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1PyE6t-0004bX-KR; Sat, 12 Mar 2011 02:59:15 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1PyE6t-00020K-9r; Sat, 12 Mar 2011 02:59:15 +0100 Date: Sat, 12 Mar 2011 02:59:14 +0100 From: Ingo Schwarze To: uqs@spoerlein.net Cc: tech@mdocml.bsd.lv Subject: Re: Logic error in mandoc.c time2a() Message-ID: <20110312015914.GB12289@iris.usta.de> References: <20110311204204.GA85668@acme.spoerlein.net> <20110312002738.GA12289@iris.usta.de> 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: <20110312002738.GA12289@iris.usta.de> User-Agent: Mutt/1.5.21 (2010-09-15) > I need to cook a diff... Index: mandoc.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mandoc.c,v retrieving revision 1.22 diff -u -p -r1.22 mandoc.c --- mandoc.c 7 Mar 2011 01:35:33 -0000 1.22 +++ mandoc.c 12 Mar 2011 01:56:00 -0000 @@ -382,29 +382,29 @@ static char * time2a(time_t t) { struct tm tm; - char buf[DATESIZE]; - char *p; - size_t nsz, rsz; + char *buf, *p; + size_t ssz; int isz; localtime_r(&t, &tm); - p = buf; - rsz = DATESIZE; + p = buf = mandoc_malloc(10 + 4 + 4 + 1); - if (0 == (nsz = strftime(p, rsz, "%B ", &tm))) - return(NULL); - - p += (int)nsz; - rsz -= nsz; - - if (-1 == (isz = snprintf(p, rsz, "%d, ", tm.tm_mday))) - return(NULL); + if (0 == (ssz = strftime(p, 10 + 1, "%B ", &tm))) + goto fail; + p += (int)ssz; + if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm.tm_mday))) + goto fail; p += isz; - rsz -= isz; - return(strftime(p, rsz, "%Y", &tm) ? buf : NULL); + if (0 == strftime(p, 4 + 1, "%Y", &tm)) + goto fail; + return(buf); + +fail: + free(buf); + return(NULL); } @@ -426,7 +426,7 @@ mandoc_normdate(char *in, mandocmsg msg, t = 0; } out = t ? time2a(t) : NULL; - return(mandoc_strdup(out ? out : in)); + return(out ? out : mandoc_strdup(in)); } -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv