From bd5012edc89f96450d3444abd9b390c9f858719b Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 31 Jul 2024 11:13:04 +0800 Subject: [PATCH] PhysicalMemory: make sure to detect all memory devices --- src/detection/physicalmemory/physicalmemory.c | 6 ++++++ src/detection/physicalmemory/physicalmemory_linux.c | 6 +++--- src/modules/physicalmemory/physicalmemory.c | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/detection/physicalmemory/physicalmemory.c b/src/detection/physicalmemory/physicalmemory.c index 6591c3245..c5df181f3 100644 --- a/src/detection/physicalmemory/physicalmemory.c +++ b/src/detection/physicalmemory/physicalmemory.c @@ -23,6 +23,12 @@ static inline const char* getVendorString(unsigned vendorId) void FFPhysicalMemoryUpdateVendorString(FFPhysicalMemoryResult* device) { + if (ffStrbufEqualS(&device->vendor, "Unknown")) + { + ffStrbufClear(&device->vendor); + return; + } + char vendorIdStr[5]; if (ffStrbufStartsWithS(&device->vendor, "0x")) { diff --git a/src/detection/physicalmemory/physicalmemory_linux.c b/src/detection/physicalmemory/physicalmemory_linux.c index 1eb971e8b..fc83f92a3 100644 --- a/src/detection/physicalmemory/physicalmemory_linux.c +++ b/src/detection/physicalmemory/physicalmemory_linux.c @@ -75,10 +75,10 @@ const char* ffDetectPhysicalMemory(FFlist* result) if (!data) return "Memory device is not found in SMBIOS data"; - for (; data->Header.Type == FF_SMBIOS_TYPE_MEMORY_DEVICE; - data = (const FFSmbiosMemoryDevice*) ffSmbiosNextEntry(&data->Header)) + for (; data->Header.Type < FF_SMBIOS_TYPE_END_OF_TABLE; + data = (const FFSmbiosMemoryDevice*) ffSmbiosNextEntry(&data->Header)) { - if (data->Size == 0) continue; + if (data->Header.Type != FF_SMBIOS_TYPE_MEMORY_DEVICE || data->Size == 0) continue; const char* strings = (const char*) data + data->Header.Length; diff --git a/src/modules/physicalmemory/physicalmemory.c b/src/modules/physicalmemory/physicalmemory.c index 84e62eb90..6949b045d 100644 --- a/src/modules/physicalmemory/physicalmemory.c +++ b/src/modules/physicalmemory/physicalmemory.c @@ -20,6 +20,12 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options) return; } + if (result.length == 0) + { + ffPrintError(FF_PHYSICALMEMORY_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No physical memory detected"); + return; + } + FF_STRBUF_AUTO_DESTROY prettySize = ffStrbufCreate(); uint32_t i = 0;