about summary refs log tree commit diff
path: root/src/network/lookup.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-10-04 20:27:17 -0400
committerRich Felker <dalias@aerifal.cx>2018-10-04 20:27:17 -0400
commitd1395c43c019aec6b855cf3c656bf47c8a719e7f (patch)
treec7c070b4887d17832631c2868ea6f9a757194dab /src/network/lookup.h
parent7bf773a8f9b97875ba67b646c1681ac5ca22016f (diff)
downloadmusl-d1395c43c019aec6b855cf3c656bf47c8a719e7f.tar.gz
musl-d1395c43c019aec6b855cf3c656bf47c8a719e7f.tar.xz
musl-d1395c43c019aec6b855cf3c656bf47c8a719e7f.zip
allow freeaddrinfo of arbitrary sublists of addrinfo list
the specification for freeaddrinfo allows it to be used to free
"arbitrary sublists" of the list returned by getaddrinfo. it's not
clearly stated how such sublists come into existence, but the
interpretation seems to be that the application can edit the ai_next
pointers to cut off a portion of the list and then free it.

actual freeing of individual list slots is contrary to the design of
our getaddrinfo implementation, which has no failure paths after
making a single allocation, so that light callers can avoid linking
realloc/free. freeing individual slots is also incompatible with
sharing the string for ai_canonname, which the current implementation
does despite no requirement that it be present except on the first
result. so, rather than actually freeing individual slots, provide a
way to find the start of the allocated array, and reference-count it,
freeing the memory all at once after the last slot has been freed.

since the language in the spec is "arbitrary sublists", no provision
for handling other constructs like multiple lists glued together,
circular links, etc. is made. presumably passing such a construct to
freeaddrinfo produces undefined behavior.
Diffstat (limited to 'src/network/lookup.h')
-rw-r--r--src/network/lookup.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/network/lookup.h b/src/network/lookup.h
index f1952af5..ef662725 100644
--- a/src/network/lookup.h
+++ b/src/network/lookup.h
@@ -4,6 +4,18 @@
 #include <stdint.h>
 #include <stddef.h>
 #include <features.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+struct aibuf {
+	struct addrinfo ai;
+	union sa {
+		struct sockaddr_in sin;
+		struct sockaddr_in6 sin6;
+	} sa;
+	volatile int lock[1];
+	short slot, ref;
+};
 
 struct address {
 	int family;