fix getservby*() with null pointer for protocol argument
authorRich Felker <dalias@aerifal.cx>
Sun, 15 Jul 2012 00:16:23 +0000 (20:16 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 15 Jul 2012 00:16:23 +0000 (20:16 -0400)
not sure this is the best fix but it should work

src/network/getservbyname_r.c
src/network/getservbyport_r.c

index 5c02515..efa5d91 100644 (file)
@@ -12,6 +12,10 @@ int getservbyname_r(const char *name, const char *prots,
        struct addrinfo *ai, hint = { .ai_family = AF_INET };
        int i;
 
+       if (!prots) return -(
+               getservbyname_r(name, "tcp", se, buf, buflen, res)
+               && getservbyname_r(name, "udp", se, buf, buflen, res) );
+
        /* Align buffer */
        i = (uintptr_t)buf & sizeof(char *)-1;
        if (!i) i = sizeof(char *);
index f119abc..821afae 100644 (file)
@@ -15,6 +15,10 @@ int getservbyport_r(int port, const char *prots,
                .sin_port = port,
        };
 
+       if (!prots) return -(
+               getservbyport_r(port, "tcp", se, buf, buflen, res)
+               && getservbyport_r(port, "udp", se, buf, buflen, res) );
+
        /* Align buffer */
        i = (uintptr_t)buf & sizeof(char *)-1;
        if (!i) i = sizeof(char *);