From: Viktor Szakats Date: Tue, 1 Nov 2022 22:40:36 +0000 (+0000) Subject: lib: sync guard for Curl_getaddrinfo_ex() definition and use X-Git-Tag: curl-7_87_0~210 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=edae6c66c7444a59224a56c360d8fa5e4a7b86db;p=thirdparty%2Fcurl.git lib: sync guard for Curl_getaddrinfo_ex() definition and use `Curl_getaddrinfo_ex()` gets _defined_ with `HAVE_GETADDRINFO` set. But, `hostip4.c` _used_ it with `HAVE_GETADDRINFO_THREADSAFE` set alone. It meant a build with the latter, but without the former flag could result in calling this function but not defining it, and failing to link. Patch this by adding an extra check for `HAVE_GETATTRINFO` around the call. Before this patch, build systems prevented this condition. Now they don't need to. While here, simplify the related CMake logic on Windows by setting `HAVE_GETADDRINFO_THREADSAFE` to the detection result of `HAVE_GETADDRINFO`. This expresses the following intent clearer than the previous patch and keeps the logic in a single block of code: When we have `getaddrinfo()` on Windows, it's always threadsafe. Follow-up to 67d88626d44ec04b9e11dca4cfbf62cd29fe9781 Reviewed-by: Jay Satiro Closes #9734 --- diff --git a/CMake/Platforms/WindowsCache.cmake b/CMake/Platforms/WindowsCache.cmake index 3bcfcd1eec..3cb4ffec3d 100644 --- a/CMake/Platforms/WindowsCache.cmake +++ b/CMake/Platforms/WindowsCache.cmake @@ -70,7 +70,6 @@ if(NOT UNIX) set(HAVE_UTIME 1) set(HAVE_RAND_EGD 0) set(HAVE_GMTIME_R 0) - set(HAVE_GETADDRINFO_THREADSAFE 1) set(HAVE_GETHOSTBYNAME_R 0) set(HAVE_SIGNAL 1) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6719c872a5..13aff5f4b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1077,8 +1077,8 @@ check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64) check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R) check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT) check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO) -if(NOT HAVE_GETADDRINFO) - set(HAVE_GETADDRINFO_THREADSAFE OFF) +if(WIN32) + set(HAVE_GETADDRINFO_THREADSAFE ${HAVE_GETADDRINFO}) endif() check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO) check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE) diff --git a/lib/hostip4.c b/lib/hostip4.c index b0280cd092..109bd1e5ea 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -121,14 +121,15 @@ struct Curl_addrinfo *Curl_getaddrinfo(struct Curl_easy *data, struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port) { -#if !defined(HAVE_GETADDRINFO_THREADSAFE) && defined(HAVE_GETHOSTBYNAME_R_3) +#if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)) && \ + defined(HAVE_GETHOSTBYNAME_R_3) int res; #endif struct Curl_addrinfo *ai = NULL; struct hostent *h = NULL; struct hostent *buf = NULL; -#if defined(HAVE_GETADDRINFO_THREADSAFE) +#if defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE) struct addrinfo hints; char sbuf[12]; char *sbufptr = NULL; @@ -276,14 +277,16 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, h = NULL; /* set return code to NULL */ free(buf); } -#else /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */ +#else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || + HAVE_GETHOSTBYNAME_R */ /* * Here is code for platforms that don't have a thread safe * getaddrinfo() nor gethostbyname_r() function or for which * gethostbyname() is the preferred one. */ h = gethostbyname((void *)hostname); -#endif /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */ +#endif /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || + HAVE_GETHOSTBYNAME_R */ if(h) { ai = Curl_he2ai(h, port);