Hi, patch will fail with a segmentation fault in "plan a" if it encounters a diff with a revision (Prereq line) when the input file is empty.
i_womp will be set to NULL to avoid mmapping 0 bytes, but later on it will be scanned for the supplied revision. The fix is simple: avoid scanning i_womp if it's NULL. Just enter the if-condition that the revision is not in there. How to reproduce: $ echo a > a $ echo b > b $ diff -u a b | sed '3i\ > Prereq: 1\ > ' > b.diff $ cat b.diff --- a Mon Nov 24 16:31:24 2014 +++ b Mon Nov 24 16:31:26 2014 Prereq: 1 @@ -1 +1 @@ -a +b $ rm a b; touch a b; $ patch -i b.diff Hmm... Looks like a unified diff to me... The text leading up to this was: -------------------------- |--- a Mon Nov 24 16:31:24 2014 |+++ b Mon Nov 24 16:31:26 2014 |Prereq: 1 -------------------------- Segmentation fault (core dumped) Tobias Index: inp.c =================================================================== RCS file: /cvs/src/usr.bin/patch/inp.c,v retrieving revision 1.40 diff -u -p -r1.40 inp.c --- inp.c 22 Nov 2014 15:49:28 -0000 1.40 +++ inp.c 24 Nov 2014 15:36:37 -0000 @@ -303,7 +303,7 @@ plan_a(const char *filename) /* now check for revision, if any */ if (revision != NULL) { - if (!rev_in_string(i_womp)) { + if (i_womp == NULL || !rev_in_string(i_womp)) { if (force) { if (verbose) say("Warning: this file doesn't appear "