Skip to content

windows: include wincrypt.h before iphlpapi.h for mingw-w64 <6#18012

Closed
vszakats wants to merge 7 commits intocurl:masterfrom
vszakats:w-win7-test
Closed

windows: include wincrypt.h before iphlpapi.h for mingw-w64 <6#18012
vszakats wants to merge 7 commits intocurl:masterfrom
vszakats:w-win7-test

Conversation

@vszakats
Copy link
Member

@vszakats vszakats commented Jul 24, 2025

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 0d71b18 #17413
Ref: #18009


@vszakats vszakats added build Windows Windows-specific labels Jul 24, 2025
@vszakats vszakats marked this pull request as draft July 24, 2025 12:36
@github-actions github-actions bot added the CI Continuous Integration label Jul 24, 2025
@vszakats vszakats changed the title test old mingw-w64 targeting win7 [test] old mingw-w64 targeting win7 Jul 24, 2025
@vszakats vszakats changed the title [test] old mingw-w64 targeting win7 url: fix to include winsock2.h before iphlpapi.h Jul 24, 2025
@vszakats
Copy link
Member Author

vszakats commented Jul 24, 2025

This lead into a journey into the spider-web of weird Windows build combinations with UWP, buggy mingw-w64 headers and wincrypt.h availability.

Might trigger another PR trying to simplify wincrypt.h includes/conditions. Still thinking what would be the best to get out of all the pitfalls. And/or will need to extend if_nametoindex detection with a bunch of complexity to counter this pre-mingw-w64 v5 issue. Unless this issue is also present in MS SDKs, which I haven't checked yet.

edit: as of SDK 7.1a (the earliest SDK version curl supports, via v110_xp toolset meant for XP, see lib/config-win32.h) mprapi.h does include wincrypt.h. So this looks like a mingw-w64 <6 specific header bug.
Ref: https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B

vszakats added 5 commits July 24, 2025 19:40
Seen with a non-unity, mingw-w64 CI job targeting a Vista+ Windows
version while working on a PR. This combination is not normally
tested in CI.

Fixing:
```
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

Follow-up to 0d71b18 curl#17413
Ref: curl#18009
The issue with this is that the if_nametoindex auto-detection code would
also need this hack, and it will make those super complicated.

The auto-detection is not normally run with cmake (but necessary to pass
a checkprefill test). With autotools however, it's required to detect
if_nametoindex.

`wincrypt.h` is not safe to include as-is because UWP does not support it,
but in this case this is safe because `if_nametoindex` is not supported by
UWP, and thus `HAVE_IF_NAMETOINDEX` is always undefined.
@vszakats vszakats changed the title url: fix to include winsock2.h before iphlpapi.h windows: fix to include winsock2.h before iphlpapi.h Jul 24, 2025
@vszakats vszakats marked this pull request as ready for review July 24, 2025 17:51
@vszakats vszakats changed the title windows: fix to include winsock2.h before iphlpapi.h windows: fix to include wincrypt.h before iphlpapi.h (for mingw-w64 <=5) Jul 24, 2025
@vszakats vszakats changed the title windows: fix to include wincrypt.h before iphlpapi.h (for mingw-w64 <=5) windows: fix to include wincrypt.h before iphlpapi.h (for mingw-w64 <6) Jul 24, 2025
@vszakats vszakats changed the title windows: fix to include wincrypt.h before iphlpapi.h (for mingw-w64 <6) windows: include wincrypt.h before iphlpapi.h for mingw-w64 <6 Jul 24, 2025
@vszakats vszakats closed this in 7d8d5cf Jul 24, 2025
@vszakats vszakats deleted the w-win7-test branch July 24, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build CI Continuous Integration Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant