diff options
author | Max Prokhorov <prokhorov.max@outlook.com> | 2016-06-13 04:13:42 +0300 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-06-16 10:12:59 +0200 |
commit | ab6b3ad1c10768be64343940878617b1ae438c43 (patch) | |
tree | ae252e1f4468806f394fa7767b42ad30b27fa3c2 /src/basic/process-util.c | |
parent | cf527c6873b86266ab75e56f28e2eada23866296 (diff) |
util-lib: drop trailing non-printable characters from cmdline (#3512)
If max_length is equal or greater than cmdline length all trailing non-printable
characters are dropped. If max_length is 0 it should do the same.
This should also fix cmdline truncation if the last character is not '\0'.
Fixes #3469.
Diffstat (limited to 'src/basic/process-util.c')
-rw-r--r-- | src/basic/process-util.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c index faadb756c..bcc5a45d8 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -101,6 +101,7 @@ int get_process_comm(pid_t pid, char **name) { int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line) { _cleanup_fclose_ FILE *f = NULL; + bool space = false; char *r = NULL, *k; const char *p; int c; @@ -127,14 +128,21 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * return -ENOMEM; } - r[len++] = isprint(c) ? c : ' '; - } + if (isprint(c)) { + if (space) { + r[len++] = ' '; + space = false; + } + + r[len++] = c; + } else + space = true; + } if (len > 0) - r[len-1] = 0; + r[len] = 0; } else { - bool space = false; size_t left; r = new(char, max_length); |