Browse Source

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.
Rich Felker 6 years ago
parent
commit
224d938c5e
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/network/getaddrinfo.c

+ 1 - 1
src/network/getaddrinfo.c

@@ -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,