From c8a50907b02f69ac1af44559eb34fe3bd2916eaf Mon Sep 17 00:00:00 2001 From: vit9696 Date: Tue, 14 Apr 2020 07:55:15 +0300 Subject: [PATCH] OcXmlLib: Fix parsing negative integers Resolves issues with parsing MinVersion/MinDate in APFS section --- Library/OcXmlLib/OcXmlLib.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Library/OcXmlLib/OcXmlLib.c b/Library/OcXmlLib/OcXmlLib.c index 7b41558c..074f1261 100755 --- a/Library/OcXmlLib/OcXmlLib.c +++ b/Library/OcXmlLib/OcXmlLib.c @@ -1530,16 +1530,37 @@ PlistIntegerValue ( BOOLEAN Hex ) { - UINT64 Temp; + UINT64 Temp; + CONST CHAR8 *TempStr; + BOOLEAN Negate; if (PlistNodeCast (Node, PLIST_NODE_TYPE_INTEGER) == NULL) { return FALSE; } + TempStr = XmlNodeContent (Node); + + while (*TempStr == ' ' || *TempStr == '\t') { + ++TempStr; + } + + Negate = *TempStr == '-'; + + if (Negate) { + ++TempStr; + } + if (Hex) { - Temp = AsciiStrHexToUint64 (XmlNodeContent (Node)); + Temp = AsciiStrHexToUint64 (TempStr); } else { - Temp = AsciiStrDecimalToUint64 (XmlNodeContent (Node)); + Temp = AsciiStrDecimalToUint64 (TempStr); + } + + // + // May produce unexpected results when the value is too large, but just do not care. + // + if (Negate) { + Temp = 0ULL - Temp; } switch (Size) {