From owner-freebsd-audit Sat Feb 23 9:10:45 2002 Delivered-To: freebsd-audit@freebsd.org Received: from heechee.tobez.org (254.adsl0.ryv.worldonline.dk [213.237.10.254]) by hub.freebsd.org (Postfix) with ESMTP id F17CF37B402 for ; Sat, 23 Feb 2002 09:10:40 -0800 (PST) Received: by heechee.tobez.org (Postfix, from userid 1001) id EB474A93C; Sat, 23 Feb 2002 18:10:30 +0100 (CET) Date: Sat, 23 Feb 2002 18:10:30 +0100 From: Anton Berezin To: audit@FreeBSD.org Subject: [CFR] a small fix of gethostbyname2() Message-ID: <20020223171030.GA29155@heechee.tobez.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.24i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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