public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Make inet_pton RFC2133 compliant
@ 2004-08-04 10:13 Jakub Jelinek
  2004-08-05 16:28 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-08-04 10:13 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

http://www.faqs.org/rfcs/rfc2133.html
is a little bit vague, but still:
    Inet_pton() returns 1 if the conversion succeeds, 0 if the input is not
    a valid IPv4 dotted-decimal string
...
    If the af argument is AF_INET, the function accepts a string in the
    standard IPv4 dotted-decimal form:

        ddd.ddd.ddd.ddd

    where ddd is a one to three digit decimal number between 0 and 255.
    Note that many implementations of the existing inet_addr() and
    inet_aton() functions accept nonstandard input:  octal numbers,
    hexadecimal numbers, and fewer than four numbers.  inet_pton() does
    not accept these formats.

Both inet_aton and inet_pton ATM parse octal numbers, but interpret them
a different way, which is certainly a bad thing:
  inet_aton ("035.000.00000.071", &in)
  inet_pton (AF_INET, "035.000.00000.071", &in)
Both calls succeed (return 1), but the first one fills in
29.0.0.57 while the second one 35.0.0.71.

I've googled around what other inet_pton4 implementations do.
Some do what glibc does ATM, some do what the following patch does,
BSD ones forbid if first digit in the octet is '0' and second character
is digit, but not '9' (which is really strange, why is 091 special while
085 not).

The patch below disallows all octal literals with the exception of 0,
i.e. disallows even 00 or 0000000000.
I'm not sure if it should allow that or not (similarly there is no ambiguity
with inet_aton for say 07 or 006).

2004-08-04  Jakub Jelinek  <jakub@redhat.com>

	* resolv/inet_pton.c (inet_pton4): Disallow octal numbers.  Reported
	by A. Guru <a.guru@sympatico.ca>.  [BZ #295]

--- libc/resolv/inet_pton.c.jj	2002-08-03 14:08:47.000000000 +0200
+++ libc/resolv/inet_pton.c	2004-08-04 11:55:12.826244037 +0200
@@ -69,7 +69,8 @@ libc_hidden_def (inet_pton)
 
 /* int
  * inet_pton4(src, dst)
- *	like inet_aton() but without all the hexadecimal and shorthand.
+ *	like inet_aton() but without all the hexadecimal, octal (with the
+ *	exception of 0) and shorthand.
  * return:
  *	1 if `src' is a valid dotted quad, else 0.
  * notice:
@@ -94,6 +95,8 @@ inet_pton4(src, dst)
 		if (ch >= '0' && ch <= '9') {
 			u_int new = *tp * 10 + (ch - '0');
 
+			if (saw_digit && *tp == 0)
+				return (0);
 			if (new > 255)
 				return (0);
 			*tp = new;

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Make inet_pton RFC2133 compliant
  2004-08-04 10:13 [PATCH] Make inet_pton RFC2133 compliant Jakub Jelinek
@ 2004-08-05 16:28 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-08-05 16:28 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

Applied since this is the latest version of bind, where we got the code
from in the first place.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-05 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-04 10:13 [PATCH] Make inet_pton RFC2133 compliant Jakub Jelinek
2004-08-05 16:28 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).