inet_pton(AF_INET6, ....) seems too permissive
Mikhail T.
mi at aldan.algebra.com
Tue Jul 26 04:42:17 GMT 2005
>Submitter-Id: current-users
>Originator: Mikhail T.
>Organization: Virtual Estates, Inc.
>Confidential: no
>Synopsis: inet_pton(AF_INET6, ....) seems too permissive
>Severity: non-critical
>Priority: medium
>Category: bin
>Class: sw-bug
>Release: FreeBSD 5.4-STABLE amd64
>Environment:
System: FreeBSD blue.virtual-estates.net 5.4-STABLE FreeBSD 5.4-STABLE #7: Thu Jul 21 00:06:41 EDT 2005 root at blue.virtual-estates.net:/var/obj/var/src/sys/SILVER amd64
>Description:
NSPR's addtest pointed me at this problem -- our inet_pton
gladly accepts invalid IPv6 addresses like:
1:2:3:4:5:6:7::8
or
1:2:3:4:5:6::7:8
>How-To-Repeat:
Compile the program below and run as:
./inet_pton6_test 1:2:3:4:5:6:7::8 1:2:3:4:5:6::7:8
inet_pton should reject (return 0) both of these addresses.
/*------------------ Cut here ----------------------------------------*/
#include <err.h>
#include <stdio.h>
#include <sysexits.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int
main(int argc, char *argv[])
{
int exit_code = 0;
if (argc-- == 1)
errx(EX_USAGE, "need at least one argument");
do {
struct in_addr dummy;
const char *host = *++argv;
int result;
result = inet_pton(AF_INET6, host, &dummy);
switch(result) {
case 1:
printf("%s seems Ok\n", host);
break;
case 0:
printf("%s seems invalid\n", host);
exit_code = 1;
break;
case -1:
perror(host);
break;
default:
warn("unexpected result %d to `%s'", result, host);
exit_code = 2;
break;
}
} while (--argc);
return exit_code;
}
/*------------------ Cut here ----------------------------------------*/
>Fix:
More information about the freebsd-standards
mailing list