From 07f36b52aaa308a57c1a18f03758a0a733c7ae53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Wed, 6 May 2026 17:49:18 +0200 Subject: [PATCH] [FREELDR] peloader.c: Minor nits --- boot/freeldr/freeldr/lib/peloader.c | 37 +++++++++++++---------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/boot/freeldr/freeldr/lib/peloader.c b/boot/freeldr/freeldr/lib/peloader.c index 5015704a521..5f27e4cc4be 100644 --- a/boot/freeldr/freeldr/lib/peloader.c +++ b/boot/freeldr/freeldr/lib/peloader.c @@ -51,12 +51,11 @@ PeLdrpFetchAddressOfSecurityCookie(PVOID BaseAddress, ULONG SizeOfImage) TRUE, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &DirSize); - - /* Check for sanity */ + /* Validate it */ if (!ConfigDir || DirSize < RTL_SIZEOF_THROUGH_FIELD(IMAGE_LOAD_CONFIG_DIRECTORY, SecurityCookie)) { - /* Invalid directory*/ + /* Invalid directory */ return NULL; } @@ -329,11 +328,9 @@ PeLdrpBindImportName( /* Get pointer to the export directory of loaded DLL */ RefExportDirectory = (PIMAGE_EXPORT_DIRECTORY) RtlImageDirectoryEntryToData(VaToPa(DataTableEntry->DllBase), - TRUE, - IMAGE_DIRECTORY_ENTRY_EXPORT, - &RefExportSize); - - /* Fail if it's NULL */ + TRUE, + IMAGE_DIRECTORY_ENTRY_EXPORT, + &RefExportSize); if (RefExportDirectory) { UCHAR Buffer[128]; @@ -476,11 +473,11 @@ PeLdrpScanImportAddressTable( } else { - ExportDirectory = - (PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(VaToPa(DllBase), - TRUE, - IMAGE_DIRECTORY_ENTRY_EXPORT, - &ExportSize); + ExportDirectory = (PIMAGE_EXPORT_DIRECTORY) + RtlImageDirectoryEntryToData(VaToPa(DllBase), + TRUE, + IMAGE_DIRECTORY_ENTRY_EXPORT, + &ExportSize); } TRACE("PeLdrpScanImportAddressTable(): ExportDirectory 0x%p\n", ExportDirectory); @@ -551,13 +548,11 @@ PeLdrInitSecurityCookie(PLDR_DATA_TABLE_ENTRY LdrEntry) /* Fetch address of the cookie */ Cookie = PeLdrpFetchAddressOfSecurityCookie(VaToPa(LdrEntry->DllBase), LdrEntry->SizeOfImage); - if (!Cookie) return NULL; /* Check if it's a default one */ - if ((*Cookie == DEFAULT_SECURITY_COOKIE) || - (*Cookie == 0)) + if ((*Cookie == DEFAULT_SECURITY_COOKIE) || (*Cookie == 0)) { /* Generate new cookie using cookie address and time as seed */ NewCookie = (ULONG_PTR)Cookie ^ (ULONG_PTR)ArcGetRelativeTime(); @@ -638,8 +633,11 @@ PeLdrScanImportDescriptorTable( BOOLEAN Success; /* Get a pointer to the import table of this image */ - ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase), - TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize); + ImportTable = (PIMAGE_IMPORT_DESCRIPTOR) + RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase), + TRUE, + IMAGE_DIRECTORY_ENTRY_IMPORT, + &ImportTableSize); #if DBG { @@ -693,7 +691,6 @@ PeLdrScanImportDescriptorTable( ThunkData, DirectoryPath, &ScanDTE->InLoadOrderLinks); - if (!Success) { ERR("PeLdrpScanImportAddressTable() failed: ImportName = '%s', DirectoryPath = '%s'\n", @@ -909,12 +906,10 @@ PeLdrLoadImageEx( PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage, (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)), MemoryType); - if (PhysicalBase == NULL) { /* Don't fail, allocate again at any other "low" place */ PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType); - if (PhysicalBase == NULL) { ERR("Failed to alloc %lu bytes for image %s\n", NtHeaders->OptionalHeader.SizeOfImage, FilePath);