Fix https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4402 :
authormorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 26 Jan 2010 01:40:10 +0000 (01:40 +0000)
committermorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 26 Jan 2010 01:40:10 +0000 (01:40 +0000)
Escape all non-printable characters so that we generate valid PDML.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31674 f5534014-38df-0310-8fa8-9805f1628bb7

print.c

diff --git a/print.c b/print.c
index bafd91ee4204a29a505eb52ada0989b5751854ed..91d259b1ad9991fdc446d036ab51a2cff836d08d 100644 (file)
--- a/print.c
+++ b/print.c
@@ -726,6 +726,7 @@ static void
 print_escaped_xml(FILE *fh, const char *unescaped_string)
 {
        const char *p;
+       char temp_str[8];
 
        for (p = unescaped_string; *p != '\0'; p++) {
                switch (*p) {
@@ -745,7 +746,12 @@ print_escaped_xml(FILE *fh, const char *unescaped_string)
                                fputs("&apos;", fh);
                                break;
                        default:
-                               fputc(*p, fh);
+                               if (g_ascii_isprint(*p))
+                                       fputc(*p, fh);
+                               else {
+                                       g_snprintf(temp_str, sizeof(temp_str), "\\x%x", (guint8)*p);
+                                       fputs(temp_str, fh);
+                               }
                }
        }
 }