From 8b14c24c7ccf94f899395ea8220631060e86266d Mon Sep 17 00:00:00 2001 From: jief666 Date: Sun, 17 Oct 2021 13:20:36 +0200 Subject: [PATCH] Fix access to undefined SlotCount. --- rEFIt_UEFI/Settings/ConfigPlist/SMBIOSPlist.h | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/rEFIt_UEFI/Settings/ConfigPlist/SMBIOSPlist.h b/rEFIt_UEFI/Settings/ConfigPlist/SMBIOSPlist.h index e6c0ddb18..278cbce29 100755 --- a/rEFIt_UEFI/Settings/ConfigPlist/SMBIOSPlist.h +++ b/rEFIt_UEFI/Settings/ConfigPlist/SMBIOSPlist.h @@ -207,17 +207,26 @@ public: virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override { if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false; XBool b = true; - for ( size_t i = 0 ; i < Modules.size() ; ) { - if ( Modules[i].SlotIndex.value() >= SlotCount.value() ) { - xmlLiteParser->addWarning(generateErrors, S8Printf("Ignore memory module with slot >= SlotCount at '%s:%d'", xmlPath.c_str(), keyPos.getLine())); - Modules.RemoveAtIndex(i); - }else{ - i++; - } + if ( Modules.size() == 0 ) { + // whatever if SlotCount is defined or not, and whatever value, it's ok. + return b; } - if ( SlotCount.value() < Modules.dgetCalculatedSlotCount() ) { - log_technical_bug("SlotCount.value() < Modules.dgetCalculatedSlotCount()"); + if ( !SlotCount.isDefined() ) { + xmlLiteParser->addWarning(generateErrors, S8Printf("SlotCount is not defined in SMBIOS, but you defined memory modules. SlotCount adjusted to %d, which maybe wrong.", Modules.dgetCalculatedSlotCount())); // do not set b to false because value is auto-corrected, so it's now ok. SlotCount.setUInt8Value(Modules.dgetCalculatedSlotCount()); + }else{ + for ( size_t i = 0 ; i < Modules.size() ; ) { + if ( Modules[i].SlotIndex.value() >= SlotCount.value() ) { + xmlLiteParser->addWarning(generateErrors, S8Printf("Ignored memory module with slot >= SlotCount at '%s:%d'", xmlPath.c_str(), keyPos.getLine())); // do not set b to false because value is auto-corrected, so it's now ok. + Modules.RemoveAtIndex(i); + }else{ + i++; + } + } + if ( SlotCount.value() < Modules.dgetCalculatedSlotCount() ) { + log_technical_bug("SlotCount.value() < Modules.dgetCalculatedSlotCount()"); + SlotCount.setUInt8Value(Modules.dgetCalculatedSlotCount()); + } } return b; }