]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
windows: include `wincrypt.h` before `iphlpapi.h` for mingw-w64 <6
authorViktor Szakats <commit@vsz.me>
Thu, 24 Jul 2025 12:44:03 +0000 (14:44 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 24 Jul 2025 21:49:37 +0000 (23:49 +0200)
Required for mingw-w64 5.x (and older) builds targeting a Windows 7+.

mingw-w64 6+ fixed `mprapi.h` (included indirectly via `iphlpapi.h`)
to include `wincrypt.h` for the missing types.

MSVC is not affected because SDK 7.1a (the oldest MS SDK curl supports),
`mprapi.h` does include `wincrypt.h`.

Make sure to include `wincrypt.h` before including `iphlpapi.h` as
a workaround. `wincrypt.h` is used unconditionally even though it's
not available in UWP. This is safe in this context, because we use
`iphlpapi.h` for `if_nametoindex`, which is not supported and used
in UWP builds.

This fixes auto-detection that missed detecting `if_nametoindex` in
the affected combination, and this build error in non-unity builds:
```
In file included from D:/my-cache/mingw32/i686-w64-mingw32/include/iprtrmib.h:9:0,
                 from D:/my-cache/mingw32/i686-w64-mingw32/include/iphlpapi.h:17,
                 from D:/a/curl/curl/lib/url.c:63:
D:/my-cache/mingw32/i686-w64-mingw32/include/mprapi.h:865:3: error: unknown type name 'CERT_NAME_BLOB'
   CERT_NAME_BLOB *certificateNames;
   ^~~~~~~~~~~~~~
D:/my-cache/mingw32/i686-w64-mingw32/include/mprapi.h:887:3: error: unknown type name 'CRYPT_HASH_BLOB'
   CRYPT_HASH_BLOB certBlob;
   ^~~~~~~~~~~~~~~
```
Ref: https://github.com/curl/curl/actions/runs/16497057672/job/46645264552?pr=18012#step:10:140

This combination is not normally tested in CI. It was caught in
the `dl-mingw, CM 6.4.0-i686 schannel !unity Win7` job while working
on another PR.

Follow-up to 0d71b18153c8edb996738f8a362373fc72d0013b #17413
Ref: #18009
Closes #18012

CMakeLists.txt
configure.ac
lib/url.c

index 334b5c38659752f7664fa3e864338ab9c76d1d86..5f51997f2e79afe740781e73d61dfcfd66efa5fd 100644 (file)
@@ -1785,7 +1785,8 @@ check_function_exists("setlocale"       HAVE_SETLOCALE)
 check_function_exists("setrlimit"       HAVE_SETRLIMIT)
 
 if(WIN32)
-  check_symbol_exists("if_nametoindex"  "winsock2.h;iphlpapi.h" HAVE_IF_NAMETOINDEX)  # Windows Vista+ non-UWP
+  # include wincrypt.h as a workaround for mingw-w64 __MINGW64_VERSION_MAJOR <= 5 header bug */
+  check_symbol_exists("if_nametoindex"  "winsock2.h;wincrypt.h;iphlpapi.h" HAVE_IF_NAMETOINDEX)  # Windows Vista+ non-UWP */
 else()
   check_function_exists("if_nametoindex"  HAVE_IF_NAMETOINDEX)  # net/if.h
   check_function_exists("realpath"        HAVE_REALPATH)
index acf253eadceb0f64529e2aaa26d0ad438d7635a7..27c46bbffc8d9e99349a480b24d39542ee22e124 100644 (file)
@@ -4275,6 +4275,7 @@ if test "$curl_cv_native_windows" = 'yes'; then
       #define WIN32_LEAN_AND_MEAN
       #endif
       #include <winsock2.h>
+      #include <wincrypt.h>  /* workaround for mingw-w64 __MINGW64_VERSION_MAJOR <= 5 header bug */
       #include <iphlpapi.h>
     ]],[[
       if_nametoindex("");
index 3d78ceeed53c1173a398ba16a1a0b2f4cc9985f7..df2a332061a385acdf891d9c482384b887088493 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -60,6 +60,9 @@
 #endif
 
 #if defined(HAVE_IF_NAMETOINDEX) && defined(_WIN32)
+#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR <= 5)
+#include <wincrypt.h>  /* workaround for old mingw-w64 missing to include it */
+#endif
 #include <iphlpapi.h>
 #endif