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:   bin/84106: inet_pton(AF_INET6, ....) seems too permissive
Message-ID:  <200507260442.j6Q4gDHh028351@blue.virtual-estates.net>
Resent-Message-ID: <200507260450.j6Q4o5Qf022135@freefall.freebsd.org>

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

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



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