]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
XML output: escape XML-metacharacters in executable path and arguments. This is a...
authorBart Van Assche <bvanassche@acm.org>
Sat, 22 Oct 2011 08:24:32 +0000 (08:24 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sat, 22 Oct 2011 08:24:32 +0000 (08:24 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12188

coregrind/m_main.c

index a93a78a0395b2b2c5cf858be11d1dde723d326fc..916b2e56e9a0aca2b66ad89f6d3d0ca4a19f4e91 100644 (file)
@@ -1026,21 +1026,26 @@ 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(const Char* arg,
-                            UInt (*umsg_or_xml)( const HChar*, ... ) )
+// Print the argument, escaping any chars that require it.
+static void umsg_arg(const Char* arg)
 {
    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
+         VG_(umsg)("\\");   // escape with a backslash if necessary
       }
-      umsg_or_xml("%c", arg[i]);
+      VG_(umsg)("%c", arg[i]);
    }
 }
 
+// Send output to the XML-stream and escape any XML meta-characters.
+static void xml_arg(const Char* arg)
+{
+   VG_(printf_xml)("%pS", arg);
+}
+
 /* 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
@@ -1055,6 +1060,9 @@ static void print_preamble ( Bool logging_to_fd,
    UInt (*umsg_or_xml)( const HChar*, ... )
       = VG_(clo_xml) ? VG_(printf_xml) : VG_(umsg);
 
+   UInt (*umsg_or_xml_arg)( const HChar* )
+      = VG_(clo_xml) ? xml_arg : umsg_arg;
+
    vg_assert( VG_(args_for_client) );
    vg_assert( VG_(args_for_valgrind) );
    vg_assert( toolname );
@@ -1106,11 +1114,12 @@ static void print_preamble ( Bool logging_to_fd,
       // favour utility and simplicity over aesthetics.
       umsg_or_xml("%sCommand: ", xpre);
       if (VG_(args_the_exename))
-         umsg_or_xml_arg(VG_(args_the_exename), umsg_or_xml);
+         umsg_or_xml_arg(VG_(args_the_exename));
+          
       for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
          HChar* s = *(HChar**)VG_(indexXA)( VG_(args_for_client), i );
          umsg_or_xml(" ");
-         umsg_or_xml_arg(s, umsg_or_xml);
+         umsg_or_xml_arg(s);
       }
       umsg_or_xml("%s\n", xpost);