ntdll: Skip unused import descriptors when loading libraries. (v2)
Sebastian Lackner
sebastian at fds-team.de
Wed Feb 10 10:38:28 CST 2016
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---
Changes in v2:
* Move checks inside import_dll, as suggested by Alexandre.
The name "pwm" was chosen since thats also what is used in lots of other functions.
I have verified that it still works as expected with a simple test app.
dlls/ntdll/loader.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index bf1d365..a0049fe 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -564,7 +564,7 @@ static FARPROC find_named_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *
* Import the dll specified by the given import descriptor.
* The loader_section must be locked while calling this function.
*/
-static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *descr, LPCWSTR load_path )
+static BOOL import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *descr, LPCWSTR load_path, WINE_MODREF **pwm )
{
NTSTATUS status;
WINE_MODREF *wmImp;
@@ -586,6 +586,13 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
else
import_list = thunk_list;
+ if (!import_list->u1.Ordinal)
+ {
+ WARN( "Skipping unused import %s\n", name );
+ *pwm = NULL;
+ return TRUE;
+ }
+
while (len && name[len-1] == ' ') len--; /* remove trailing spaces */
if (len * sizeof(WCHAR) < sizeof(buffer))
@@ -597,7 +604,7 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
else /* need to allocate a larger buffer */
{
WCHAR *ptr = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
- if (!ptr) return NULL;
+ if (!ptr) return FALSE;
ascii_to_unicode( ptr, name, len );
ptr[len] = 0;
status = load_dll( load_path, ptr, 0, &wmImp );
@@ -612,7 +619,7 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
else
ERR("Loading library %s (which is needed by %s) failed (error %x).\n",
name, debugstr_w(current_modref->ldr.FullDllName.Buffer), status);
- return NULL;
+ return FALSE;
}
/* unprotect the import address table since it can be located in
@@ -693,7 +700,8 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
done:
/* restore old protection of the import address table */
NtProtectVirtualMemory( NtCurrentProcess(), &protect_base, &protect_size, protect_old, &protect_old );
- return wmImp;
+ *pwm = wmImp;
+ return TRUE;
}
@@ -901,8 +909,11 @@ static NTSTATUS fixup_imports( WINE_MODREF *wm, LPCWSTR load_path )
status = STATUS_SUCCESS;
for (i = 0; i < nb_imports; i++)
{
- if (!(wm->deps[i] = import_dll( wm->ldr.BaseAddress, &imports[i], load_path )))
+ if (!import_dll( wm->ldr.BaseAddress, &imports[i], load_path, &wm->deps[i] ))
+ {
+ wm->deps[i] = NULL;
status = STATUS_DLL_NOT_FOUND;
+ }
}
current_modref = prev;
if (wm->ldr.ActivationContext) RtlDeactivateActivationContext( 0, cookie );
--
2.7.0
More information about the wine-patches
mailing list