From 1640958e371e76ae31252ad955adb9de22b9a6c3 Mon Sep 17 00:00:00 2001 From: Richard Bainesly Date: Fri, 21 Jun 2024 17:40:37 -0400 Subject: [PATCH] protect stoi --- hyprctl/main.cpp | 7 ++++++- src/debug/HyprCtl.cpp | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 40ed0aa2..8916b7cc 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -353,7 +353,12 @@ int main(int argc, char** argv) { fullArgs += "f"; needRoll = true; if (ARGS.size() >= 3) - rollRate = std::stoi(ARGS[2]); + try { + rollRate = std::stoi(ARGS[2]); + } catch (std::invalid_argument& e) { + log("invalid argument\n"); + return 1; + } } else if (ARGS[i] == "--batch") { fullRequest = "--batch "; } else if (ARGS[i] == "--instance" || ARGS[i] == "-i") { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index f3de4cbd..d0998c54 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1829,7 +1829,11 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) { std::string val; if (iss >> val) { if (iss >> val) { - runWritingDebugLogThread(ACCEPTEDCONNECTION, std::stoi(val)); + try { + runWritingDebugLogThread(ACCEPTEDCONNECTION, std::stoi(val)); + } catch (std::invalid_argument& e) { + Debug::log(ERR, "Error in rollinglog request: {}", e.what()); + } } else { runWritingDebugLogThread(ACCEPTEDCONNECTION); }