From pavlin@catarina.usc.edu  Thu Apr 27 01:21:11 2000
Return-Path: <pavlin@catarina.usc.edu>
Received: from catarina.usc.edu (catarina.usc.edu [128.125.51.47])
	by hub.freebsd.org (Postfix) with ESMTP id D501637B7DD
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Apr 2000 01:21:10 -0700 (PDT)
	(envelope-from pavlin@catarina.usc.edu)
Received: from gaudi.usc.edu (gaudi.usc.edu [128.125.51.46])
	by catarina.usc.edu (8.9.3/8.9.3) with ESMTP id BAA03218;
	Thu, 27 Apr 2000 01:20:25 -0700 (PDT)
Received: (from pavlin@localhost)
	by gaudi.usc.edu (8.9.3/8.9.3) id BAA56964;
	Thu, 27 Apr 2000 01:20:24 -0700 (PDT)
Message-Id: <200004270820.BAA56964@gaudi.usc.edu>
Date: Thu, 27 Apr 2000 01:20:24 -0700 (PDT)
From: pavlin@catarina.usc.edu
Reply-To: pavlin@catarina.usc.edu
To: FreeBSD-gnats-submit@freebsd.org
Cc: pavlin@catarina.usc.edu
Subject: inet_aton(204.08.126.0) failure
X-Send-Pr-Version: 3.2

>Number:         18251
>Category:       misc
>Synopsis:       inet_aton() may fail for some addresses (e.g. 204.08.126.0)
>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:   Thu Apr 27 01:30:01 PDT 2000
>Closed-Date:    Sat Apr 29 17:22:24 PDT 2000
>Last-Modified:  Sat Apr 29 17:30:07 PDT 2000
>Originator:     Pavlin Ivanov Radoslavov
>Release:        FreeBSD 4.0-RELEASE i386
>Organization:
University of Southern California, Dept. of CS
>Environment:

	FreeBSD 4.0-RELEASE (but probably also true for FreeBSD-current)

>Description:

	inet_aton() may fail for some IPv4 addresses that may look OK.
	E.g. such address is 204.08.126.0 (note the '0' in front of '8',
	i.e. "08" is OK in base-10, but not valid in base-8
	(a fact that triggers the error because of the particular
	implemetation which uses strtoul()

>How-To-Repeat:

	Compile and execute the following code:


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int
main()
{
    struct in_addr in_addr;
    char *s;

    s = "204.08.126.0";
    if (inet_aton(s, &in_addr) == 1)
	printf("OK\n");
    else
	printf("ERROR\n");
    
    exit (0);
}

>Fix:

	The problem is in the inet_aton() implementation in libc:
	/usr/src/lib/libc/net/inet_addr.c

	Older FreeBSD versions (e.g. FreeBSD-3.2) are OK, so one
	possible solution is to use the implementation from
	those older systems instead of the FreeBSD-4.0 solution.


>Release-Note:
>Audit-Trail:

From: Bill Fenner <fenner@research.att.com>
To: pavlin@catarina.usc.edu
Cc: freebsd-gnats-submit@freebsd.org, pavlin@catarina.usc.edu
Subject: Re: misc/18251: inet_aton(204.08.126.0) failure
Date: Thu, 27 Apr 2000 13:02:49 -0700

 This is documented in the inet_aton() man page:
 
      All numbers supplied as ``parts'' in a `.' notation may be decimal, oc-
      tal, or hexadecimal, as specified in the C language (i.e., a leading 0x
      or 0X implies hexadecimal; otherwise, a leading 0 implies octal; other-
      wise, the number is interpreted as decimal).
 
 Many people think that inet_aton() only takes dotted decimal, but
 it actually also accepts hex and octal and addresses with less than
 4 dots.
 
   Bill
 
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Sat Apr 29 17:22:24 PDT 2000 
State-Changed-Why:  
The 4.0 behavior agrees with the man page and has been the documented 
behavior since at least 4.3-Reno.  The bug was in the previous versions. 
This is consistent with other OS's as well (e.g. Solaris). 
>Unformatted:
