[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#247962: libc: inet_aton gets singletons wrong



Package: libc6
Version: 2.2.5-11.2
Severity: normal



#include <stdio.h>
#include <stdlib.h>

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

main (int argc, char *argv[])
{
 struct in_addr in;
 int res;

 res = inet_aton(argv[1], &in);

 printf ("res %d mask %ld\n", err, in.s_addr);

}

% gcc test.c
% ./a.out 255.255.255.255
res 1 mask -1
% ./a.out 255.255.255.0
res 1 mask 16777215
% ./a.out 255.255.255
res 1 mask -16711681
% ./a.out 255.255
res 1 mask -16776961
% ./a.out 255.0.0.0
res 1 mask 255
% ./a.out 8                          <---------- ***
res 1 mask 134217728                 <---------- ***
% ./a.out 0.0.0.8
res 1 mask 134217728
% ./a.out 8.0.0.0
res 1 mask 8


inet_aton should return INVALID (0) for an address like "8" because
the manual page says:

    inet_aton() converts the Internet host address cp from the
    standard numbers-and-dots notation into  binary  data ...


and in this case (and some other above) the host address is NOT in
"standard numbers-and-dots notation". So the input is out of range,
and the manpage says

    inet_aton returns nonzero if the address is valid, zero if not.

and it fails to return INVALID (0) in these cases. This is problematic
because it treats "8" like "0.0.0.8" (and 255.255 like 0.0.255.255).

I don't know what standards apply, but I am attempting to look for a
netmask of either /255.0.0.0 or /8 . I did not expect inet_aton to
return SUCCESS for a "numbers-and-dots" entry that does not have any
dots.

Can you review the internal parser here?



-- System Information
Debian Release: 3.0
Kernel Version: Linux lm011.lab.it.uc3m.es 2.4.25-cpufreq-xfs-prempt-mpls #4 SMP Fri Mar 5 17:59:24 CET 2004 i686 unknown




Reply to: