From owner-freebsd-bugs@FreeBSD.ORG Sun Mar 14 00:20:03 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2EA2C106564A for ; Sun, 14 Mar 2010 00:20:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E68C28FC1A for ; Sun, 14 Mar 2010 00:20:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o2E0K2Ei061734 for ; Sun, 14 Mar 2010 00:20:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o2E0K2wu061733; Sun, 14 Mar 2010 00:20:02 GMT (envelope-from gnats) Resent-Date: Sun, 14 Mar 2010 00:20:02 GMT Resent-Message-Id: <201003140020.o2E0K2wu061733@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 26CF31065670 for ; Sun, 14 Mar 2010 00:11:44 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id F02858FC13 for ; Sun, 14 Mar 2010 00:11:43 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o2E0BhAJ077171 for ; Sun, 14 Mar 2010 00:11:43 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o2E0Bg8G077170; Sun, 14 Mar 2010 00:11:42 GMT (envelope-from nobody) Message-Id: <201003140011.o2E0Bg8G077170@www.freebsd.org> Date: Sun, 14 Mar 2010 00:11:42 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/144722: [patch] port over character escape fix for hexdump in NetBSD PR # 28157 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Mar 2010 00:20:03 -0000 >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 gcooper@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: