On Mon, May 12, 2014 at 09:47:19PM +0000, Florian Obser wrote:

> > > Eric?
> > 
> > I think the bug is in hostent_file_match. The following diff has the
> > advantage that this works in /etc/hosts:
> > 
> > 192.0.2.1
> > 192.0.2.1 foo
> > 
> > $ getent hosts 192.0.2.1
> > 192.0.2.1         foo
> > 
> 
> hm, maybe this is better:
> 
> diff --git gethostnamadr_async.c gethostnamadr_async.c
> index 674bcb4..1c77bd9 100644
> --- gethostnamadr_async.c
> +++ gethostnamadr_async.c
> @@ -440,6 +440,8 @@ hostent_file_match(FILE *f, int reqtype, int family, 
> const char *data,
>                                       goto found;
>                       }
>               } else {
> +                     if (n < 2)
> +                             continue;

Yes, but the check must be done for all cases.
The following diff also fixes getnetnamadr.
getaddrinfo is already fine. 

Eric.

Index: gethostnamadr_async.c
===================================================================
RCS file: /cvs/src/lib/libc/asr/gethostnamadr_async.c,v
retrieving revision 1.28
diff -u -p -r1.28 gethostnamadr_async.c
--- gethostnamadr_async.c       26 Mar 2014 18:13:15 -0000      1.28
+++ gethostnamadr_async.c       13 May 2014 06:47:41 -0000
@@ -432,6 +432,10 @@ hostent_file_match(FILE *f, int reqtype,
                        return (NULL);
                }
 
+               /* there must be an address and at least one name */
+               if (n < 2)
+                       continue;
+
                if (reqtype == ASR_GETHOSTBYNAME) {
                        for (i = 1; i < n; i++) {
                                if (strcasecmp(data, tokens[i]))
Index: getnetnamadr_async.c
===================================================================
RCS file: /cvs/src/lib/libc/asr/getnetnamadr_async.c,v
retrieving revision 1.14
diff -u -p -r1.14 getnetnamadr_async.c
--- getnetnamadr_async.c        26 Mar 2014 18:13:15 -0000      1.14
+++ getnetnamadr_async.c        13 May 2014 06:47:41 -0000
@@ -287,6 +287,10 @@ netent_file_match(FILE *f, int reqtype, 
                        return (NULL);
                }
 
+               /* there must be an address and at least one name */
+               if (n < 2)
+                       continue;
+
                if (reqtype == ASR_GETNETBYADDR) {
                        net = inet_network(tokens[1]);
                        if (memcmp(&net, data, sizeof net) == 0)

Reply via email to