From 6d5fcbbf4bac0639d531577786b158c24b60d9c6 Mon Sep 17 00:00:00 2001 From: Dave Voutila Date: Sat, 2 Jan 2021 17:44:13 -0500 Subject: getaddrinfo(3) on musl & BSDs fails with servname = "" (#1396) If one calls getaddrinfo(3) on OpenBSD like so, it returns -8 EAI_NONAME: struct addrinfo hints; struct addrinfo *results; int rv; results = NULL; memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_ADDRCONFIG; hints.ai_flags |= AI_PASSIVE; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; rv = getaddrinfo("localhost", "", &hints, &results); In the above code, that mirrors the current logic in resolv_task(), rv will end up being -8. On non-musl, non-BSD posix systems I tested (only amd64 Debian), it succeeds and returns 0. --- src/platform/posix/posix_resolv_gai.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c index 36a0924e..83974b3d 100644 --- a/src/platform/posix/posix_resolv_gai.c +++ b/src/platform/posix/posix_resolv_gai.c @@ -253,7 +253,7 @@ nni_resolv_ip(const char *host, const char *serv, int af, bool passive, return; } - if (serv == NULL) { + if (serv == NULL || strcmp(serv, "") == 0) { item->serv = NULL; } else if ((item->serv = nni_strdup(serv)) == NULL) { nni_aio_finish_error(aio, NNG_ENOMEM); -- cgit v1.2.3-70-g09d2