From owner-freebsd-bugs@FreeBSD.ORG Thu May 15 05:30:00 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A8974F78 for ; Thu, 15 May 2014 05:30:00 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 858E1228A for ; Thu, 15 May 2014 05:30:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s4F5U0Rh014612 for ; Thu, 15 May 2014 05:30:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s4F5U06H014611; Thu, 15 May 2014 05:30:00 GMT (envelope-from gnats) Resent-Date: Thu, 15 May 2014 05:30:00 GMT Resent-Message-Id: <201405150530.s4F5U06H014611@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, Hiroto Kagotani Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DB4DDD31 for ; Thu, 15 May 2014 05:20:08 +0000 (UTC) Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C967721DA for ; Thu, 15 May 2014 05:20:08 +0000 (UTC) Received: from cgiserv.freebsd.org ([127.0.1.6]) by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s4F5K8TO098950 for ; Thu, 15 May 2014 05:20:08 GMT (envelope-from nobody@cgiserv.freebsd.org) Received: (from nobody@localhost) by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s4F5K88p098947; Thu, 15 May 2014 05:20:08 GMT (envelope-from nobody) Message-Id: <201405150520.s4F5K88p098947@cgiserv.freebsd.org> Date: Thu, 15 May 2014 05:20:08 GMT From: Hiroto Kagotani To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: bin/189827: sed treats some absolute addr2 of `N' command as relative X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 May 2014 05:30:00 -0000 >Number: 189827 >Category: bin >Synopsis: sed treats some absolute addr2 of `N' command as relative >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: Thu May 15 05:30:00 UTC 2014 >Closed-Date: >Last-Modified: >Originator: Hiroto Kagotani >Release: 10.0-RELEASE-p2 >Organization: >Environment: FreeBSD myhost.mydomain 10.0-RELEASE-p2 FreeBSD 10.0-RELEASE-p2 #0: Tue Apr 29 17:06:01 UTC 2014 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64 >Description: As sed's `N' command appends the next line of input to the pattern space, absolute addr2 having odd number difference from addr1 does not exactly match `linenum'. In this case, after r192732, sed treats addr2 as relative without checking the address type. As the result, `N' command with 2 addresses sometimes produces weird output. I confirmed that sed in r168258 and r192731 works as expected. sed before r168258 has another related `N' command bug, which also exists in OpenBSD and NetBSD. (discussed in https://forums.freebsd.org/viewtopic.php?t=37343) >How-To-Repeat: % seq 1 10 | sed '3,3N; s/\n/-/' 1 2 3-4 5 6 7 8 9 10 % seq 1 10 | sed '3,4N; s/\n/-/' 1 2 3-4 5-6 <-- unexpected 7-8 <-- unexpected 9 10 % seq 1 10 | sed '3,5N; s/\n/-/' 1 2 3-4 5-6 7 8 9 10 >Fix: Attached is my simple fix. Some complex testcases using `N' command should be added. Patch attached with submission follows: Index: usr.bin/sed/process.c =================================================================== --- usr.bin/sed/process.c (revision 266006) +++ usr.bin/sed/process.c (working copy) @@ -292,7 +292,8 @@ cp->startline = 0; lastaddr = 1; r = 1; - } else if (linenum - cp->startline <= cp->a2->u.l) + } else if (cp->a2->type == AT_RELLINE && + linenum - cp->startline <= cp->a2->u.l) r = 1; else if ((cp->a2->type == AT_LINE && linenum > cp->a2->u.l) || >Release-Note: >Audit-Trail: >Unformatted: