restrict str_version conversion to 3 groups

Signed-off-by: Slice <sergey.slice@gmail.com>
This commit is contained in:
Slice 2023-05-31 00:17:19 +03:00
parent 501f391525
commit e0bde75175
8 changed files with 27 additions and 10 deletions

View File

@ -6,7 +6,8 @@
*/ */
#include "CloverVersion.h" #include "CloverVersion.h"
#include "../../Version.h" #include "../../../Version.h"
#ifdef FIRMWARE_REVISION #ifdef FIRMWARE_REVISION

View File

@ -27,7 +27,7 @@
// //
// Searches Source for Search pattern of size SearchSize // Searches Source for Search pattern of size SearchSize
// and returns the number of occurences. // and returns the number of occurrences.
// //
UINTN SearchAndCount(const UINT8 *Source, UINT64 SourceSize, const UINT8 *Search, UINTN SearchSize) UINTN SearchAndCount(const UINT8 *Source, UINT64 SourceSize, const UINT8 *Search, UINTN SearchSize)
{ {

View File

@ -1933,7 +1933,7 @@ printf("%s", "");
// } // }
// } // }
const XObjArray<DEV_PROPERTY> compatibleArbProperties = getCompatibleArbProperty(); const XObjArray<DEV_PROPERTY> compatibleArbProperties = getCompatibleArbProperty();
size_t oldArbIdx = 0; // size_t oldArbIdx = 0;
for ( size_t idx = 0 ; idx < compatibleArbProperties.size() ; ++idx ) for ( size_t idx = 0 ; idx < compatibleArbProperties.size() ; ++idx )
{ {
if ( ArbProperties == NULL ) { if ( ArbProperties == NULL ) {
@ -1943,7 +1943,7 @@ printf("%s", "");
if ( !compareDevProperty(S8Printf("ArbProperties[%zu]", idx), *ArbProperties, compatibleArbProperties[idx]) ) { if ( !compareDevProperty(S8Printf("ArbProperties[%zu]", idx), *ArbProperties, compatibleArbProperties[idx]) ) {
return false; return false;
} }
++oldArbIdx; // ++oldArbIdx;
ArbProperties = ArbProperties->Next; ArbProperties = ArbProperties->Next;
} }
if ( ArbProperties != NULL ) { if ( ArbProperties != NULL ) {

View File

@ -5,13 +5,15 @@
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile #include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#define DBG(...) DebugLog(1, __VA_ARGS__)
XString8 NonDetected = "10.10.10"_XS8; //longer string XString8 NonDetected = "10.10.10"_XS8; //longer string
/** /**
Convert a Null-terminated ASCII string representing version number (separate by dots) Convert a Null-terminated ASCII string representing version number (separate by dots)
to a UINT64 value. to a UINT64 value.
If Version is NULL, then result is 0. (Slice - no) If Version is NULL, then result is 0.
@param Version The pointer to a Null-terminated ASCII version string. Like 10.9.4 @param Version The pointer to a Null-terminated ASCII version string. Like 10.9.4
@param MaxDigitByPart Is the maximum number of digits between the dot separators @param MaxDigitByPart Is the maximum number of digits between the dot separators
@ -23,6 +25,13 @@ XString8 NonDetected = "10.10.10"_XS8; //longer string
**/ **/
UINT64 AsciiStrVersionToUint64(const LString8& Version_, UINT8 MaxDigitByPart, UINT8 MaxParts)
{
const XString8 Version = Version_;
// DebugLog(1, "call Version %s\n", Version.c_str());
return AsciiStrVersionToUint64(Version, MaxDigitByPart, MaxParts);
}
UINT64 AsciiStrVersionToUint64(const XString8& Version_, UINT8 MaxDigitByPart, UINT8 MaxParts) UINT64 AsciiStrVersionToUint64(const XString8& Version_, UINT8 MaxDigitByPart, UINT8 MaxParts)
{ {
UINT64 result = 0; UINT64 result = 0;
@ -41,14 +50,16 @@ UINT64 AsciiStrVersionToUint64(const XString8& Version_, UINT8 MaxDigitByPart, U
} }
max_part_value = part_mult - 1; max_part_value = part_mult - 1;
size_t idx = 0; size_t idx = 0;
while (idx < Version.length() && MaxParts > 0) { //Slice - NULL pointer dereferencing while (idx < Version.length() && MaxParts > 0) {
if (Version[idx] >= '0' && Version[idx] <= '9') { if (Version[idx] >= '0' && Version[idx] <= '9') {
part_value = part_value * 10 + (UINT16)(Version[idx] - '0'); part_value = part_value * 10 + (UINT16)(Version[idx] - '0');
// DebugLog(1, "part_value=%d\n", (int)part_value);
if (part_value > max_part_value) if (part_value > max_part_value)
part_value = max_part_value; part_value = max_part_value;
} }
else if (Version[idx] == '.') { else if (Version[idx] == '.') {
result = (result * part_mult) + part_value; result = (result * part_mult) + part_value;
// DebugLog(1, "result=%lld\n", result);
part_value = 0; part_value = 0;
MaxParts--; MaxParts--;
} }

View File

@ -655,7 +655,7 @@ void ConfigManager::FillSmbiosWithDefaultValue(MacModel Model, const SmbiosPlist
//// gSettings.Smbios.EfiVersion.takeValueFrom(ApplePlatformData[Model].efiversion); // gSettings.Smbios.EfiVersion.takeValueFrom(ApplePlatformData[Model].efiversion);
// if ( smbiosDictClass.getEfiVersion().isDefined() ) { // if ( smbiosDictClass.getEfiVersion().isDefined() ) {
// if (AsciiStrVersionToUint64(gSettings.Smbios.EfiVersion, 4, 5) > AsciiStrVersionToUint64(smbiosDictClass.dgetEfiVersion(), 4, 5)) { // if (AsciiStrVersionToUint64(gSettings.Smbios.EfiVersion, 4, 5) > AsciiStrVersionToUint64(smbiosDictClass.dgetEfiVersion(), 4, 5)) {
// DBG("Using latest EfiVersion from clover: %s\n", gSettings.Smbios.EfiVersion.c_str()); // DBG("Using latest EfiVersion from clover: %s\n", gSettings.Smbios.EfiVersion.c_str());

View File

@ -48,6 +48,7 @@ extern const UINT8 default_dcfg_1[];
#include "ConfigPlistAbstract.h" #include "ConfigPlistAbstract.h"
#include "SMBIOSPlist.h" #include "SMBIOSPlist.h"
class ConfigPlistClass : public ConfigPlistAbstractClass class ConfigPlistClass : public ConfigPlistAbstractClass
{ {
using super = ConfigPlistAbstractClass; using super = ConfigPlistAbstractClass;

View File

@ -9,7 +9,6 @@
#include "../../cpp_lib/XmlLiteSimpleTypes.h" #include "../../cpp_lib/XmlLiteSimpleTypes.h"
#include "../../cpp_lib/XmlLiteParser.h" #include "../../cpp_lib/XmlLiteParser.h"
SmbiosPlistClass::SmbiosDictClass::MemoryDictClass::ModuleDictClass SmbiosPlistClass::SmbiosDictClass::MemoryDictClass::ModuleDictClass::NullValue = SmbiosPlistClass::SmbiosDictClass::MemoryDictClass::ModuleDictClass(); SmbiosPlistClass::SmbiosDictClass::MemoryDictClass::ModuleDictClass SmbiosPlistClass::SmbiosDictClass::MemoryDictClass::ModuleDictClass::NullValue = SmbiosPlistClass::SmbiosDictClass::MemoryDictClass::ModuleDictClass();
SmbiosPlistClass::SmbiosDictClass::SlotDeviceDictClass SmbiosPlistClass::SmbiosDictClass::SlotDeviceDictClass::NullValue = SmbiosPlistClass::SmbiosDictClass::SlotDeviceDictClass(); SmbiosPlistClass::SmbiosDictClass::SlotDeviceDictClass SmbiosPlistClass::SmbiosDictClass::SlotDeviceDictClass::NullValue = SmbiosPlistClass::SmbiosDictClass::SlotDeviceDictClass();

View File

@ -533,11 +533,16 @@ public:
} }
} }
if ( EfiVersion.isDefined() ) { if ( EfiVersion.isDefined() ) {
if ( AsciiStrVersionToUint64(ApplePlatformDataArray[dgetModel()].efiversion, 4, 5) > AsciiStrVersionToUint64(EfiVersion.value(), 4, 5)) { // DebugLog(1, "have EfiVersion=%s\n", EfiVersion.value().c_str());
long long int result = AsciiStrVersionToUint64(ApplePlatformDataArray[dgetModel()].efiversion, 4, 3);
long long int result2 = AsciiStrVersionToUint64(EfiVersion.value(), 4, 3);
// DebugLog(1, "make uint64=%lld vs %lld\n", result, result2);
// DebugLog(1, "compare 1715 %c 1968\n", (result > result2)? '>':'<');
if ( result > result2) {
xmlLiteParser->addWarning(generateErrors, S8Printf("EfiVersion '%s' is older than default ('%s') -> ignored. Dict '%s:%d'.", EfiVersion.value().c_str(), ApplePlatformDataArray[dgetModel()].efiversion.c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict xmlLiteParser->addWarning(generateErrors, S8Printf("EfiVersion '%s' is older than default ('%s') -> ignored. Dict '%s:%d'.", EfiVersion.value().c_str(), ApplePlatformDataArray[dgetModel()].efiversion.c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
xmlLiteParser->productNameNeeded = !getProductName().isDefined(); xmlLiteParser->productNameNeeded = !getProductName().isDefined();
EfiVersion.reset(); EfiVersion.reset();
} else if (AsciiStrVersionToUint64(ApplePlatformDataArray[dgetModel()].efiversion, 4, 5) == AsciiStrVersionToUint64(EfiVersion.value(), 4, 5)) { } else if (result == result2) {
xmlLiteParser->addInfo(generateErrors, S8Printf("EfiVersion '%s' is the same as default. Dict '%s:%d'.", EfiVersion.value().c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict xmlLiteParser->addInfo(generateErrors, S8Printf("EfiVersion '%s' is the same as default. Dict '%s:%d'.", EfiVersion.value().c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
xmlLiteParser->productNameNeeded = !getProductName().isDefined(); xmlLiteParser->productNameNeeded = !getProductName().isDefined();
EfiVersion.reset(); EfiVersion.reset();