Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 212eb96

Browse files
Thomas Rastgitster
authored andcommitted
apply: carefully strdup a possibly-NULL name
2901bbe (apply: free patch->{def,old,new}_name fields, 2012-03-21) cleaned up the memory management of filenames in the patches, but forgot that find_name_traditional() can return NULL as a way of saying "I couldn't find a name". That NULL unfortunately gets passed into xstrdup() next, resulting in a segfault. Use null_strdup() so as to safely propagate the null, which will let us emit the correct error message. Reported-by: DevHC on #git Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ce2e39 commit 212eb96

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static void parse_traditional_patch(const char *first, const char *second, struc
898898
patch->old_name = name;
899899
} else {
900900
patch->old_name = name;
901-
patch->new_name = xstrdup(name);
901+
patch->new_name = null_strdup(name);
902902
}
903903
}
904904
if (!name)

t/t4111-apply-subdir.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ test_expect_success 'apply --index from subdir of toplevel' '
8686
test_cmp expected sub/dir/file
8787
'
8888

89+
test_expect_success 'apply half-broken patch from subdir of toplevel' '
90+
(
91+
cd sub/dir &&
92+
test_must_fail git apply <<-EOF
93+
--- sub/dir/file
94+
+++ sub/dir/file
95+
@@ -1,0 +1,0 @@
96+
--- file_in_root
97+
+++ file_in_root
98+
@@ -1,0 +1,0 @@
99+
EOF
100+
)
101+
'
102+
89103
test_expect_success 'apply from .git dir' '
90104
cp postimage expected &&
91105
cp preimage .git/file &&

0 commit comments

Comments
 (0)