aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-03-11 18:01:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-03-11 18:01:34 +0100
commitfe8b5802bafb7bce7af525237d1195a91a3e4af4 (patch)
tree5d75f8fbabf93e2e5901ee6269425eabd126b5be
parent7b434a67dcaa88047095cf0196941c5456bb1c87 (diff)
downloadbusybox-fe8b5802bafb7bce7af525237d1195a91a3e4af4.tar.gz
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.c10
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:
// state 1: Found +++ file indicator, look for @@
// state 2: In hunk: counting initial context lines
// state 3: In hunk: getting body
+// Like GNU patch, we don't require a --- line before the +++, and
+// also allow the --- after the +++ line.
int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int patch_main(int argc UNUSED_PARAM, char **argv)
@@ -462,6 +464,14 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
TT.context = 0;
state = 2;
+ // If the --- line is missing or malformed, either oldname
+ // or (for -R) newname could be NULL -- but not both. Like
+ // GNU patch, proceed based on the +++ line, and avoid SEGVs.
+ if (!oldname)
+ oldname = xstrdup("MISSING_FILENAME");
+ if (!newname)
+ newname = xstrdup("MISSING_FILENAME");
+
// If this is the first hunk, open the file.
if (TT.filein == -1) {
int oldsum, newsum, empty = 0;