On Wednesday 21 April 2004 10:43, Gilbert Ramirez wrote:
> On Tuesday 20 April 2004 11:58, Loránd Jakab wrote:
> > Hi everyone,
> > I have a problem with the PDML output of some IEEE 802.11 frames. I use
> > tethereal to transform binary captures to PDML, then I wrote a Perl
> > script based on the XML::Parser module to extract some information.
> > Recently I came across a probably malformed packed, that causes
> > tethereal to output binary data into the PDML file, which breaks the
> > parser. The binary data is written to the "show" attribute's value
> > field. If it is a malformed packet, it would be best that the dissector
> > would put only ASCII charcters in that field, maybe the hexa or octal
> > values...
> >
> > A packet that demonstrates the problem is attached.
> >
> > Could someone please post a patch?
> >
> > Thanks,
> > Lori
>
I've committed this fix. It may change in the future, but it should work for
you.
--gilbert
Index: epan/ftypes/ftype-string.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/epan/ftypes/ftype-string.c,v
retrieving revision 1.20
diff -u -r1.20 ftype-string.c
--- epan/ftypes/ftype-string.c 27 Feb 2004 12:00:32 -0000 1.20
+++ epan/ftypes/ftype-string.c 26 Apr 2004 02:07:12 -0000
@@ -34,6 +34,8 @@
#define CMP_MATCHES NULL
#endif
+#include <ctype.h>
+
static void
string_fvalue_new(fvalue_t *fv)
{
@@ -76,12 +78,21 @@
case FTREPR_DFILTER:
repr_len = 0;
for (p = fv->value.string; (c = *p) != '\0'; p++) {
+ /* Backslashes and double-quotes must
+ * be escaped */
if (c == '\\' || c == '"') {
- /* Backslashes and double-quotes
- must be escaped. */
+ repr_len += 2;
+ }
+ /* Values that can't nicely be represented
+ * in ASCII need to be escaped. */
+ else if (!isprint(c)) {
+ /* c --> \xNN */
+ repr_len += 4;
+ }
+ /* Other characters are just passed through. */
+ else {
repr_len++;
}
- repr_len++;
}
return repr_len + 2; /* string plus leading and trailing quotes */
}
@@ -94,17 +105,32 @@
{
gchar *p, c;
char *bufp;
+ char hex[2];
if (rtype == FTREPR_DFILTER) {
bufp = buf;
*bufp++ = '"';
for (p = fv->value.string; (c = *p) != '\0'; p++) {
+ /* Backslashes and double-quotes must
+ * be escaped. */
if (c == '\\' || c == '"') {
- /* Backslashes and double-quotes
- must be escaped. */
*bufp++ = '\\';
+ *bufp++ = c;
+ }
+ /* Values that can't nicely be represented
+ * in ASCII need to be escaped. */
+ else if (!isprint(c)) {
+ /* c --> \xNN */
+ sprintf(hex, "%02x", (unsigned int) c);
+ *bufp++ = '\\';
+ *bufp++ = 'x';
+ *bufp++ = hex[0];
+ *bufp++ = hex[1];
+ }
+ /* Other characters are just passed through. */
+ else {
+ *bufp++ = c;
}
- *bufp++ = c;
}
*bufp++ = '"';
*bufp = '\0';