Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Jul 2005 00:42:13 -0400 (EDT)
From:      "Mikhail T." <mi@aldan.algebra.com>
To:        FreeBSD-gnats-submit@freebsd.org
Cc:        standards@freebsd.org
Subject:   inet_pton(AF_INET6, ....) seems too permissive
Message-ID:  <200507260442.j6Q4gDHh028351@blue.virtual-estates.net>

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

>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@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:



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