mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
fix mishandling of errno in getaddrinfo AI_ADDRCONFIG logic
this code attempts to use the value of errno from failure of socket or connect to infer availability of the requested address family (v4 or v6). however, in the case where connect failed, there is an intervening call to close between connect and the use of errno. close is not required to preserve errno on success, and in fact the __aio_close code, which is called whenever aio is linked and thus always called in dynamic-linked programs, unconditionally clobbers errno. as a result, getaddrinfo fails with EAI_SYSTEM and errno=ENOENT rather than correctly determining that the address family was unavailable. this fix is based on report/patch by Jussi Nieminen, but simplified slightly to avoid breaking the case where socket, not connect, failed.
This commit is contained in:
parent
d16d7b1099
commit
7d568410b4
1 changed files with 2 additions and 0 deletions
|
@ -66,9 +66,11 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
|
|||
pthread_setcancelstate(
|
||||
PTHREAD_CANCEL_DISABLE, &cs);
|
||||
int r = connect(s, ta[i], tl[i]);
|
||||
int saved_errno = errno;
|
||||
pthread_setcancelstate(cs, 0);
|
||||
close(s);
|
||||
if (!r) continue;
|
||||
errno = saved_errno;
|
||||
}
|
||||
switch (errno) {
|
||||
case EADDRNOTAVAIL:
|
||||
|
|
Loading…
Add table
Reference in a new issue