From owner-freebsd-bugs@FreeBSD.ORG Wed Apr 19 16:10:18 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3B01D16A40B for ; Wed, 19 Apr 2006 16:10:18 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id ECE2A43D5C for ; Wed, 19 Apr 2006 16:10:15 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k3JGAFZQ066324 for ; Wed, 19 Apr 2006 16:10:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k3JGAFUW066323; Wed, 19 Apr 2006 16:10:15 GMT (envelope-from gnats) Resent-Date: Wed, 19 Apr 2006 16:10:15 GMT Resent-Message-Id: <200604191610.k3JGAFUW066323@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, Andrey Zholos Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 09F2516A40D for ; Wed, 19 Apr 2006 16:05:48 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71DF943D48 for ; Wed, 19 Apr 2006 16:05:46 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k3JG5kmD028693 for ; Wed, 19 Apr 2006 16:05:46 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k3JG5kdR028692; Wed, 19 Apr 2006 16:05:46 GMT (envelope-from nobody) Message-Id: <200604191605.k3JG5kdR028692@www.freebsd.org> Date: Wed, 19 Apr 2006 16:05:46 GMT From: Andrey Zholos To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: bin/96052: sed "P" command broken on empty pattern space 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: Wed, 19 Apr 2006 16:10:18 -0000 >Number: 96052 >Category: bin >Synopsis: sed "P" command broken on empty pattern space >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Apr 19 16:10:15 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Andrey Zholos >Release: FreeBSD 6.1-PRERELEASE >Organization: >Environment: FreeBSD sigma 6.1-PRERELEASE FreeBSD 6.1-PRERELEASE #5: Fri Mar 24 21:54:25 EET 2006 root@sigma:/usr/obj/usr/src/sys/SIGMA i386 >Description: If the "P" command is used once on a non-empty pattern space and then again on an empty pattern space, the second usage restores the pattern space length to the length that it had when the first "P" was used. # echo 111 | sed -ne 'G;P;s/.*//;l;P;l' 111 $ \000\000\000\000$ Here, when the first "P" is used, there are 4 characters in the pattern space ("111\n"). The "s" clears the pattern space, but after the second "P" there are 4 characters there again. >How-To-Repeat: See above. >Fix: --- /usr/src/usr.bin/sed/process.c.orig Sat Apr 9 17:31:41 2005 +++ /usr/src/usr.bin/sed/process.c Wed Apr 19 17:54:18 2006 @@ -188,12 +188,11 @@ case 'P': if (pd) break; - if (psl != 0 && - (p = memchr(ps, '\n', psl)) != NULL) { + if ((p = memchr(ps, '\n', psl)) != NULL) { oldpsl = psl; psl = p - ps; } OUT(ps) if (p != NULL) psl = oldpsl; break; When psl == 0, p is not reset to NULL and oldpsl is not set, so "psl = oldpsl" restores psl to whatever it was on a previous "P" command. So, one possible fix is to drop the test for psl != 0. >Release-Note: >Audit-Trail: >Unformatted: