From 9f4c47501d7d03102aea0343e8678311e1796bb4 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 31 Mar 2021 22:15:39 +0200 Subject: [PATCH] kernelbase: Make sure that last error is set on LOAD_LIBRARY_AS_DATAFILE failure. Signed-off-by: Alexandre Julliard --- dlls/kernelbase/loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dlls/kernelbase/loader.c b/dlls/kernelbase/loader.c index bdc153b1a47..ac463528e3c 100644 --- a/dlls/kernelbase/loader.c +++ b/dlls/kernelbase/loader.c @@ -95,7 +95,6 @@ static BOOL load_library_as_datafile( LPCWSTR load_path, DWORD flags, LPCWSTR na file = CreateFileW( filenameW, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, 0 ); } - if (file == INVALID_HANDLE_VALUE) ERR("can't load %s\n", debugstr_w(name)); if (file == INVALID_HANDLE_VALUE) return FALSE; mapping = CreateFileMappingW( file, NULL, protect, 0, 0, NULL ); @@ -108,7 +107,11 @@ static BOOL load_library_as_datafile( LPCWSTR load_path, DWORD flags, LPCWSTR na if (!(flags & LOAD_LIBRARY_AS_IMAGE_RESOURCE)) { /* make sure it's a valid PE file */ - if (!RtlImageNtHeader( module )) goto failed; + if (!RtlImageNtHeader( module )) + { + SetLastError( ERROR_BAD_EXE_FORMAT ); + goto failed; + } *mod_ret = (HMODULE)((char *)module + 1); /* set bit 0 for data file module */ if (flags & LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE)