-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[linux] please provide parameter that allows to control how cmdline()
splits
#2335
Comments
cmdline()
splits
I'm afraid adding a parameter which works on Linux only is a no-go from an API standpoint. A user interested in getting the raw cmdline for whatever reason should just read /proc/pid/cmdline. Still, he would have the exact same problem we have: how to interpret it? IMO we can only improve the internal heuristic, assuming it can be improved (I don't know). As for your examples: I don't understand the
...so I can clearly see where the separators are. Can you re-paste the examples above by using this instead of |
Well its the nature of such deep system information, that it may be platform dependent. Linux e.g. says in
So it may be the "original" program name & arguments separated (and terminated) by As the manpage says, it may not even be valid to think of it as a "command line" in the sense of a program name followed by arguments (which I think, the current heuristic tries to employ however).
But I don't see why such parameter would only work on Linux? What I've had named In case of Linux, that would IMO be simply Last but not least, there could be some Last but not least, in a way this issue may also be a tiny bit "security" relevant (similar to #2334). But what can still happen is e.g. the following scenario: As my tool, would kill processes, I'm trying to make sure it's really an OpenSSH However, if the results of Thanks, |
As I said above, because even with the original raw bytes you would still have the same problem of not knowing what the separator is, so you would end up guessing anyway. You can go back to the raw cmdline by converting the string into bytes if that's what you want: is_possible_tmux = b"tmux" in bytes(" ".join(psutil.Process(pid).cmdline()), "utf8") The trailing separator is trimmed, but other than that no information is lost. Realistically I don't think any of this matter though.
Agreed. |
Summary
Description
Hey.
While skimming through the code because of #2334 I've stumbled over:
https://github.com/giampaolo/psutil/blob/master/psutil/_pslinux.py#L1783-L1798
and #1179.
I think doing automagically this actually a problem (and depending on how the results are used, may even be a security issue, or e.g. lead to killing of wrong processes).
Simply splitting by spaces, just because some heuristics thinks it would have found out that arguments were split by them, may or may not be correct.
Consider the simple example:
Then one has:
which already fits the condition. Trailing
0x0
, one list element, space contained.So the user will get wrongly a two element list.
Another simple example might be:
I is
unzip
t
x.zip
or is itunzip
t x.zip
or evenunzip t
x.zip
.If programs change their cmdline, anything can happen... and I don't think it's good to further mess that up.
The main problem is however, that the caller of
cmdline()
cannot know whether this happened or not, so he cannot even undo it.My suggest would be:
cmdline()
should be safe, and return the contents split by0x0
only.But there could be an parameter for it, which enables the splitting by space in the (presumed) well known cases.
Such parameter would even allow to apply different styles of splitting.
So one could have:
split=raw
which gives back the unmodifiedbytes
(no splitting at all),split="null"
(which IMO should be default), which splits by0x0
only, and possibly further ones including the single-element with spaces case.Thanks,
Chris.
PS: Is it really possibly that
cmdline
does not end in0x0
(even after a process has modified it)? I wasn't able to get that done... any examples?The text was updated successfully, but these errors were encountered: