From d4a4cb2e80d9c8136f03d1880cf9aa5b00fb02b2 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 28 Dec 2024 15:58:51 +0100 Subject: [PATCH] fix: Crash when providing invalid version string to semantic version class Fixes #2036 --- lib/libimhex/source/helpers/semantic_version.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/libimhex/source/helpers/semantic_version.cpp b/lib/libimhex/source/helpers/semantic_version.cpp index 3df1c1ac6..671feb941 100644 --- a/lib/libimhex/source/helpers/semantic_version.cpp +++ b/lib/libimhex/source/helpers/semantic_version.cpp @@ -39,6 +39,8 @@ namespace hex { } u32 SemanticVersion::major() const { + if (!isValid()) return 0; + try { return std::stoul(m_parts[0]); } catch (...) { @@ -47,6 +49,8 @@ namespace hex { } u32 SemanticVersion::minor() const { + if (!isValid()) return 0; + try { return std::stoul(m_parts[1]); } catch (...) { @@ -55,6 +59,8 @@ namespace hex { } u32 SemanticVersion::patch() const { + if (!isValid()) return 0; + try { return std::stoul(m_parts[2]); } catch (...) { @@ -63,6 +69,8 @@ namespace hex { } bool SemanticVersion::nightly() const { + if (!isValid()) return false; + return m_parts.size() == 4 && m_parts[3] == "WIP"; } @@ -96,6 +104,8 @@ namespace hex { } std::string SemanticVersion::get(bool withBuildType) const { + if (!isValid()) return ""; + auto result = wolv::util::combineStrings(m_parts, "."); if (withBuildType && !m_buildType.empty())