diff options
author | Simon McVittie <smcv@collabora.com> | 2018-10-25 16:43:36 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2018-10-31 16:56:36 +0000 |
commit | f7bf69443df17ca4b58256030c337b0369c7ab80 (patch) | |
tree | af2fea30ae979194d38a70209a2f8c5820ff477e /dbus/dbus-sysdeps-util-unix.c | |
parent | 93c1d08300605893cb1c6645bead1b1654378c56 (diff) | |
download | dbus-f7bf69443df17ca4b58256030c337b0369c7ab80.tar.gz |
sysdeps: Remove trailing NUL from command lines from /proc
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/222
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'dbus/dbus-sysdeps-util-unix.c')
-rw-r--r-- | dbus/dbus-sysdeps-util-unix.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index 24eba4e3..262dcfde 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -1092,7 +1092,22 @@ string_squash_nonprintable (DBusString *str) buf = _dbus_string_get_udata (str); len = _dbus_string_get_length (str); - + + /* /proc/$pid/cmdline is a sequence of \0-terminated words, but we + * want a sequence of space-separated words, with no extra trailing + * space: + * "/bin/sleep" "\0" "60" "\0" + * -> "/bin/sleep" "\0" "60" + * -> "/bin/sleep" " " "60" + * + * so chop off the trailing NUL before cleaning up unprintable + * characters. */ + if (len > 0 && buf[len - 1] == '\0') + { + _dbus_string_shorten (str, 1); + len--; + } + for (i = 0; i < len; i++) { unsigned char c = (unsigned char) buf[i]; |