diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-03-11 18:01:34 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-03-11 18:01:34 +0100 |
commit | fe8b5802bafb7bce7af525237d1195a91a3e4af4 (patch) | |
tree | 5d75f8fbabf93e2e5901ee6269425eabd126b5be | |
parent | 7b434a67dcaa88047095cf0196941c5456bb1c87 (diff) | |
download | busybox-w32-fe8b5802bafb7bce7af525237d1195a91a3e4af4.tar.gz busybox-w32-fe8b5802bafb7bce7af525237d1195a91a3e4af4.tar.bz2 busybox-w32-fe8b5802bafb7bce7af525237d1195a91a3e4af4.zip |
patch: segfault fix. Closes 7916
Fix segfault on this case (malformed --- line):
-- dwarves.orig 2015-02-25 01:45:27.753000000 +0000
+++ dwarves 2015-02-25 01:46:08.199000000 +0000
@@ -1,7 +1,7 @@
Bashful
Doc
Dopey
-Grouchy
+Grumpy
Happy
Sleepy
Sneezy
function old new delta
patch_main 1903 1957 +54
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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; |