From owner-svn-src-stable@FreeBSD.ORG Mon Feb 13 10:24:50 2012 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 083451065670; Mon, 13 Feb 2012 10:24:50 +0000 (UTC) (envelope-from tijl@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D07FA8FC14; Mon, 13 Feb 2012 10:24:49 +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 q1DAOnhW038171; Mon, 13 Feb 2012 10:24:49 GMT (envelope-from tijl@svn.freebsd.org) Received: (from tijl@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1DAOnZY038169; Mon, 13 Feb 2012 10:24:49 GMT (envelope-from tijl@svn.freebsd.org) Message-Id: <201202131024.q1DAOnZY038169@svn.freebsd.org> From: Tijl Coosemans Date: Mon, 13 Feb 2012 10:24:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r231578 - stable/9/usr.bin/hexdump X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Feb 2012 10:24:50 -0000 Author: tijl Date: Mon Feb 13 10:24:49 2012 New Revision: 231578 URL: http://svn.freebsd.org/changeset/base/231578 Log: MFC r229794: - 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. MFC r230649: Fix decoding of escape sequences in format strings: - Zero-terminate the resulting string by letting the for-loop copy the terminating zero. - Exit the for-loop after handling a backslash at the end of the format string to fix a buffer overrun. - Remove some unnecessary comments and blank lines. PR: bin/144722 Modified: stable/9/usr.bin/hexdump/parse.c Directory Properties: stable/9/usr.bin/hexdump/ (props changed) Modified: stable/9/usr.bin/hexdump/parse.c ============================================================================== --- stable/9/usr.bin/hexdump/parse.c Mon Feb 13 10:24:22 2012 (r231577) +++ stable/9/usr.bin/hexdump/parse.c Mon Feb 13 10:24:49 2012 (r231578) @@ -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,14 @@ 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++, p2++) { + if (*p1 == '\\') { + p1++; + switch(*p1) { + case '\0': + *p2 = '\\'; + *++p2 = '\0'; + return; case 'a': /* *p2 = '\a'; */ *p2 = '\007'; @@ -482,6 +485,11 @@ escape(char *p1) *p2 = *p1; break; } + } else { + *p2 = *p1; + if (*p1 == '\0') + return; + } } }