Bug 191641 - patch(1) may misapply diffs missing final line feed
Summary: patch(1) may misapply diffs missing final line feed
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Kyle Evans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-05 21:26 UTC by Gavin Atkinson
Modified: 2018-01-18 21:50 UTC (History)
5 users (show)

See Also:
kevans: mfc-stable11+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gavin Atkinson freebsd_committer freebsd_triage 2014-07-05 21:26:45 UTC
I believe that this is unrelated to bug 74127.

"patch 2.0-12u10 FreeBSD" may sometimes duplicate the previous line when it should actually insert a blank line.  This is reproduceable, for example, try applying the patch in bug 190195 to a checked out r242826 head tree, then compare the expected diff to the resulting diff.

I believe this is due to the last line of the patch attached to bug 190195 not ending with a linefeed.

Expected:

[...]
>                                 "Northbridge Proximity Temperature", \
>                                 "Wireless Module Temperature", }
>
 #define ASMC_MP_TEMPS		{ "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", \
Seen:

[...] 
>				  "Northbridge Proximity Temperature", \
>				  "Wireless Module Temperature", }
>				  "Wireless Module Temperature", }
 #define ASMC_MP_TEMPS		{ "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", \
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2017-10-06 16:42:50 UTC
Hi,

Review pending for this: https://reviews.freebsd.org/D12609
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2017-10-07 03:35:22 UTC
(In reply to Kyle Evans from comment #1)

Looks good. does it also fix PR 191641 ?
Comment 3 Conrad Meyer freebsd_committer freebsd_triage 2017-10-08 16:57:22 UTC
(In reply to Pedro F. Giffuni from comment #2)
That's this PR?
Comment 4 Pedro F. Giffuni freebsd_committer freebsd_triage 2017-10-08 17:19:28 UTC
(In reply to Conrad Meyer from comment #3)
Sorry .. I meant 74127, which also refers to 84816.
Comment 5 Conrad Meyer freebsd_committer freebsd_triage 2017-10-08 17:23:05 UTC
No, I don't see how this could fix 74127 (or 84816).
Comment 6 Pedro F. Giffuni freebsd_committer freebsd_triage 2017-10-08 17:37:13 UTC
(In reply to Conrad Meyer from comment #5)

Well, the patch is correct but we may be missing the big picture(TM).

No one is asking Kyle to fix all the bugs in patch(1) though ;).
Comment 7 Kyle Evans freebsd_committer freebsd_triage 2017-10-08 17:56:36 UTC
(In reply to Pedro F. Giffuni from comment #4)

74127 looks like a logical error elsewhere- I can poke at that sometime this upcoming week.
Comment 8 commit-hook freebsd_committer freebsd_triage 2017-10-09 14:50:43 UTC
A commit references this bug:

Author: kevans
Date: Mon Oct  9 14:50:02 UTC 2017
New revision: 324431
URL: https://svnweb.freebsd.org/changeset/base/324431

Log:
  patch(1): Don't overrun line buffer in some cases

  Patches like file.txt attached to PR 190195 with a final line formed
  like ">(EOL)" could cause a copy past the end of the current line buffer. In the
  case of PR 191641, this caused a duplicate line to be copied into the resulting
  file.

  Instead of running past the end, treat it as if it were a blank line.

  PR:		191641
  Reviewed by:	cem, emaste, pfg
  Approved by:	emaste (mentor)
  Differential Revision:	https://reviews.freebsd.org/D12609

Changes:
  head/usr.bin/patch/pch.c
Comment 9 vali gholami 2017-11-26 20:46:32 UTC
MARKED AS SPAM
Comment 10 commit-hook freebsd_committer freebsd_triage 2018-01-18 21:47:24 UTC
A commit references this bug:

Author: kevans
Date: Thu Jan 18 21:46:42 UTC 2018
New revision: 328147
URL: https://svnweb.freebsd.org/changeset/base/328147

Log:
  MFC r324431: patch(1): Don't overrun line buffer in some cases

  Patches like file.txt attached to PR 190195 with a final line formed
  like ">(EOL)" could cause a copy past the end of the current line buffer. In
  the case of PR 191641, this caused a duplicate line to be copied into the
  resulting file.

  Instead of running past the end, treat it as if it were a blank line.

  PR:		191641

Changes:
_U  stable/11/
  stable/11/usr.bin/patch/pch.c