fix invalid free of partial addrinfo list with multiple services
authorRich Felker <dalias@aerifal.cx>
Wed, 20 Feb 2019 22:51:22 +0000 (17:51 -0500)
committerRich Felker <dalias@aerifal.cx>
Wed, 20 Feb 2019 22:51:22 +0000 (17:51 -0500)
the backindex stored by getaddrinfo to allow freeaddrinfo to perform
partial-free wrongly used the address result index, rather than the
output slot index, and thus was only valid when they were equal
(nservs==1).

patch based on report with proposed fix by Markus Wichmann.

src/network/getaddrinfo.c

index 5ae8cbfb9823b70b712536ae4b1196bea51fabd1..209970adf8e62f2bb2d0c493a9ae912d9c7d5e17 100644 (file)
@@ -104,7 +104,7 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
        }
 
        for (k=i=0; i<naddrs; i++) for (j=0; j<nservs; j++, k++) {
-               out[k].slot = i;
+               out[k].slot = k;
                out[k].ai = (struct addrinfo){
                        .ai_family = addrs[i].family,
                        .ai_socktype = ports[j].socktype,