[FREELDR] Use strsafe functions in the PE loader.

This commit is contained in:
Hermès Bélusca-Maïto 2022-02-06 21:22:35 +01:00
parent 313e6b6cbb
commit cfbec70e04
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -245,9 +245,9 @@ PeLdrpBindImportName(
((ULONG_PTR)ForwarderName < ((ULONG_PTR)ExportDirectory + ExportSize)))
{
PLDR_DATA_TABLE_ENTRY DataTableEntry;
CHAR ForwardDllName[255];
PIMAGE_EXPORT_DIRECTORY RefExportDirectory;
ULONG RefExportSize;
CHAR ForwardDllName[256];
TRACE("PeLdrpBindImportName(): ForwarderName %s\n", ForwarderName);
@ -255,7 +255,7 @@ PeLdrpBindImportName(
RtlCopyMemory(ForwardDllName, ForwarderName, sizeof(ForwardDllName));
/* Strip out the symbol name */
*strrchr(ForwardDllName,'.') = '\0';
*strrchr(ForwardDllName, '.') = ANSI_NULL;
/* Check if the target image is already loaded */
if (!PeLdrCheckForLoadedDll(ModuleListHead, ForwardDllName, &DataTableEntry))
@ -264,7 +264,7 @@ PeLdrpBindImportName(
if (strchr(ForwardDllName, '.') == NULL)
{
/* Name does not have an extension, append '.dll' */
strcat(ForwardDllName, ".dll");
RtlStringCbCatA(ForwardDllName, sizeof(ForwardDllName), ".dll");
}
/* Now let's try to load it! */
@ -351,8 +351,8 @@ PeLdrpLoadAndScanReferencedDll(
PVOID BasePA = NULL;
/* Prepare the full path to the file to be loaded */
strcpy(FullDllName, DirectoryPath);
strcat(FullDllName, ImportName);
RtlStringCbCopyA(FullDllName, sizeof(FullDllName), DirectoryPath);
RtlStringCbCatA(FullDllName, sizeof(FullDllName), ImportName);
TRACE("Loading referenced DLL: %s\n", FullDllName);