From 69089152d136cbac78ababc007d9a4bcf64e0830 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 9 Feb 2006 12:15:57 +0100 Subject: [PATCH] ntdll: Better handling of errors when loading a builtin dll from an existing file. --- dlls/ntdll/loader.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index d4e946a14f7..00817ffb134 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -1427,7 +1427,6 @@ static NTSTATUS load_builtin_dll( LPCWSTR load_path, LPCWSTR path, HANDLE file, DWORD flags, WINE_MODREF** pwm ) { char error[256], dllname[MAX_PATH]; - int file_exists; const WCHAR *name, *p; DWORD len, i; void *handle = NULL; @@ -1456,20 +1455,28 @@ static NTSTATUS load_builtin_dll( LPCWSTR load_path, LPCWSTR path, HANDLE file, if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL )) return STATUS_DLL_NOT_FOUND; - if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, FALSE )) + if (wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, FALSE )) { - file_exists = 1; - prev_info = builtin_load_info; - info.filename = nt_name.Buffer + 4; /* skip \??\ */ - builtin_load_info = &info; - handle = wine_dlopen( unix_name.Buffer, RTLD_NOW, error, sizeof(error) ); - builtin_load_info = prev_info; - RtlFreeHeap( GetProcessHeap(), 0, unix_name.Buffer ); + RtlFreeUnicodeString( &nt_name ); + return STATUS_DLL_NOT_FOUND; } + prev_info = builtin_load_info; + info.filename = nt_name.Buffer + 4; /* skip \??\ */ + builtin_load_info = &info; + handle = wine_dlopen( unix_name.Buffer, RTLD_NOW, error, sizeof(error) ); + builtin_load_info = prev_info; RtlFreeUnicodeString( &nt_name ); + RtlFreeHeap( GetProcessHeap(), 0, unix_name.Buffer ); + if (!handle) + { + WARN( "failed to load .so lib for builtin %s: %s\n", debugstr_w(path), error ); + return STATUS_INVALID_IMAGE_FORMAT; + } } else { + int file_exists; + /* we don't want to depend on the current codepage here */ len = strlenW( name ) + 1; if (len >= sizeof(dllname)) return STATUS_NAME_TOO_LONG; @@ -1484,20 +1491,20 @@ static NTSTATUS load_builtin_dll( LPCWSTR load_path, LPCWSTR path, HANDLE file, builtin_load_info = &info; handle = wine_dll_load( dllname, error, sizeof(error), &file_exists ); builtin_load_info = prev_info; - } - - if (!handle) - { - if (!file_exists) + if (!handle) { - /* The file does not exist -> WARN() */ - WARN("cannot open .so lib for builtin %s: %s\n", debugstr_w(name), error); - return STATUS_DLL_NOT_FOUND; + if (!file_exists) + { + /* The file does not exist -> WARN() */ + WARN("cannot open .so lib for builtin %s: %s\n", debugstr_w(name), error); + return STATUS_DLL_NOT_FOUND; + } + /* ERR() for all other errors (missing functions, ...) */ + ERR("failed to load .so lib for builtin %s: %s\n", debugstr_w(name), error ); + return STATUS_PROCEDURE_NOT_FOUND; } - /* ERR() for all other errors (missing functions, ...) */ - ERR("failed to load .so lib for builtin %s: %s\n", debugstr_w(name), error ); - return STATUS_PROCEDURE_NOT_FOUND; } + if (info.status != STATUS_SUCCESS) return info.status; if (!info.wm) -- 2.11.4.GIT