fix invalid free of partial addrinfo list with multiple services

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.
This commit is contained in:
Rich Felker 2019-02-20 17:51:22 -05:00
parent 9d44b6460a
commit 224d938c5e
1 changed files with 1 additions and 1 deletions

View 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++) { 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){ out[k].ai = (struct addrinfo){
.ai_family = addrs[i].family, .ai_family = addrs[i].family,
.ai_socktype = ports[j].socktype, .ai_socktype = ports[j].socktype,