diff options
author | Rich Felker <dalias@aerifal.cx> | 2019-02-20 17:58:21 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2019-02-20 17:58:21 -0500 |
commit | ad795d56ba3fb9d69f524ee676e3b1e2355cceb7 (patch) | |
tree | 4a4e17ac64b24c94c4329f6b042027b166e21d38 /src/network | |
parent | 224d938c5e538ac37f84c6e9a01bd2095aa7081a (diff) | |
download | musl-ad795d56ba3fb9d69f524ee676e3b1e2355cceb7.tar.gz musl-ad795d56ba3fb9d69f524ee676e3b1e2355cceb7.tar.bz2 musl-ad795d56ba3fb9d69f524ee676e3b1e2355cceb7.tar.xz musl-ad795d56ba3fb9d69f524ee676e3b1e2355cceb7.zip |
fix spurious undefined behavior in getaddrinfo
addressing &out[k].sa was arguably undefined, despite &out[k] being
defined the slot one past the end of an array, since the member access
.sa is intervening between the [] operator and the & operator.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/getaddrinfo.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c index 209970ad..efaab306 100644 --- a/src/network/getaddrinfo.c +++ b/src/network/getaddrinfo.c @@ -113,8 +113,8 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), .ai_addr = (void *)&out[k].sa, - .ai_canonname = outcanon, - .ai_next = &out[k+1].ai }; + .ai_canonname = outcanon }; + if (k) out[k-1].ai.ai_next = &out[k].ai; switch (addrs[i].family) { case AF_INET: out[k].sa.sin.sin_family = AF_INET; @@ -130,7 +130,6 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru } } out[0].ref = nais; - out[nais-1].ai.ai_next = 0; *res = &out->ai; return 0; } |