NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/48926: gethostbyname(3) doesn't appear to work under NetBSD-5.2 and NetBSD-6.1.x when hostnames appear only in /etc/hosts



The following reply was made to PR lib/48926; it has been noted by GNATS.

From: Brian Buhrow <buhrow%nfbcal.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: buhrow%nfbcal.org@localhost
Subject: Re: lib/48926: gethostbyname(3) doesn't appear to work under 
NetBSD-5.2 and NetBSD-6.1.x when hostnames appear only in /etc/hosts
Date: Mon, 23 Jun 2014 01:14:04 -0700

        Hello.  Further investigation revealed this bug appears to
 only affecte NetBSD-5.2 and anything on the netbsd-5 branch. A better
 descripption of the bug is that only the first valid entry in the
 /etc/hosts file will ever be seen by the system because the new file
 parsing routines assume that fgetln() returns a nul terminated string, as
 fgets() used to, and that it is safe to put NULL characters in the middle
 of the returned string to help separate the fields of valid lines.  The
 side effect is that with the latest changes in this file, once the first
 entry is parsed, subsequent lines of the file are efectively erased because
 the beginning of each line is "Nulled out" from the parsing of the previous
 line.
        Below is a patch to the NetBSd-5 version of the gethnamaddr.c file
 which fixes this problem and restores the NetBSd-5.1 and earlier behavior.
 It's possible this patch will need to be applied in some form to the
 NetBSD-6 branch, but I've not yet tested that.  This patch is known to work
 on NetBSD-5 systems without a problem.
        I'll request a pullup shortly.
 
 -thanks
 -Brian
 
 
 Index: gethnamaddr.c
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/net/gethnamaddr.c,v
 retrieving revision 1.73.18.3
 diff -u -r1.73.18.3 gethnamaddr.c
 --- gethnamaddr.c      23 Dec 2013 23:12:44 -0000      1.73.18.3
 +++ gethnamaddr.c      23 Jun 2014 07:27:02 -0000
 @@ -1,4 +1,4 @@
 -/*    $NetBSD$        */
 +/*    $NetBSD: gethnamaddr.c,v 1.73.18.3 2013/12/23 23:12:44 riz Exp $        
*/
  
  /*
   * ++Copyright++ 1985, 1988, 1993
 @@ -57,7 +57,7 @@
  static char sccsid[] = "@(#)gethostnamadr.c   8.1 (Berkeley) 6/4/93";
  static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp 
";
  #else
 -__RCSID("$NetBSD$");
 +__RCSID("$NetBSD: gethnamaddr.c,v 1.73.18.3 2013/12/23 23:12:44 riz Exp $");
  #endif
  #endif /* LIBC_SCCS and not lint */
  
 @@ -722,7 +722,7 @@
  gethostent_r(FILE *hf, struct hostent *hent, char *buf, size_t buflen, int 
*he)
  {
        char *p, *name;
 -      char *cp, **q;
 +      char *cp, **q, sav;
        int af, len;
        size_t llen, anum, i;
        char *aliases[MAXALIASES];
 @@ -742,12 +742,17 @@
                goto again;
        if (*p == '#')
                goto again;
 +      sav = p[llen];
        p[llen] = '\0';
 -      if (!(cp = strpbrk(p, "#\n")))
 +      if (!(cp = strpbrk(p, "#\n"))) {
 +              p[llen] = sav;
                goto again;
 +      }
        *cp = '\0';
 -      if (!(cp = strpbrk(p, " \t")))
 +      if (!(cp = strpbrk(p, " \t"))) {
 +              p[llen] = sav;
                goto again;
 +      }
        *cp++ = '\0';
        if (inet_pton(AF_INET6, p, &host_addr) > 0) {
                af = AF_INET6;
 @@ -766,13 +771,18 @@
                }
                __res_put_state(res);
        } else {
 +              p[llen] = sav;
                goto again;
        }
        /* if this is not something we're looking for, skip it. */
 -      if (hent->h_addrtype != 0 && hent->h_addrtype != af)
 +      if (hent->h_addrtype != 0 && hent->h_addrtype != af) {
 +              p[llen] = sav;
                goto again;
 -      if (hent->h_length != 0 && hent->h_length != len)
 +      }
 +      if (hent->h_length != 0 && hent->h_length != len) {
 +              p[llen] = sav;
                goto again;
 +      }
  
        while (*cp == ' ' || *cp == '\t')
                cp++;
 @@ -805,10 +815,12 @@
        hent->h_aliases[anum] = NULL;
  
        *he = NETDB_SUCCESS;
 +      p[llen] = sav;
        return hent;
  nospc:
        errno = ENOSPC;
        *he = NETDB_INTERNAL;
 +      p[llen] = sav;
        return NULL;
  }
  
 


Home | Main Index | Thread Index | Old Index