]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 384631 - Sanitise client args as printed with -v
authorJulian Seward <jseward@acm.org>
Tue, 6 Feb 2018 11:54:03 +0000 (12:54 +0100)
committerJulian Seward <jseward@acm.org>
Tue, 6 Feb 2018 11:54:03 +0000 (12:54 +0100)
umsg_arg, xml_arg: sanitise the guest's command line arguments that we print
in a "Command: " line as part of the preamble, when -v is given.  This
changes any character outside the range 32 .. 127 to '_'.  Printing
unsanitised command line args has been observed to cause xfce4-terminal to
assert.  Of course the command line args actually given to the guest aren't
changed -- this just changes how they are printed.

This fixes #384631.

coregrind/m_libcprint.c

index 3c437e4d9a62d5580a2ef35f2af779f76fc99a00..1069d129636a7a695738544506f9a213f63bdef2 100644 (file)
 /*=== Printing the preamble                                        ===*/
 /*====================================================================*/
 
+// Returns a strdup'd copy of |str| in which characters which are not in the
+// obviously-harmless-ASCII range are replaced with '_'.  Not doing this has
+// been observed to cause xfce4-terminal to assert.  Caller takes ownership
+// of the returned string.
+static HChar* sanitise_arg (const HChar* arg)
+{
+   HChar* clone = VG_(strdup)("m_libcprint.sanitise_arg", arg);
+   for (HChar* p = clone; *p; p++) {
+      UInt c = * ((UChar*)p);
+      if (c < 32 || c > 127) c = '_';
+      *p = (HChar)c;
+   }
+   return clone;
+}
+
 // Print the argument, escaping any chars that require it.
-static void umsg_arg(const HChar *arg)
+static void umsg_arg(const HChar *unsanitised_arg)
 {
+   HChar* arg = sanitise_arg(unsanitised_arg);
    SizeT len = VG_(strlen)(arg);
    const HChar *special = " \\<>";
    for (UInt i = 0; i < len; i++) {
@@ -64,12 +80,15 @@ static void umsg_arg(const HChar *arg)
       }
       VG_(umsg)("%c", arg[i]);
    }
+   VG_(free)(arg);
 }
 
 // Send output to the XML-stream and escape any XML meta-characters.
-static void xml_arg(const HChar *arg)
+static void xml_arg(const HChar *unsanitised_arg)
 {
+   HChar* arg = sanitise_arg(unsanitised_arg);
    VG_(printf_xml)("%pS", arg);
+   VG_(free)(arg);
 }
 
 // Write the name and value of log file qualifiers to the xml file.