This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: ["Alexander V. Lukyanov" <lav@long.yar.ru>] libc/1096: gethostbyname fails to handle addresses like 10.1234


>>>>> Geoff Keating writes:

>> Mail-Copies-To: never
>> Cc: "Alexander V. Lukyanov" <lav@long.yar.ru>
>> From: Andreas Jaeger <aj@arthur.rhein-neckar.de>
>> Date: 25 Apr 1999 22:49:56 +0200
>> 
>> Now the questions are:
>> - should gethostbyname accept "10.1234" ?
>> - should inet_pton accept "10.1234" ?
>> 
>> Depending on the answer to these two question, we might have to fix
>> digits_dots.c or inet_pton.c.

Geoff> Certainly, gethostbyname should accept all numeric IPv4 addresses.
Geoff> But inet_pton is specifically only dotted quad, so it's OK as-is.

Geoff> So I think digits_dots.c should be changed.

Here's a patch to fix digits_dots.  Could anybody review the patch
please?  

I checked that it does work for IPv4 but I'm not convinced that I
didn't break it for IPv6. What should happen with af==AF_INET6 and an
all numeric address.  Would this be a valid IPv6 address?  In that
case my patch is wrong.:-(  

The if should be rewritten to something like:
		  switch (af)
		    {
		    case AF_INET:
		      ok = (inet_aton (name, (struct in_addr *)host_addr) == 0);
		      break;
		    case AF_INET6:
		      ok = (inet_pton (af, name, host_addr) <= 0);
		      break;
		    }
		  if (!ok)

after declaring ok as int.

Andreas

1999-04-28  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* nss/digits_dots.c (if): Use inet_aton to parse IPv4 numbers.
	This allows e.g. gethostbyname to accept "10.1234".
	Reported by Alexander V. Lukyanov <lav@long.yar.ru> [PR libc/1096].

	* nss/test-netdb.c (test_hosts): Add test for gethostbyname and
	non quad IPv4 numbers.


--- nss/digits_dots.c.~1~	Sat Jan 17 11:00:43 1998
+++ nss/digits_dots.c	Wed Apr 28 22:28:23 1999
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by H.J. Lu <hjl@gnu.ai.mit.edu>, 1997.
 
@@ -104,7 +104,7 @@
 	   we'd actually done a lookup.  What if someone types
 	   255.255.255.255?  The test below will succeed
 	   spuriously... ???  */
-		  if (inet_pton (af, name, host_addr) <= 0)
+		  if (inet_aton (name, (struct in_addr *)host_addr) == 0)
 		    {
 		      __set_h_errno (HOST_NOT_FOUND);
 #ifndef HAVE_LOOKUP_BUFFER
@@ -119,7 +119,7 @@
 		  (*h_addr_ptrs)[0] = (char *)host_addr;
 		  (*h_addr_ptrs)[1] = (char *)0;
 		  resbuf.h_addr_list = *h_addr_ptrs;
-		  if (_res.options & RES_USE_INET6 && af == AF_INET)
+		  if (_res.options & RES_USE_INET6 || af == AF_INET6)
 		    {
 		      /* We need to change the IP v4 address into the
 			 IP v6 address.  */

--- nss/test-netdb.c.~1~	Sat Feb 14 07:30:36 1998
+++ nss/test-netdb.c	Wed Apr 28 22:32:12 1999
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
 
@@ -167,6 +167,9 @@
   hptr1 = gethostbyname ("127.0.0.1");
   output_hostent ("gethostbyname (\"127.0.0.1\")", hptr1);
 
+  hptr1 = gethostbyname ("10.1234");
+  output_hostent ("gethostbyname (\"10.1234\")", hptr1);
+
   hptr1 = gethostbyname2 ("localhost", AF_INET);
   output_hostent ("gethostbyname2 (\"localhost\", AF_INET)", hptr1);
 
-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]