>Number: 144722 >Category: bin >Synopsis: [patch] port over character escape fix for hexdump in NetBSD >PR # 28157 >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Mar 14 00:20:02 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: 9-CURRENT >Organization: Cisco Systems, Inc. >Environment: FreeBSD bayonetta.localdomain 9.0-CURRENT FreeBSD 9.0-CURRENT #2: Thu Mar 4 13:16:39 PST 2010 gcoo...@bayonetta.localdomain:/usr/obj/usr/src/sys/BAYONETTA amd64 >Description: A number of \\ and \n related escaping bugs are reported in NetBSD PR # 28157 which were fixed quite a while ago in NetBSD's copy of hexdump, but not FreeBSD's copy of hexdump.
The attached patch is a minimal change which merges the fixes present in NetBSD's hexdump with our copy of hexdump (some of the fixes in the patch provided in the NetBSD PR had been orthogonally fixed in our hexdump). >How-To-Repeat: % hexdump -e '8/1 "\\x%02x" "\n"' /path/to/some/data hexdump: % : bad conversion character % hexdump -e '1/1 "\\x%02x"' /path/to/some/data Segmentation fault (core dumped) % hexdump -e '1/1 "\nx"' /path/to/some/data --> many 'n's are output. (instead of 'x's) >Fix: See attached patch. Patch attached with submission follows: Index: parse.c =================================================================== --- parse.c (revision 205137) +++ parse.c (working copy) @@ -259,7 +259,9 @@ sokay = NOTOKAY; } - p2 = p1 + 1; /* Set end pointer. */ + p2 = *p1 ? p1 + 1 : p1; /* Set end pointer -- make sure + * that it's non-NUL/-NULL first + * though. */ cs[0] = *p1; /* Set conversion string. */ cs[1] = '\0'; @@ -453,13 +455,21 @@ char *p2; /* alphabetic escape sequences have to be done in place */ - for (p2 = p1;; ++p1, ++p2) { - if (!*p1) { - *p2 = *p1; - break; - } - if (*p1 == '\\') - switch(*++p1) { + for (p2 = p1; *p1; p1++, p2++) { + /* + * Let's take a peak at the next item and see whether or not + * we need to escape the value... + */ + if (*p1 == '\\') { + + p1++; + + switch(*p1) { + /* A standalone `\' */ + case '\0': + *p2 = '\\'; + *++p2 = '\0'; + break; case 'a': /* *p2 = '\a'; */ *p2 = '\007'; @@ -486,7 +496,13 @@ *p2 = *p1; break; } + + } else { + *p2 = *p1; + } + } + } void >Release-Note: >Audit-Trail: >Unformatted: _______________________________________________ freebsd-bugs@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-bugs To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"