about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2022-08-24 20:48:47 -0400
committerRich Felker <dalias@aerifal.cx>2022-08-24 20:48:47 -0400
commitd8fddb964108e57e670d20c36e6da84796617d78 (patch)
tree0e997b8da1bd6ab250d9b1cf760cbba44b111f51 /src
parentd4f987e4ac44e4e5ca2bcf68365b4c2b77bdf2d0 (diff)
downloadmusl-d8fddb964108e57e670d20c36e6da84796617d78.tar.gz
musl-d8fddb964108e57e670d20c36e6da84796617d78.tar.xz
musl-d8fddb964108e57e670d20c36e6da84796617d78.zip
fix fallback when ipv6 is disabled but resolv.conf has v6 nameserves
apparently this code path was never tested, as it's not usual to have
v6 nameservers listed on a system without v6 networking support. but
it was always intended to work.

when reverting to binding a v4 address, also revert the family in the
sockaddr structure and the socklen for it. otherwise bind will just
fail due to mismatched family/sockaddr size.

fix dns resolver fallback when v6 nameservers are listed by
Diffstat (limited to 'src')
-rw-r--r--src/network/res_msend.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index 3e018009..105bf598 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -68,14 +68,15 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
 	}
 
 	/* Get local address and open/bind a socket */
-	sa.sin.sin_family = family;
 	fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
 
 	/* Handle case where system lacks IPv6 support */
 	if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
 		fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
 		family = AF_INET;
+		sl = sizeof sa.sin;
 	}
+	sa.sin.sin_family = family;
 	if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
 		if (fd >= 0) close(fd);
 		pthread_setcancelstate(cs, 0);