[ros-diffs] [cwittich] 36178: fix some kernel32 module winetests (GetProcAddress, GetModuleFileName)

cwittich at svn.reactos.org cwittich at svn.reactos.org
Sat Sep 13 09:37:05 CEST 2008


Author: cwittich
Date: Sat Sep 13 02:37:05 2008
New Revision: 36178

URL: http://svn.reactos.org/svn/reactos?rev=36178&view=rev
Log:
fix some kernel32 module winetests (GetProcAddress, GetModuleFileName)

Modified:
    trunk/reactos/dll/win32/kernel32/misc/ldr.c

Modified: trunk/reactos/dll/win32/kernel32/misc/ldr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ldr.c?rev=36178&r1=36177&r2=36178&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] Sat Sep 13 02:37:05 2008
@@ -230,22 +230,29 @@
 {
 	ANSI_STRING ProcedureName;
 	FARPROC fnExp = NULL;
+	NTSTATUS Status;
 
 	if (HIWORD(lpProcName) != 0)
 	{
 		RtlInitAnsiString (&ProcedureName,
 		                   (LPSTR)lpProcName);
-		LdrGetProcedureAddress ((PVOID)hModule,
+		Status = LdrGetProcedureAddress ((PVOID)hModule,
 		                        &ProcedureName,
 		                        0,
 		                        (PVOID*)&fnExp);
 	}
 	else
 	{
-		LdrGetProcedureAddress ((PVOID)hModule,
+		Status = LdrGetProcedureAddress ((PVOID)hModule,
 		                        NULL,
 		                        (ULONG)lpProcName,
 		                        (PVOID*)&fnExp);
+	}
+
+	if (!NT_SUCCESS(Status))
+	{
+		SetLastError( RtlNtStatusToDosError( Status ) );
+		fnExp = NULL;
 	}
 
 	return fnExp;
@@ -313,27 +320,25 @@
 		Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
 		if (Module->DllBase == (PVOID)hModule)
 		{
-			if (nSize * sizeof(WCHAR) < Module->FullDllName.Length)
-			{
+			Length = min(nSize, Module->FullDllName.Length / sizeof(WCHAR));
+			FileName.Length = 0;
+			FileName.MaximumLength = (USHORT)Length * sizeof(WCHAR);
+			FileName.Buffer = lpFilename;
+
+			/* convert unicode string to ansi (or oem) */
+			if (bIsFileApiAnsi)
+				RtlUnicodeStringToAnsiString (&FileName,
+				                              &Module->FullDllName,
+				                              FALSE);
+			else
+				RtlUnicodeStringToOemString (&FileName,
+				                             &Module->FullDllName,
+				                             FALSE);
+				
+			if (nSize < Length)
 				SetLastErrorByStatus (STATUS_BUFFER_TOO_SMALL);
-			}
 			else
-			{
-				FileName.Length = 0;
-				FileName.MaximumLength = (USHORT)nSize * sizeof(WCHAR);
-				FileName.Buffer = lpFilename;
-
-				/* convert unicode string to ansi (or oem) */
-				if (bIsFileApiAnsi)
-					RtlUnicodeStringToAnsiString (&FileName,
-					                              &Module->FullDllName,
-					                              FALSE);
-				else
-					RtlUnicodeStringToOemString (&FileName,
-					                             &Module->FullDllName,
-					                             FALSE);
-				Length = Module->FullDllName.Length / sizeof(WCHAR);
-			}
+				lpFilename[Length] = '\0';
 
 			RtlLeaveCriticalSection (Peb->LoaderLock);
 			return Length;
@@ -381,22 +386,20 @@
 
 		if (Module->DllBase == (PVOID)hModule)
 		{
-			if (nSize * sizeof(WCHAR) < Module->FullDllName.Length)
-			{
+			Length = min(nSize, Module->FullDllName.Length / sizeof(WCHAR));
+			FileName.Length = 0;
+			FileName.MaximumLength = (USHORT) Length * sizeof(WCHAR);
+			FileName.Buffer = lpFilename;
+
+			RtlCopyUnicodeString (&FileName,
+			                      &Module->FullDllName);
+			if (nSize < Length)
 				SetLastErrorByStatus (STATUS_BUFFER_TOO_SMALL);
-			}
 			else
-			{
-				FileName.Length = 0;
-				FileName.MaximumLength =(USHORT)nSize * sizeof(WCHAR);
-				FileName.Buffer = lpFilename;
-
-				RtlCopyUnicodeString (&FileName,
-				                      &Module->FullDllName);
-				Length = Module->FullDllName.Length / sizeof(WCHAR);
-			}
+				lpFilename[Length] = L'\0';
 
 			RtlLeaveCriticalSection (Peb->LoaderLock);
+
 			return Length;
 		}
 



More information about the Ros-diffs mailing list