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

Fix matching of Proc::check_args if cmdline contains non-exe path #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/shared/proc.cpy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unistd.h>
#include <unordered_set>
#include <thread>
#include <set>
#define PID 1
#define PGROUP 4

Expand Down Expand Up @@ -54,6 +55,8 @@ namespace proc:
int used = 0
;

std::set<string> known_interpreters {"python", "python3", "bash", "sh"}

string join_path(vector<string> v):
ostringstream s;
for const auto& i : v:
Expand Down Expand Up @@ -110,13 +113,16 @@ namespace proc:
base = basename((char *) base)
base_str := string(base)

auto search_interpreter = known_interpreters.find(base_str)
if search_interpreter != known_interpreters.end():
continue
Comment on lines +116 to +118
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic here is a bit unclear to me. what happens if: "python -n foo.py" is a cmdline and args is { "foo.py" }?

i think this is supposed to only check the rest of cmd_tokens if the first token is the interpreter, right? (but it should check all of the cmdline, not just the second token?)

Copy link
Author

@JanLuca JanLuca Jun 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my main idea was that we just to check the first argument of the cmdline to get the name of the running program. But then I thought about cases like shell or python scripts where the check if bash or python is running is not really meaningful. Therefore the approach was to skip the first token for this kind of interpreter and check until the first token without an leading -. I know this is still buggy in corner cases when the cmdline is something like python -X <some path> <command> but I had no quick idea how to catch these cases in general.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delay, i will revisit this PR this week (and next) and try to fix things (and write some tests:D). for args with '-X' foo, i would just skip over any args that start with '-' until we get to the first one


for auto needle : args:
if base_str == needle || full_str == needle:
found = true
break

if found:
break
break

return found

Expand Down