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

inet_pton(AF_INET6, ....) seems too permissive



>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_(_dot_)_virtual-estates_(_dot_)_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:
_______________________________________________
freebsd-standards_(_at_)_freebsd_(_dot_)_org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-standards
To unsubscribe, send any mail to "freebsd-standards-unsubscribe_(_at_)_freebsd_(_dot_)_org"