From owner-svn-src-head@FreeBSD.ORG Sat Jan 7 23:15:22 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3810F1065678; Sat, 7 Jan 2012 23:15:22 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 22F7A8FC08; Sat, 7 Jan 2012 23:15:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q07NFMGK060479; Sat, 7 Jan 2012 23:15:22 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q07NFM3v060477; Sat, 7 Jan 2012 23:15:22 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201201072315.q07NFM3v060477@svn.freebsd.org> From: Eitan Adler Date: Sat, 7 Jan 2012 23:15:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r229794 - head/usr.bin/hexdump X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Jan 2012 23:15:22 -0000 Author: eadler (ports committer) Date: Sat Jan 7 23:15:21 2012 New Revision: 229794 URL: http://svn.freebsd.org/changeset/base/229794 Log: - 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 Modified: head/usr.bin/hexdump/parse.c Modified: head/usr.bin/hexdump/parse.c ============================================================================== --- head/usr.bin/hexdump/parse.c Sat Jan 7 22:29:46 2012 (r229793) +++ head/usr.bin/hexdump/parse.c Sat Jan 7 23:15:21 2012 (r229794) @@ -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