diff options
-rw-r--r-- | editors/patch.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/editors/patch.c b/editors/patch.c index 13785ef46..f86067544 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -345,6 +345,8 @@ done: | |||
345 | // state 1: Found +++ file indicator, look for @@ | 345 | // state 1: Found +++ file indicator, look for @@ |
346 | // state 2: In hunk: counting initial context lines | 346 | // state 2: In hunk: counting initial context lines |
347 | // state 3: In hunk: getting body | 347 | // state 3: In hunk: getting body |
348 | // Like GNU patch, we don't require a --- line before the +++, and | ||
349 | // also allow the --- after the +++ line. | ||
348 | 350 | ||
349 | int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 351 | int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
350 | int patch_main(int argc UNUSED_PARAM, char **argv) | 352 | int patch_main(int argc UNUSED_PARAM, char **argv) |
@@ -462,6 +464,14 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
462 | TT.context = 0; | 464 | TT.context = 0; |
463 | state = 2; | 465 | state = 2; |
464 | 466 | ||
467 | // If the --- line is missing or malformed, either oldname | ||
468 | // or (for -R) newname could be NULL -- but not both. Like | ||
469 | // GNU patch, proceed based on the +++ line, and avoid SEGVs. | ||
470 | if (!oldname) | ||
471 | oldname = xstrdup("MISSING_FILENAME"); | ||
472 | if (!newname) | ||
473 | newname = xstrdup("MISSING_FILENAME"); | ||
474 | |||
465 | // If this is the first hunk, open the file. | 475 | // If this is the first hunk, open the file. |
466 | if (TT.filein == -1) { | 476 | if (TT.filein == -1) { |
467 | int oldsum, newsum, empty = 0; | 477 | int oldsum, newsum, empty = 0; |