Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Nov 2013 14:11:05 +0400
From:      "Alexander V. Chernikov" <melifaro@FreeBSD.org>
To:        Ian Smith <smithi@nimnet.asn.au>, Ben Morrow <ben@morrow.me.uk>
Cc:        freebsd-stable@freebsd.org, Ian Lepore <ian@freebsd.org>, freebsd-ipfw@freebsd.org, Luigi Rizzo <rizzo@iet.unipi.it>
Subject:   Re: ipfw table add problem
Message-ID:  <5295C539.8070400@FreeBSD.org>
In-Reply-To: <20131127011442.P78756@sola.nimnet.asn.au>
References:  <CAAcX-AGDZbFn5RmhLBBn2PPWRPcsFUnea5MgTc7nuXGD8Ge53A@mail.gmail.com> <52911993.8010108@ipfw.ru> <CAAcX-AEt_i8RUfmMy6WLnER0X=uLk5A1=oj911k-nyMJEghRLw@mail.gmail.com> <529259DE.2040701@FreeBSD.org> <20131125152238.S78756@sola.nimnet.asn.au> <1385391778.1220.4.camel@revolution.hippie.lan> <20131126001806.27951AD3DBF@rock.dv.isc.org> <20131126124757.GA9974@anubis.morrow.me.uk> <20131127011442.P78756@sola.nimnet.asn.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On 27.11.2013 11:56, Ian Smith wrote:
> On Tue, 26 Nov 2013 12:48:01 +0000, Ben Morrow wrote:
>   > To: freebsd-stable@freebsd.org
>
> Restoring cc ipfw@ and others after the inet_pton side?thread in
> stable@.  grepping /usr/src for inet_pton suggests that a behavioural
> change in inet_pton at this stage seems rather unlikely :)
>   
>   > Quoth Michael Butler <imb@protected-networks.net>:
>   > >
>   > > Misinterpreting "10.2.3.01" as "0.0.0.10/32" without so much as a
>   > > warning from either inet_pton() or ipfw is an egregious breach of POLA,
>   >
>   > That's not a bug in inet_pton, though, that's a bug in ipfw. It's
>   > blindly passing the string to atoi or some such when inet_pton fails,
>   > and ignoring the fact it doesn't consume the whole string.
>
> Indeed it is; strtol actually, which quits at the first (here decimal)
> non-digit.  It does return a pointer to it though, and a check for that
> character being '.' seems like a fair indicator of a failed dotted quad?
Fixed in r258677, thanks!

>
> http://svnweb.freebsd.org/base/head/sbin/ipfw/ipfw2.c?revision=250759&view=co
>
> 	if (ishexnumber(*arg) != 0 || *arg == ':') {
> 		/* Remove / if exists */
> 		if ((p = strchr(arg, '/')) != NULL) {
> 			*p = '\0';
> 			mask = atoi(p + 1);
> 		}
>
> 		if (inet_pton(AF_INET, arg, paddr) == 1) {
> 			...
> 		} else if (inet_pton(AF_INET6, arg, paddr) == 1) {
> 			...
> 		} else {
> 			/* Port or any other key */
> 			key = strtol(arg, &p, 10);
> 			/* Skip non-base 10 entries like 'fa1' */
> 			if (p != arg) {
> 				pkey = (uint32_t *)paddr;
> 				*pkey = htonl(key);
> 				type = IPFW_TABLE_CIDR;
> 				addrlen = sizeof(uint32_t);
> 			}
> 		}
> 	}
>
> 	if (type == 0 && strchr(arg, '.') == NULL) {
> 		/* Assume interface name. Copy significant data only */
> 		...
> 	}
>
> 	if (type == 0) {
> 		if (lookup_host(arg, (struct in_addr *)paddr) != 0)
> 			errx(EX_NOHOST, "hostname ``%s'' unknown", arg);
> 		...
> 	}
> 	...
> }
>
> I'm mostly a pascal programmer (oh, the shame! :) so I can easily misuse
> C pointers, but my reading of strtol(3) leads to suggest something like:
>
> 		} else {
> 			/* Port or any other key */
> 			key = strtol(arg, &p, 10);
> 			/* Skip non-base 10 entries like 'fa1' */
> 			if (p != arg) {
> +				/* IPv4 address that failed inet_pton */
> +				if (*p == '.') {
> +					errx(EX_DATAERR, "bad IPv4 address");
> +				}
> 				pkey = (uint32_t *)paddr;
> 				*pkey = htonl(key);
> 				type = IPFW_TABLE_CIDR;
> 				addrlen = sizeof(uint32_t);
> 			}
> 		}
>
> cheers, Ian
> _______________________________________________
> freebsd-ipfw@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
> To unsubscribe, send any mail to "freebsd-ipfw-unsubscribe@freebsd.org"
>




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