From nobody@FreeBSD.org  Mon Nov  8 09:36:37 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 43D5E1065674
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Nov 2010 09:36:37 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 31DE18FC1D
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Nov 2010 09:36:37 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id oA89aa8U034523
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 8 Nov 2010 09:36:36 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id oA89aaAO034522;
	Mon, 8 Nov 2010 09:36:36 GMT
	(envelope-from nobody)
Message-Id: <201011080936.oA89aaAO034522@www.freebsd.org>
Date: Mon, 8 Nov 2010 09:36:36 GMT
From: Yui NARUSE <naruse@airemix.jp>
To: freebsd-gnats-submit@FreeBSD.org
Subject: wrong bufsize of __hdtoa
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         152042
>Category:       kern
>Synopsis:       [libc] [patch] wrong bufsize of __hdtoa
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 08 09:40:06 UTC 2010
>Closed-Date:    Thu Oct 20 04:03:49 UTC 2011
>Last-Modified:  Thu Oct 20 04:03:49 UTC 2011
>Originator:     Yui NARUSE
>Release:        8.1-RELEASE
>Organization:
>Environment:
FreeBSD windy.airemix.net 8.1-RELEASE FreeBSD 8.1-RELEASE #1: Sat Jul 24 11:27:04 JST 2010     naruse@windy.airemix.net:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
When ndigits is given for __hdtoa, the bufsize for rv_alloc is too small.
It must add 1 for NUL termination.
>How-To-Repeat:

>Fix:
/usr/src/lib/libc/gdtoa % diff -u _hdtoa.c _hdtoa.c.orig
--- _hdtoa.c    2010-11-08 18:31:46.000000000 +0900
+++ _hdtoa.c.orig       2010-11-08 18:31:44.000000000 +0900
@@ -109,7 +109,7 @@
         * enough space for all the digits.
         */
        bufsize = (ndigits > 0) ? ndigits : SIGFIGS;
-       s0 = rv_alloc(bufsize);
+       s0 = rv_alloc(bufsize+1);
 
        /* Round to the desired number of digits. */
        if (SIGFIGS > ndigits && ndigits > 0) {

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Thu Oct 20 04:02:30 UTC 2011 
State-Changed-Why:  
Thanks for the report, but rv_alloc() already includes the space for the NUL 
terminator!  It's not a very clear interface, I know, but that code comes 
from a third party. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=152042 
>Unformatted:
