Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Feb 2002 18:10:30 +0100
From:      Anton Berezin <tobez@FreeBSD.org>
To:        audit@FreeBSD.org
Subject:   [CFR] a small fix of gethostbyname2()
Message-ID:  <20020223171030.GA29155@heechee.tobez.org>

next in thread | raw e-mail | index | archive | help
The bug:

$ HOSTALIASES=~/.hostaliases; export HOSTALIASES
$ cd ~
$ cat >.hostaliases
somehost somehost.fqdn.bla
^D
$ ssh somehost      # <-- works
$ ping somehost     # <-- does no work

The problem:

Programs that use gethostbyname2() and do not initialize resolver
themselves, will lead to the resolver operating uninitialized.  Even if
(I have not looked) the resolver is initialized at some point later,
some parts, like HOSTALIASES support, do not work as they should.

The fix:

Index: gethostnamadr.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/net/gethostnamadr.c,v
retrieving revision 1.19
diff -u -r1.19 gethostnamadr.c
--- gethostnamadr.c	13 Aug 2001 14:06:25 -0000	1.19
+++ gethostnamadr.c	23 Feb 2002 16:56:46 -0000
@@ -84,6 +84,11 @@
 		NS_NIS_CB(_nis_gethostbyname, NULL) /* force -DHESIOD */
 		{ 0 }
 	};       
+
+	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+		h_errno = NETDB_INTERNAL;
+		return (NULL);
+	}
 	
 	rval = nsdispatch((void *)&hp, dtab, NSDB_HOSTS, "gethostbyname",
 			  default_src, name, type);


Similarly, for -stable:

Index: gethostnamadr.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/net/gethostnamadr.c,v
retrieving revision 1.15.2.2
diff -u -r1.15.2.2 gethostnamadr.c
--- gethostnamadr.c	5 Mar 2001 10:40:42 -0000	1.15.2.2
+++ gethostnamadr.c	23 Feb 2002 16:59:11 -0000
@@ -140,6 +140,11 @@
 	struct hostent *hp = 0;
 	int nserv = 0;
 
+	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+		h_errno = NETDB_INTERNAL;
+		return (NULL);
+	}
+
 	if (!service_done)
 		init_services();
 

Would anybody mind if I commit it?

Cheers,
=Anton.
-- 
| Anton Berezin                |      FreeBSD: The power to serve |
| catpipe Systems ApS   _ _ |_ |           http://www.FreeBSD.org |
| tobez@catpipe.net    (_(_||  |                tobez@FreeBSD.org | 
| +45 7021 0050                |         Private: tobez@tobez.org |

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




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