From c20ba72234c51302e8da8916cf40482a84a7ed88 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 2 Aug 2009 23:03:06 +0000 Subject: [PATCH] In the "Command:" line in the preamble, escape special chars such as ' ' and '\\'. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10690 --- coregrind/m_main.c | 20 ++++++++++++++++++-- none/tests/Makefile.am | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 6e33e77a3b..8e3fb468e4 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -958,6 +958,21 @@ static void print_file_vars(Char* format) /*=== Printing the preamble ===*/ /*====================================================================*/ +// Print the command, escaping any chars that require it. +static void umsg_or_xml_arg(Char* arg, + UInt (*umsg_or_xml)( const HChar*, ... ) ) +{ + SizeT len = VG_(strlen)(arg); + Char* special = " \\<>"; + Int i; + for (i = 0; i < len; i++) { + if (VG_(strchr)(special, arg[i])) { + umsg_or_xml("\\"); // escape with a backslash if necessary + } + umsg_or_xml("%c", arg[i]); + } +} + /* Ok, the logging sink is running now. Print a suitable preamble. If logging to file or a socket, write details of parent PID and command line args, to help people trying to interpret the @@ -1030,7 +1045,7 @@ static void print_preamble ( Bool logging_to_fd, */ umsg_or_xml("Command: "); if (VG_(args_the_exename)) - umsg_or_xml("%s", VG_(args_the_exename)); + umsg_or_xml_arg(VG_(args_the_exename), umsg_or_xml); n = 0; for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) { HChar* s = *(HChar**)VG_(indexXA)( VG_(args_for_client), i ); @@ -1043,7 +1058,8 @@ static void print_preamble ( Bool logging_to_fd, VG_(umsg)("\n "); n = slen; } - umsg_or_xml(" %s", s); + umsg_or_xml(" "); + umsg_or_xml_arg(s, umsg_or_xml); } umsg_or_xml("\n"); diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index cb85e3c32a..92b1caaf19 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -57,6 +57,7 @@ EXTRA_DIST = \ cmdline4.stderr.exp cmdline4.vgtest \ cmdline5.stderr.exp cmdline5.vgtest \ cmdline6.stderr.exp cmdline6.vgtest \ + cmd-with-special.stderr.exp cmd-with-special.vgtest \ coolo_sigaction.stderr.exp \ coolo_sigaction.stdout.exp coolo_sigaction.vgtest \ coolo_strlen.stderr.exp coolo_strlen.vgtest \ -- 2.47.3