[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 85/98: utils/rpctrace: escape non-printable characters in strings
From: |
Samuel Thibault |
Subject: |
[hurd] 85/98: utils/rpctrace: escape non-printable characters in strings |
Date: |
Tue, 14 Jan 2014 02:00:04 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit 84932431cf4fbd494b4597105faed26ed2ac4efe
Author: Justus Winter <address@hidden>
Date: Fri Dec 13 12:57:55 2013 +0100
utils/rpctrace: escape non-printable characters in strings
* utils/rpctrace.c (escape_sequences): New char array mapping
characters to their escape sequence.
(print_data): Escape non-printable characters when printing strings.
---
utils/rpctrace.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
diff --git a/utils/rpctrace.c b/utils/rpctrace.c
index b39b2e3..0f68f44 100644
--- a/utils/rpctrace.c
+++ b/utils/rpctrace.c
@@ -1528,6 +1528,20 @@ print_reply_header (struct send_once_info *info,
mig_reply_header_t *reply,
}
}
+static char escape_sequences[0x100] =
+ {
+ ['\0'] = '0',
+ ['\a'] = 'a',
+ ['\b'] = 'b',
+ ['\f'] = 'f',
+ ['\n'] = 'n',
+ ['\r'] = 'r',
+ ['\t'] = 't',
+ ['\v'] = 'v',
+ ['\\'] = '\\',
+ ['\''] = '\'',
+ ['"'] = '"',
+ };
static void
print_data (mach_msg_type_name_t type,
@@ -1555,8 +1569,38 @@ print_data (mach_msg_type_name_t type,
case MACH_MSG_TYPE_CHAR:
if (nelt > strsize)
nelt = strsize;
- fprintf (ostream, "\"%.*s\"",
- (int) (nelt * eltsize), (const char *) data);
+ fprintf (ostream, "\"");
+ /* Scan data for non-printable characters. p always points to
+ the first character that has not yet been printed. */
+ const char *p, *q;
+ p = q = (const char *) data;
+ while (*q && q - (const char *) data < (int) (nelt * eltsize))
+ {
+ if (isgraph (*q) || *q == ' ')
+ {
+ q += 1;
+ continue;
+ }
+
+ /* We encountered a non-printable character. Print anything
+ that has not been printed so far. */
+ if (p < q)
+ fprintf (ostream, "%.*s", q - p, p);
+
+ char c = escape_sequences[*((const unsigned char *) q)];
+ if (c)
+ fprintf (ostream, "\\%c", c);
+ else
+ fprintf (ostream, "\\x%02x", *((const unsigned char *) q));
+
+ q += 1;
+ p = q;
+ }
+
+ /* Print anything that has not been printed so far. */
+ if (p < q)
+ fprintf (ostream, "%.*s", q - p, p);
+ fprintf (ostream, "\"");
return;
#if 0
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 63/98: libfshelp: use a hash table in get-identity.c, (continued)
- [hurd] 63/98: libfshelp: use a hash table in get-identity.c, Samuel Thibault, 2014/01/13
- [hurd] 90/98: trans/mtab: populate mtab objects on demand, Samuel Thibault, 2014/01/13
- [hurd] 09/98: init: fix memory leak, Samuel Thibault, 2014/01/13
- [hurd] 88/98: libports: remove the threadvars stack size hack, Samuel Thibault, 2014/01/13
- [hurd] 02/98: Normalize whitespace at the end of each file to '\n', Samuel Thibault, 2014/01/13
- [hurd] 84/98: utils/rpctrace: handle MACH_MSG_TYPE_PORT_SEND rights in trace_and_forward, Samuel Thibault, 2014/01/13
- [hurd] 82/98: utils/rpctrace: generalize code in rewrite_right, Samuel Thibault, 2014/01/13
- [hurd] 86/98: utils/rpctrace: fix output so that replies can be attributed to requests, Samuel Thibault, 2014/01/13
- [hurd] 81/98: utils/mount: fix autodetection of fat file systems, Samuel Thibault, 2014/01/13
- [hurd] 79/98: trans/fakeroot: remove dead code, Samuel Thibault, 2014/01/13
- [hurd] 85/98: utils/rpctrace: escape non-printable characters in strings,
Samuel Thibault <=
- [hurd] 80/98: trans/fakeroot: remove dead code, Samuel Thibault, 2014/01/13
- [hurd] 83/98: utils/rpctrace: generalize tracing code, Samuel Thibault, 2014/01/13
- [hurd] 89/98: libps: fix process user and system times, Samuel Thibault, 2014/01/13
- [hurd] 87/98: trans/fakeroot: shutdown the translator if the last client is gone, Samuel Thibault, 2014/01/13