diff options
Diffstat (limited to 'editors/patch.c')
-rw-r--r-- | editors/patch.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/editors/patch.c b/editors/patch.c index 13785ef46..cb25e4140 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) |
@@ -412,7 +414,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
412 | } | 414 | } |
413 | 415 | ||
414 | // Open a new file? | 416 | // Open a new file? |
415 | if (!strncmp("--- ", patchline, 4) || !strncmp("+++ ", patchline, 4)) { | 417 | if (is_prefixed_with(patchline, "--- ") || is_prefixed_with(patchline, "+++ ")) { |
416 | char *s, **name = reverse ? &newname : &oldname; | 418 | char *s, **name = reverse ? &newname : &oldname; |
417 | int i; | 419 | int i; |
418 | 420 | ||
@@ -444,7 +446,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
444 | 446 | ||
445 | // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@ | 447 | // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@ |
446 | // but a missing ,value means the value is 1. | 448 | // but a missing ,value means the value is 1. |
447 | } else if (state == 1 && !strncmp("@@ -", patchline, 4)) { | 449 | } else if (state == 1 && is_prefixed_with(patchline, "@@ -")) { |
448 | int i; | 450 | int i; |
449 | char *s = patchline+4; | 451 | char *s = patchline+4; |
450 | 452 | ||
@@ -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; |