From 622804013f9fb039266788c43d677724af596d8c Mon Sep 17 00:00:00 2001 From: louist103 Date: Mon, 31 Oct 2022 14:15:36 -0400 Subject: Check for non hex in offset. --- ZAPD/ZFile.cpp | 7 ++++++- ZAPDUtils/Utils/StringHelper.h | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index 6f22c88..60382f6 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -213,7 +213,12 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) // Check for repeated attributes. if (offsetXml != nullptr) { - rawDataIndex = strtol(StringHelper::Split(offsetXml, "0x")[1].c_str(), NULL, 16); + std::string offsetStr = StringHelper::Split(offsetXml, "0x")[1]; + if (!StringHelper::HasOnlyHexDigits(offsetStr)) + { + HANDLE_ERROR(WarningType::InvalidXML, StringHelper::Sprintf("Invalid offset %s entered", offsetStr.c_str()), ""); + } + rawDataIndex = strtol(offsetStr.c_str(), NULL, 16); if (offsetSet.find(offsetXml) != offsetSet.end()) { diff --git a/ZAPDUtils/Utils/StringHelper.h b/ZAPDUtils/Utils/StringHelper.h index 2289927..693813c 100644 --- a/ZAPDUtils/Utils/StringHelper.h +++ b/ZAPDUtils/Utils/StringHelper.h @@ -105,6 +105,11 @@ public: { return std::all_of(str.begin(), str.end(), ::isdigit); } + + static bool HasOnlyHexDigits(const std::string& str) + { + return std::all_of(str.begin(), str.end(), ::isxdigit); + } static std::string ToUpper(const std::string& str) { -- cgit v1.2.3