From nobody@FreeBSD.org  Wed May  6 23:25:47 2009
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 E490D106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  6 May 2009 23:25:47 +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 D30558FC23
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  6 May 2009 23:25:47 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n46NPljY079025
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 6 May 2009 23:25:47 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n46NPlSc079024;
	Wed, 6 May 2009 23:25:47 GMT
	(envelope-from nobody)
Message-Id: <200905062325.n46NPlSc079024@www.freebsd.org>
Date: Wed, 6 May 2009 23:25:47 GMT
From: Yuri <yuri@tsoft.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: strtol: overflow error when it shouldn't be
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         134320
>Category:       kern
>Synopsis:       [libc] strtol(3): overflow error when it shouldn't be
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    vwe
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 06 23:30:04 UTC 2009
>Closed-Date:    Tue Jun 16 22:12:37 UTC 2009
>Last-Modified:  Tue Jun 16 22:12:37 UTC 2009
>Originator:     Yuri
>Release:        7.2-PRERELEASE
>Organization:
n/a
>Environment:
>Description:
I look at the testcase:
---------------------------------
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

main() {
  const char *nptr = "d223d221";
  long l = ::strtol(nptr, NULL, 16);
  printf("l=%x errno=%i err=%s\n", l, errno, strerror(errno));
}
------------------------

It prints: l=7fffffff errno=34 err=Result too large

Why result is too large? 0xd223d221 is a valid representation of a signed 32-bit integer between LONG_MIN=-2,147,483,648(0x80000000) and LONG_MAX=+2,147,483,647(0x7fffffff).

So strtol could convert the value but didn't.

>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Bruce Evans <brde@optusnet.com.au>
To: Yuri <yuri@tsoft.com>
Cc: freebsd-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Subject: Re: misc/134320: strtol: overflow error when it shouldn't be
Date: Thu, 7 May 2009 11:46:02 +1000 (EST)

 On Wed, 6 May 2009, Yuri wrote:
 
 > main() {
 >  const char *nptr = "d223d221";
 >  long l = ::strtol(nptr, NULL, 16);
 >  printf("l=%x errno=%i err=%s\n", l, errno, strerror(errno));
 > }
 > ------------------------
 >
 > It prints: l=7fffffff errno=34 err=Result too large
 >
 > Why result is too large? 0xd223d221 is a valid representation of a signed 32-bit integer between LONG_MIN=-2,147,483,648(0x80000000) and LONG_MAX=+2,147,483,647(0x7fffffff).
 
 Hex values are non-negative, so they can never give a valid representation
 of a negative integer.  Here 0xd223d221 is an integer exceeding LONG_MAX.
 
 Bruce
State-Changed-From-To: open->closed 
State-Changed-By: vwe 
State-Changed-When: Tue Jun 16 22:11:07 UTC 2009 
State-Changed-Why:  
0xd223d221 > 0x7fffffff 
I agree with Bruce - not an issue. 


Responsible-Changed-From-To: freebsd-bugs->vwe 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Tue Jun 16 22:11:07 UTC 2009 
Responsible-Changed-Why:  
track 

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