summaryrefslogtreecommitdiff
path: root/usr.bin/patch
AgeCommit message (Collapse)Author
2022-12-26spelling fixes; from paul tagliamonteJason McIntyre
amendments to his diff are noted on tech
2022-08-03fix locate_hunk in empty filesOmar Polo
if `first_guess' is zero then main() assumes that locate_hunk has failed and aborts the patch operation. Instead, make sure to return 1 (the line number) so that the patch operation can continue. Issue originally found by Neels Hofmeyr in the regress suite of the diff implementation for got, where the tests assume that applying a diff with `patch' and then again with `patch -R' yields back the original file. ok stsp@
2022-08-03fix dwim for reversed patchesOmar Polo
patch(1) fails to recognize the reversal application of a patch that cerates a file. since an empty context always matches, the idea is to run the dwim ("do what I mean") code also when locate_hunk succeeds but the patch would create a file and the match is on the first line. fixes the (disabled) test t3. ok stsp@
2022-03-31man pages: add missing commas between subordinate and main clausesChristian Weisgerber
jmc@ dislikes a comma before "then" in a conditional, so leave those untouched. ok jmc@
2022-02-18Avoid gendered language in man pages when not referring to a specificJonathan Gray
person. Rewrite or use singular they. ok thfr@ sthen@ daniel@ ian@ job@ kmos@ jcs@ ratchov@ phessler@ and others I'm likely missing on an earlier version. feedback tj@, feedback and ok jmc@
2021-12-21state up front that patch(1) operates on text files,Ingo Schwarze
fixing an omission pointed out by chrisz@; OK jmc@ deraadt@ chrisz@
2021-11-09-i may not be specified multiple times; from josh grosseJason McIntyre
ok millert
2021-10-24For open/openat, if the flags parameter does not contain O_CREAT, theTheo de Raadt
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past have passed mode_t (0, 044, 0644, or such), which might lead future people to copy this broken idiom, and perhaps even believe this parameter has some meaning or implication or application. Delete them all. This comes out of a conversation where tb@ noticed that a strange (but intentional) pledge behaviour is to always knock-out high-bits from mode_t on a number of system calls as a safety factor, and his bewilderment that this appeared to be happening against valid modes (at least visually), but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef. ok millert
2020-10-12Accommodate POSIX basename(3) that takes a non-const parameter andChristian Weisgerber
may modify the string buffer. From Joerg Sonnenberger for DragonFly BSD. ok millert@
2019-12-11Merge existing decls and decls introduced in rev 1.10Jeremie Courreges-Anglas
Also: - sort declarations in the same order as definitions in pch.c - delete an extra pfetch() declaration ok tobias@
2019-12-09Move RCS Id to the top of the fileJeremie Courreges-Anglas
2019-12-02Tweak previous, using fputs here was fineJeremie Courreges-Anglas
2019-12-02Use getline(3) to handle lines longer than 8192 bytes in patch filesJeremie Courreges-Anglas
Spotted by jsg@ when working on mesa. Diff tested by sthen@ in a partial i386 bulk. Input from and ok jsg@ millert@
2019-08-17signal handlers should not call exit() due to possibility of reenteringTheo de Raadt
libc (stdio etc), instead do the unlink tasks then call _exit() instead ok millert
2019-06-28When system calls indicate an error they return -1, not some arbitraryTheo de Raadt
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
2019-06-28mkstemp() returns -1 on failureTheo de Raadt
2018-12-30Delete unnecessary <libgen.h> #includesPhilip Guenther
ok deraadt@
2018-06-22Add --dry-run as synonym to -C/--check.Vadim Zhukov
FreeBSD and NetBSD has this for a while, and GNU patch got it even earlier than we got -C. input from sthen@ & jca@; okay sthen@, jca@ and deraadt@.
2018-04-26Use <fcntl.h> instead of <sys/file.h> for open() and friends.Philip Guenther
Delete a bunch of unnecessary #includes and sort to match style(9) while doing the above cleanup. ok deraadt@ krw@
2018-04-11Stop telling patch(1) runs ed(1).Vadim Zhukov
okay tb@ and benno@
2018-04-07Remove unused pathnames.h header since patch was refactoring into not invokinganton
ed back in 2015; ok millert@ tb@ tobias@
2017-12-20Fix adding and removing files with git-style a/ b/ diffs: only skipTheo Buehler
six letters if they actually match "--- a/" and "+++ b/" instead of laxer checks. ok tom, tedu, millert
2017-06-12rejname[] is also -r option buffer, and should be PATH_MAXTheo de Raadt
ok millert
2017-05-30Unbreak previous for git diffs that do not have the a/ prefix.Florian Obser
Found the hard way be me, OK tedu
2017-05-26sometimes patches coming from other places have extra a/ and b/ directoriesTed Unangst
prepended to filenames. detect this condition and attempt to correct it. ok openbsd
2017-03-26One string buffer can use recallocarray() to ensure that the address spaceTheo de Raadt
doesn't get dribbled with known contents. ok otto millert tobias
2017-03-25parameter "lines_allocated" is a local pointer and should not be confusedTheo de Raadt
with the global by the same name, so rename it "lines_allocatedp".
2016-09-02Fix 'c'hange command handling if last line of a file is removed.Tobias Stoeckmann
If the last line of a file is removed, the line cache is erroneously considered empty, which means that changed lines are added at the top. spotted by and okay otto@
2016-09-02If reading fails, do not go into infinite loop asking for a filenameOtto Moerbeek
Happens in bulf build where no tty is available. ok sthen@ naddy@ $(jot -b yes 1000) landry@
2016-07-19Cleanup close(open idioms.Theo de Raadt
ok krw
2016-02-22Properly handle ed-files which fully replace input file content. ThisTobias Stoeckmann
misbehaviour is triggered with 'c' and 'i' commands on empty buffers. Spotted and fixed by Martin Natano <natano at natano dot net>. ok millert@
2016-01-04usage() should exit 2 here, not EXIT_SUCCESSGleydson Soares
ok tb@
2015-12-29fix exit status on pledge(2) failure.Gleydson Soares
OK tb@ jsg@
2015-11-11exit() after perror() for pledge failure. Perhaps this got introducedTheo de Raadt
as a test idiom, either when pledge was young or during the transition to strings.... dunno
2015-11-11creat() -> open equiv; from Frederic NowakTheo de Raadt
2015-10-16Add native support for ed-style diffs. No need to pledge "proc exec" anymore.Tobias Stoeckmann
ok deraadt
2015-10-09Change all tame callers to namechange to pledge(2).Theo de Raadt
2015-10-07patch(1) can move to "stdio rpath wpath cpath tmppath fattr proc exec"Theo de Raadt
(adding proc exec), now that "exec" has arrived in the kernel. This permits the dangerous game of feeding ed-style diffs with popen() via /bin/ed. Shocked yet? Your mission, should you choose to accept it, is to replace this code with an builtin ed-style patcher, maybe cribbing code from ed itself. I'm sorry, but we can't fix the entire world all at once. Noone loves deprecating standarized features as much as we do, but there are some lines. Maybe if people become aware of how crappy the implimentations of some standard features are, they could help decide the path.
2015-10-04remove tame "proc". it is not useful, because the "ed" diffs requireTheo de Raadt
fork+execve, and execve is not going to become available in this fashion. ed diffs should be handled using a built-in handler, and various folks have been discussing this behind the scenes.
2015-10-03As pointed out by tobiasu, ed-style patches still use popen() and executeTheo de Raadt
/bin/ed. This is RETARDED. Nothing learned from the last year? Add tame "proc" until that is fixed, to allow fork+exec. I beg for someone to cross-link the guts of ed directly into patch, or write a ed-subset which can do the job.
2015-10-03patch appears to work fully with tame "stdio rpath wpath cpath tmppath fattr".Theo de Raadt
in case of exploitation, no more network access, fork, execve, etc. I wonder if we could use whitepath lists here - if it is reasonable to limit operation in directories known early on?
2015-07-31Account for newlines in substitution (s///) commands. SubstitutionTodd C. Miller
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. From Martin Natano. OK deraadt@
2015-07-26Remove support for automatically checking files out of RCS. TheTodd C. Miller
behavior is confusing to users and even GNU patch no longer does it by default. OK krw@ guenther@
2015-03-13remove the first comma from constructs like ", and," and ", or,": you can useJason McIntyre
"and" and "or" to join sentence clauses, and you can use commas, but both hinders reading;
2015-02-05Include stdint.h, not limits.h to get SIZE_MAX. OK guenther@Todd C. Miller
2015-01-16Replace <sys/param.h> with <limits.h> and other less dirty headers whereTheo de Raadt
possible. Annotate <sys/param.h> lines with their current reasons. Switch to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where sensible to avoid pulling in the pollution. These are the files confirmed through binary verification. ok guenther, millert, doug (helped with the verification protocol)
2014-12-14Handle ed command "s" as a one line command, which it is.Tobias Stoeckmann
Prevents arbitrary ed command executions in following lines. ok millert
2014-12-13The function savestr allows NULL return values during Plan A patching so inTobias Stoeckmann
case of out of memory conditions, Plan B can step in. In many cases, NULL value is not properly handled, so use xstrdup here (it's outside Plan A/B patching, which means that even Plan B relies on successful operations).
2014-12-09Fix division by zero for files with long lines (> 1024) in Plan B modeTobias Stoeckmann
by supporting arbitrarily long lines just like Plan A does. ok tedu
2014-12-08spacesTheo de Raadt