Commit Graph

94 Commits

Author SHA1 Message Date
wiz f31c8e4c6d Fix memory leak
CVS: ----------------------------------------------------------------------
CVS: CVSROOT  cvs.NetBSD.org:/cvsroot
CVS: please use "PR category/123" to have the commitmsg appended to PR 123
CVS:
CVS: Please evaluate your changes and consider the following.
CVS: Abort checkin if you answer no.
CVS: => For all changes:
CVS: Do the changed files compile?
CVS: Has the change been tested?
CVS: => If you are not completely familiar with the changed components:
CVS: Has the change been posted for review?
CVS: Have you allowed enough time for feedback?
CVS: => If the change is major:
CVS: => If the change adds files to, or removes files from $DESTDIR:
CVS: => If you are changing a library or kernel interface:
CVS: Have you successfully run "./build.sh release"?
2023-06-16 23:36:26 +00:00
wiz 0fb1b87aad Remove trailing whitespace. 2023-06-16 23:32:37 +00:00
wiz a874c40b0c Comment out variable assignations that are not used.
Remove trailing whitespace.
2023-06-16 23:31:53 +00:00
wiz 66c213d6e4 patch: add --backup-if-mismatch and --no-backup-if-mismatch for GNU patch compatibility
These options only make sense in POSIX mode, since NetBSD's patch
has --backup enabled by default and GNU patch doesn't.

In POSIX mode, GNU patch and NetBSD patch now behave the same for these
two options.
2023-06-16 11:27:00 +00:00
dholland 71e9f39a89 Fix the message that appears if you patch -R an unapplied patch. 2021-09-20 23:22:36 +00:00
cjep dca6da60c8 correct indentation. spotted by Roland. 2021-05-26 07:57:05 +00:00
cjep 9265e94bb9 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.
2021-05-25 11:25:59 +00:00
nia 894dfd713b patch(1): use PATH_MAX for the size of rejname
via freebsd, openbsd
2021-02-20 09:17:13 +00:00
nia 8b022a822c patch: make '-V none' work in the expected way
Internally the code confuses the concept of "the user doesn't want
a backup file" and "the user hasn't defined a type of backup file".

Introduce a new "undefined" backup type to serve the purpose "none"
previously did, and make "none" not generate backup files, as expected.

http://mail-index.netbsd.org/tech-userlevel/2021/02/19/msg012901.html

XXX pullup?
2021-02-19 17:46:53 +00:00
rhialto d36fee1ba5 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.
2020-11-17 20:49:12 +00:00
christos a2ee17b347 Keep things portable (requested by joerg) by not depending on reallocarr
and instead doing the overflow check ourselves.
2018-06-18 18:33:31 +00:00
christos 759529ae76 PR/53368: Thomas Barabosch: Potential integer overflow in usr.bin/patch/inp.c 2018-06-16 00:40:14 +00:00
christos 019d365a3a Pass -S to ed(1) so that patches containing ! commands don't run commands.
Real cause of CVS-2018-0492:
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894667)
2018-04-05 18:50:10 +00:00
wiz 01869ca4d2 Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
joerg a08385b414 Explain what "-V none" does. 2015-11-07 18:26:55 +00:00
joerg 3f2a71f305 paths.h is not used. 2015-11-07 18:11:21 +00:00
wiz 282efd00b8 Fix two typos. 2015-08-02 12:19:12 +00:00
christos 429d474275 remove reference to SCCS which is not supported anymore.
XXX: pullup-7
2015-08-02 03:19:02 +00:00
christos e139f8ac36 from bitrieg:
Substitution commands might contain a newline in the replacement pattern
(escaped with a backslash before it), causing patch's understanding of
the state the ed child process is in to diverge from reality. This can
lead to patch unwillingly feeding '!' (execute shell command) lines to
ed. Finding out how to do this is left as an exercise to the reader.

XXX: pullup-7
2015-07-30 21:47:51 +00:00
christos 2703f4af80 Use absolute paths for RCS commands (Martin Natano) 2015-07-24 18:56:44 +00:00
christos 8bfaa68572 From Martin Natano @bitrig: Use execve(2) instead of system to apply patches
that require rcs command execution instead system(3) to avoid malicious
filenames in patches causing bad things to happen. In the process, lose SCCS
support. It is not like we are shipping sccs commands for that to work.
2015-07-24 18:56:00 +00:00
christos 938d39fd7f PR/49422: Ryo ONODERA: patch(1) cannot handle context diffs 2014-11-27 15:07:23 +00:00
christos 59de200486 Avoid coredumps when the linenumbers in the hunks turn negative.
From: http://marc.info/?l=openbsd-tech&m=141693055412785

XXX: pullup 7
2014-11-26 00:31:32 +00:00
christos e9d34c2f4d mention -V none 2014-04-11 17:41:09 +00:00
christos 0b1777bf87 recognize -V none 2014-04-11 17:30:03 +00:00
wiz b5609ab012 Add comma after i.e.
From Bug Hunting.
2013-01-29 09:30:11 +00:00
wiz 1ac719d147 Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
2012-04-08 22:00:37 +00:00
joerg d5bd94639a Consistently use __dead and __printflike. 2011-09-06 18:25:14 +00:00
dholland 51ab93526e Exit with EXIT_FAILURE for invalid arguments. PR 43517. 2011-03-26 21:45:48 +00:00
wiz 2724492d78 Print version string to stdout instead of stderr;
it is user-requested and not an error.
2010-10-02 19:31:14 +00:00
joerg 06c042e9bc Plug a memory leak. From Igor Zinovik. 2010-01-10 01:10:16 +00:00
joerg 6e3add81a1 Do not try to mmap a zero length file. 2009-10-21 17:16:11 +00:00
joerg 57b5269dad Explicitly include fcntl.h for O_CREAT to not depend on namespace
pollution.
2009-06-05 19:55:43 +00:00
lukem d96ab870e3 Attempt to fix previous to address a coredump. 2009-04-18 03:25:34 +00:00
lukem 1e4c32c4f5 Fix sign-compare issue 2009-04-13 00:07:26 +00:00
joerg 7e69823738 Don't workaround ancient macro argumentent limitation with .Xo/.Xc. 2009-03-10 13:57:08 +00:00
joerg d5b2c9a825 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.
2008-09-19 18:33:34 +00:00
gdt 69bdd817cc Add error checking to use of fputs in creating output file in
temprorary directory.  Previously, fputs was used without checking the
return value, leading to silent truncation when the temporary
filesystem was full (such as can easily happen when migrating to
tmpfs).
2008-08-10 22:36:23 +00:00
lukem bd560fde31 Convert to using raise_default_signal(3). 2007-10-14 04:54:34 +00:00
christos 1e1f0dd3ab PR/34627: Lubomir Kundrak: patch(1) segfaults, when fed from stdin in batch
or force mode
2006-09-26 16:36:07 +00:00
christos 04e2c897d2 Coverity CID 3510: Don't leak memory. 2006-05-24 16:43:35 +00:00
christos bd21f84917 Coverity CID 1253, 1254: Don't assign the return of read or write to size_t.
It will never be negative.
2006-04-09 19:12:17 +00:00
christos f5a5211062 It is silly to creat() and close a file just to stat it. open/fstat/close
instead checking for errors. From Coverity CID 1276.
2006-04-09 19:06:34 +00:00
christos 5800a5519e Coverity CID 2078, 2079, 2080: Plug memory leaks. 2006-04-09 19:03:32 +00:00
wiz de60b309dc Sort options. Add -C to usage. 2005-03-25 23:55:02 +00:00
wiz eb0439126c Fix typo and drop trailing whitespace. 2005-03-25 23:49:28 +00:00
skd 4f9669ed8d add --dry-run like gnu patch. 2005-03-25 23:00:55 +00:00
mycroft 33131ab95f Fix an array overrun in option parsing.
Fixes PR 26732, PR 26775, PR 28416 and PR 28589.
2004-12-09 18:06:10 +00:00
dsl 58d3abc94f Add (unsigned char) cast to ctype functions
Stop infinite loop if get lower case char with no upper case equiv.
2004-10-30 21:52:09 +00:00
cube 224d89c7db Remove debug printf (hi mycroft!). 2004-08-14 12:53:35 +00:00