]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps: Remove trailing NUL from command lines from /proc
authorSimon McVittie <smcv@collabora.com>
Thu, 25 Oct 2018 15:43:36 +0000 (16:43 +0100)
committerSimon McVittie <smcv@collabora.com>
Wed, 31 Oct 2018 16:56:36 +0000 (16:56 +0000)
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/222
Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-sysdeps-util-unix.c

index 24eba4e319208c7b5e8b3c1661c65b6a8a97b71d..262dcfdedca56046eb763ba20827d9db6ad266c5 100644 (file)
@@ -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];