From ed7cefdd3a0a5b002b5a91d0078b32036355b73e Mon Sep 17 00:00:00 2001 From: tachyglossues <81535731+tachyglossues@users.noreply.github.com> Date: Sun, 26 May 2024 11:11:29 +0200 Subject: [PATCH] fix: prevent potential crash in handleBezier due to invalid input before, when the conf file contained anything other than a float in the 4 bezier curve generation points for annimations, it crashed Hyprland, which now returns an error message. --- src/config/ConfigManager.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f65b5abb..2a3938cd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1821,26 +1821,20 @@ std::optional CConfigManager::handleBezier(const std::string& comma const auto ARGS = CVarList(args); std::string bezierName = ARGS[0]; + if (ARGS[1] == "" || ARGS[2] == "" || ARGS[3] == "" || ARGS[4] == "") + return "too few arguments"; + if (ARGS[5]!= "") + return "too many arguments"; - 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]); - - if (ARGS[5] != "") - return "too many arguments"; - + float p1x = 0, p1y = 0, p2x = 0, p2y = 0; + try { + p1x = std::stof(ARGS[1]); + p1y = std::stof(ARGS[2]); + p2x = std::stof(ARGS[3]); + p2y = std::stof(ARGS[4]); + } catch (const std::invalid_argument&) { + return "invalid argument"; + } g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y)); return {};