From mteterin@250-217.customer.cloud9.net  Fri Nov 19 19:35:14 2004
Return-Path: <mteterin@250-217.customer.cloud9.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 123BE16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Nov 2004 19:35:14 +0000 (GMT)
Received: from out007.verizon.net (out007pub.verizon.net [206.46.170.107])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 8BFE543D31
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Nov 2004 19:35:13 +0000 (GMT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from corbulon.video-collage.com ([151.204.231.237])
          by out007.verizon.net
          (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP
          id <20041119193512.MXYM1327.out007.verizon.net@corbulon.video-collage.com>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Fri, 19 Nov 2004 13:35:12 -0600
Received: from 250-217.customer.cloud9.net (195-11.customer.cloud9.net [168.100.195.11])
	by corbulon.video-collage.com (8.13.1/8.13.1) with ESMTP id iAJJWfLp072071
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Nov 2004 14:32:42 -0500 (EST)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from 250-217.customer.cloud9.net (mteterin@localhost [127.0.0.1])
	by 250-217.customer.cloud9.net (8.13.1/8.13.1) with ESMTP id iAJJWMKG028633
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Nov 2004 14:32:22 -0500 (EST)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: (from mteterin@localhost)
	by 250-217.customer.cloud9.net (8.13.1/8.13.1/Submit) id iAJJU05M028437;
	Fri, 19 Nov 2004 14:30:00 -0500 (EST)
	(envelope-from mteterin)
Message-Id: <200411191930.iAJJU05M028437@250-217.customer.cloud9.net>
Date: Fri, 19 Nov 2004 14:30:00 -0500 (EST)
From: Mikhail Teterin <mi+mailmx@aldan.algebra.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Larry Wall <lwall@netlabs.com>
Subject: patch(1) may misapply hunks with too little context
X-Send-Pr-Version: 3.113
X-GNATS-Notify: lwall@netlabs.com

>Number:         74127
>Category:       bin
>Synopsis:       [patch] patch(1) may misapply hunks with too little context
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 19 19:40:29 GMT 2004
>Closed-Date:    
>Last-Modified:  Wed Aug  6 14:30:02 UTC 2008
>Originator:     Mikhail Teterin
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
Virtual Estates, Inc.
>Environment:
System: FreeBSD mi.us.murex.com 5.3-STABLE FreeBSD 5.3-STABLE #3: Tue Nov 9 17:40:11 EST 2004 mteterin@mi.us.murex.com:/meow/obj/misha/src/sys/Gigabyte i386

>Description:
	A patch produced with `diff -U0' or `-U1' may be misapplied
	if the file being patched changes (is of newer version) and
	the hunk is no longer applicable.

	patch(1) should fail loudly in this case, instead it sticks
	the new lines at the old location.

>How-To-Repeat:
	Try applying this patch:

	--- l	Mon Apr  3 20:00:28 2000
	+++ l	Fri May  5 10:01:58 2000
	@@ -5,1 +5,1 @@
	-    set Log(compressProg) /usr/local/bin/gzip
	+    set Log(compressProg) /usr/bin/gzip

	to this file:

	# This program is used to compress log files
	if {![info exists Log(compressProg)]} {
	    set Log(compressProg) gzip
	}

	# Flush interval
	if {![info exists Log(flushInterval)]} {
	    set Log(flushInterval) [expr {60 * 1000}]
	}

	# This is used to turn on an alternate debug log file
	if {![info exist Log(debug_log)]} {
	    set Log(debug_log) 0
	}

	It should not apply at all. Instead, one gets the reassuring:
	``Hunk #1 succeeded at 5 with fuzz 1.'' and a botched file.

>Fix:

	Use larger context, which is not always convenient.
>Release-Note:
>Audit-Trail:

From: Edwin Groothuis <edwin@freebsd.org>
To: FreeBSD Gnats Submit <freebsd-gnats-submit@freebsd.org>
Cc:  
Subject: Re: bin/74127: [patch] patch(1) may misapply hunks with too little context
Date: Thu, 7 Aug 2008 00:20:01 +1000

 See also bin/84816: patch(1) inserts a line in the wrong place
>Unformatted:
