Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Jul 2004 06:14:02 GMT
From:      Takayuki Sakuma <takayuki@finet.fujitsu.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/69788: The processing result of strtoul() cannot judge whether it is an error.
Message-ID:  <200407300614.i6U6E2Ps087850@www.freebsd.org>
Resent-Message-ID: <200407300620.i6U6KCAM091280@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         69788
>Category:       misc
>Synopsis:       The processing result of strtoul() cannot judge whether it is an error.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 30 06:20:12 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Takayuki Sakuma
>Release:        4.10-RELEASE
>Organization:
>Environment:
FreeBSD moon.finet.fujitsu.co.jp 4.10-RELEASE FreeBSD 4.10-RELEASE #0: Tue Jul  6 12:59:40 JST 2004     root@moon.finet.fujitsu.co.jp:/usr/src/sys/compile/withDVD  i386
>Description:
The processing result of strtoul() cannot judge whether it is an error when errno has already set to ERANGE before calling this function.
>How-To-Repeat:
void
main(void)
{
        unsigned long ul;
        char *p;

        ul = strtoul("4294967296", &p, 10);
        printf("ul=%lu,*p=%x,errno=%d(%s)\n", ul, *p, errno, strerror(errno));

        ul = strtoul("4294967295", &p, 10);
        printf("ul=%lu,*p=%x,errno=%d(%s)\n", ul, *p, errno, strerror(errno));

        errno=0;
        ul = strtoul("4294967295", &p, 10);
        printf("ul=%lu,*p=%x,errno=%d(%s)\n", ul, *p, errno, strerror(errno));
}

result:
ul=4294967295,*p=0,errno=34(Result too large)
ul=4294967295,*p=0,errno=34(Result too large)
ul=4294967295,*p=0,errno=22(Unknown error: 0)

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200407300614.i6U6E2Ps087850>