Home | History | Annotate | Download | only in patch
History log of /src/usr.bin/patch/util.c
RevisionDateAuthorComments
 1.30  25-May-2021  cjep As per OpenBSD, use malloc for the line buffer. Fixes the known issue
with long lines and makes our ATF test suite pass fully.
Closes PR bin/54620 from coypu who suggested the approach.
Reviewed by christos.
 1.29  17-Nov-2020  rhialto branches: 1.29.2;
Remove heuristic for dealing with trailing newlines being truncated by mailers.

Patch and explanation taken from bsdimp:
https://bsdimp.blogspot.com/2020/08/a-35-year-old-bug-in-patch-found-in.html
https://svnweb.freebsd.org/base?view=revision&revision=364291

Every version of patch since the first one posted to mod.sources in 1985 have
included a heuristic for coping with the state of email messaging at the
time. This heuristic would add up to 4 blank lines to a patch if it thought it
needed it. The trouble is, though this causes at least one bug.

The bug in my case is that if you have a context diff whose last hunk only
deletes 3 or fewer lines, then if you try to reverse apply it with -R, it will
fail. The reason for this is the heuristic builds an internal representation
that includes those blank lines. However, it should really replicate the lines
from the pattern lines line it would any other time, not assume they are blank
lines. Removing this heuristic will prevent patch from misapplying the lines
removed after applying a 'fuzz' factor to the previous blank line in the file. I
believe this will only affect 'new-style' 4.3BSD context diffs and not the
older-style 4.2BSD diffs and plain, non-context diffs. It won't affect any of
the newer formats, since they don't use the 'omitted' construct in the same way.

Since this heuristic was put into patch at a time when email / etc ate trailing
white space on a regular basis, and since it's clear that this heuristic is the
wrong thing to do at least some of the time, it's better to remove it
entirely. It's not been needed for maybe 20 years since patch files are not
usually corrupted. If there are a small number of patch files that would benefit
from this corruption fixing, those already-currupt patches can be fixed by the
addition of blank lines. I'd wager that no one will ever come to me with an
example of a once-working patch file that breaks with this change. However, I
have 2 patches from the first 195 patches to 2.11BSD that are affected by this
bug, suggesting that the relative frequency of the issue has changed
signficantly since the original heuristic was put into place.
 1.28  18-Jun-2018  christos Keep things portable (requested by joerg) by not depending on reallocarr
and instead doing the overflow check ourselves.
 1.27  07-Nov-2015  joerg branches: 1.27.14;
paths.h is not used.
 1.26  02-Oct-2010  wiz Print version string to stdout instead of stderr;
it is user-requested and not an error.
 1.25  10-Jan-2010  joerg Plug a memory leak. From Igor Zinovik.
 1.24  19-Sep-2008  joerg Update patch to the version used by DragonFly and derived from OpenBSD.
Major changes are:
- better detection of double applied patches
- rejects remain unified diffs for unified patches
- far less limitations, e.g. patch lines may be arbitrary long

This addresses PR standards/11220 by changing patch -b behavior to be
POSIX compliant. Old behavior can be obtained using --suffix, which
works since NetBSD 1.4. pkgsrc has been adjusted accordingly.
 1.23  14-Oct-2007  lukem Convert to using raise_default_signal(3).
 1.22  09-Apr-2006  christos branches: 1.22.12;
Coverity CID 1253, 1254: Don't assign the return of read or write to size_t.
It will never be negative.
 1.21  25-Mar-2005  skd add --dry-run like gnu patch.
 1.20  30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Stop infinite loop if get lower case char with no upper case equiv.
 1.19  30-Jul-2003  itojun remove unused macros
 1.18  30-Jul-2003  itojun use bounded string op
 1.17  12-Jul-2003  itojun pedantic check around unsafe strncpy.
XXX this code needs a serious rewrite
 1.16  12-Jul-2003  itojun copyright missing in files, copy them from README
 1.15  30-May-2003  kristerw Simplify handling of memory allocation, and make sure all return values
from malloc etc. are handled.

This removes the old behavior to retry the operation with a less memory-
consuming method in case malloc failed (this mechanism has never really
worked, and is hard to test. Besides, it is less useful now than it was
20 years ago when the code was written...)
 1.14  29-May-2003  kristerw Be consistent with use of types (e.g. do not use LINENUM for quantities
that are not line numbers).
 1.13  06-Jan-2003  wiz writable, not writeable.
 1.12  16-Mar-2002  kristerw Check result of malloc and strdup
Made some functions static
Removed unneccessary buffer
Increased size of some buffers that could overflow
 1.11  11-Mar-2002  kristerw KNF
 1.10  11-Mar-2002  kristerw Ansify
Remove unused defines
Remove #ifndef lint
Remove redundant and incorrect casts.
 1.9  08-Mar-2002  kristerw Ansify
Remove 'register'
Make local functions static.
Remove most '#ifndef lint'
 1.8  11-Oct-2000  is More format string cleanup by sommerfeld.
 1.7  09-Feb-1999  sommerfe branches: 1.7.2; 1.7.10;
Fix PR2429: catch doubly-applied patches which create new files.
 1.6  06-Nov-1998  christos char -> unsigned char
rindex -> strrchr
 1.5  22-Feb-1998  christos WARNSify
 1.4  19-Sep-1996  thorpej RCS id police.
 1.3  07-Dec-1993  mycroft Eliminate a compiler warning.
 1.2  02-Aug-1993  mycroft Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1  09-Apr-1993  cgd branches: 1.1.1;
patch 2.0.12u8, from prep.ai.mit.edu. this is not under the GPL.
 1.1.1.1  09-Jan-1997  tls Import from 4.4BSD-Lite2
 1.7.10.1  18-Oct-2000  tv Pullup usr.bin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.7.2.1  19-Oct-2000  he Pull up revision 1.8 (requested by he):
Format string cleanup.
 1.22.12.1  06-Nov-2007  matt sync with HEAD
 1.27.14.1  25-Jun-2018  pgoyette Sync with HEAD
 1.29.2.1  31-May-2021  cjep sync with head

RSS XML Feed