bin/84106: inet_pton(AF_INET6, ....) seems too permissive

Mikhail T. mi at aldan.algebra.com
Tue Jul 26 04:50:06 GMT 2005


>Number:         84106
>Category:       bin
>Synopsis:       inet_pton(AF_INET6, ....) seems too permissive
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 26 04:50:05 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Mikhail T.
>Release:        FreeBSD 5.4-STABLE amd64
>Organization:
Virtual Estates, Inc.
>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:
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list