]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: sync guard for Curl_getaddrinfo_ex() definition and use
authorViktor Szakats <commit@vsz.me>
Tue, 1 Nov 2022 22:40:36 +0000 (22:40 +0000)
committerViktor Szakats <commit@vsz.me>
Tue, 1 Nov 2022 22:40:36 +0000 (22:40 +0000)
`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

CMake/Platforms/WindowsCache.cmake
CMakeLists.txt
lib/hostip4.c

index 3bcfcd1eec9d49ff5a33e3f39eff9e5d4e80f86b..3cb4ffec3d9b4fbe56c9e0eb3d0914869f2678c4 100644 (file)
@@ -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)
 
index 6719c872a5aa1116f850698f8125592bc0f2ed4c..13aff5f4b62351b7abea96c2fc3ee71d67ca6ff6 100644 (file)
@@ -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)
index b0280cd0926d829c5058caf071197e8bdae4314a..109bd1e5ea7306174fa1b456fb9a4753cc5c85d6 100644 (file)
@@ -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);