From 4b362ac9d3d3cc95f2c824d93e2e718a9adfd8ef Mon Sep 17 00:00:00 2001 From: B2krobbery <150381094+B2krobbery@users.noreply.github.com> Date: Wed, 29 Apr 2026 20:00:26 +0530 Subject: [PATCH] config: prevent crash on invalid numeric values --- src/config/ConfigManager.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5f590b8..cda747c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -89,7 +89,12 @@ static Hyprlang::CParseResult configHandleLayoutOption(const char* v, void** dat rhs.pop_back(); } - DATA->m_vValues = Hyprutils::Math::Vector2D{std::stof(lhs), std::stof(rhs)}; + try { + DATA->m_vValues = Hyprutils::Math::Vector2D{std::stof(lhs), std::stof(rhs)}; + } catch (const std::exception&) { + result.setError(std::format("invalid layout values: {}", VALUE).c_str()); + return result; + } return result; } @@ -595,34 +600,41 @@ std::optional CConfigManager::handleSource(const std::string& comma } std::optional CConfigManager::handleBezier(const std::string& command, const std::string& args) { - const auto ARGS = CVarList(args); + const auto ARGS = CVarList(args); std::string bezierName = ARGS[0]; if (ARGS[1] == "") return "too few arguments"; - float p1x = std::stof(ARGS[1]); - if (ARGS[2] == "") return "too few arguments"; - float p1y = std::stof(ARGS[2]); - if (ARGS[3] == "") return "too few arguments"; - float p2x = std::stof(ARGS[3]); - if (ARGS[4] == "") return "too few arguments"; - float p2y = std::stof(ARGS[4]); + + float p1x, p1y, p2x, p2y; + + try { + p1x = std::stof(ARGS[1]); + p1y = std::stof(ARGS[2]); + p2x = std::stof(ARGS[3]); + p2y = std::stof(ARGS[4]); + } catch (const std::exception&) { + return "invalid bezier arguments"; + } if (ARGS[5] != "") return "too many arguments"; - g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y)); + g_pAnimationManager->addBezierWithName( + bezierName, + Vector2D(p1x, p1y), + Vector2D(p2x, p2y) + ); return {}; } - std::optional CConfigManager::handleAnimation(const std::string& command, const std::string& args) { const auto ARGS = CVarList(args);