[PATCH] Cygwin: PEHeaderFromHModule: allow only images matching build architecture
Jon Turney
jon.turney@dronecode.org.uk
Sat Feb 14 15:01:29 GMT 2026
On 13/02/2026 19:35, Corinna Vinschen wrote:
> From: Corinna Vinschen <corinna@vinschen.de>
>
> This makes sure that we only ever handle images which can be executed
> on the current architecture.
>
> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
> ---
> winsup/cygwin/hookapi.cc | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/winsup/cygwin/hookapi.cc b/winsup/cygwin/hookapi.cc
> index b0126ac04e3e..5b25443c8365 100644
> --- a/winsup/cygwin/hookapi.cc
> +++ b/winsup/cygwin/hookapi.cc
> @@ -43,10 +43,13 @@ PEHeaderFromHModule (HMODULE hModule)
> /* Return valid PIMAGE_NT_HEADERS only for supported architectures. */
> switch (pNTHeader->FileHeader.Machine)
> {
> +#if defined(__x86_64__)
> case IMAGE_FILE_MACHINE_AMD64:
> break;
> +#elif defined (__aarch64__)
> case IMAGE_FILE_MACHINE_ARM64:
> break;
This needs to be followed by
#else
#error "u wot?"
> +#endif
> default:
> return NULL;
From Igor's analysis, ever returning NULL here seems like a bad idea,
as it causes apparently unrelated things to stop working.
Maybe we should just abort there instead?
I've forgotten all the details of exactly what hookapi is doing, so I'm
not sure if that kind of mixing can ever happen (It seems like not -
does the OS even let us load DLLs of a different machine type to that of
the process?)
More information about the Cygwin-patches
mailing list