From: Julian Seward Date: Tue, 6 Feb 2018 11:54:03 +0000 (+0100) Subject: Bug 384631 - Sanitise client args as printed with -v X-Git-Tag: VALGRIND_3_14_0~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cf2d76385039217b284ccc1745fc992f0a2a98b;p=thirdparty%2Fvalgrind.git Bug 384631 - Sanitise client args as printed with -v 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. --- diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c index 3c437e4d9a..1069d12963 100644 --- a/coregrind/m_libcprint.c +++ b/coregrind/m_libcprint.c @@ -53,9 +53,25 @@ /*=== 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.