- Fix how hexdump parses escape strings

From the NetBSD bug:
The way how hexdump(1) parses escape sequences has some bugs.
It shows up when an escape sequence is used as the non-last character
of a format string.

PR:		bin/144722
Submitted by:	gcooper
Approved by:	rpaulo
Obtained from:	NetBSD
MFC after:	1 week
This commit is contained in:
Eitan Adler 2012-01-07 23:15:21 +00:00
parent f5d9d54516
commit 01155b2005
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=229794

View File

@ -255,7 +255,9 @@ rewrite(FS *fs)
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';
@ -449,13 +451,21 @@ escape(char *p1)
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';
@ -482,7 +492,12 @@ escape(char *p1)
*p2 = *p1;
break;
}
} else
*p2 = *p1;
}
}
void