Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyprctl: avoid parsing string::npos on invalid cmd #7544

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,12 +970,26 @@ std::string dispatchRequest(eHyprCtlOutputFormat format, std::string in) {
}

std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) {
// get rid of the keyword keyword
in = in.substr(in.find_first_of(' ') + 1);

const auto COMMAND = in.substr(0, in.find_first_of(' '));

const auto VALUE = in.substr(in.find_first_of(' ') + 1);
// Find the first space to strip the keyword keyword
auto const firstSpacePos = in.find_first_of(' ');
if (firstSpacePos == std::string::npos) // Handle the case where there's no space found (invalid input)
return "Invalid input: no space found";

// Strip the keyword
in = in.substr(firstSpacePos + 1);

// Find the next space for the COMMAND and VALUE
auto const secondSpacePos = in.find_first_of(' ');
if (secondSpacePos == std::string::npos) // Handle the case where there's no second space (invalid input)
return "Invalid input: command and value not properly formatted";

// Extract COMMAND and VALUE
const auto COMMAND = in.substr(0, secondSpacePos);
const auto VALUE = in.substr(secondSpacePos + 1);

// If either COMMAND or VALUE is empty, handle accordingly
if (COMMAND.empty() || VALUE.empty())
return "Invalid input: command or value is empty";

std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE);

Expand Down
Loading