{"thread":{"id":"34243","subject":"[PATCH] apply: carefully strdup a possibly-NULL name","startedAt":"2013-06-21T11:38:00Z","lastAt":"2013-06-21T11:38:00Z","messageCount":1,"participants":["Thomas Rast"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"221592","messageId":"76659b15f0a52d9e94143bee803f5cf45de1e6cc.1371814540.git.trast@inf.ethz.ch","threadId":"34243","inReplyTo":null,"subject":"[PATCH] apply: carefully strdup a possibly-NULL name","fromName":"Thomas Rast","fromEmail":"trast@inf.ethz.ch","sentAt":"2013-06-21T11:38:00Z","receivedAt":"2013-06-21T11:38:00Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"2901bbe (apply: free patch->{def,old,new}_name fields, 2012-03-21)\ncleaned up the memory management of filenames in the patches, but\nforgot that find_name_traditional() can return NULL as a way of saying\n\"I couldn't find a name\".\n\nThat NULL unfortunately gets passed into xstrdup() next, resulting in\na segfault.  Use null_strdup() so as to safely propagate the null,\nwhich will let us emit the correct error message.\n\nReported-by: DevHC on #git\nSigned-off-by: Thomas Rast <trast@inf.ethz.ch>\n---\n builtin/apply.c         |  2 +-\n t/t4111-apply-subdir.sh | 14 ++++++++++++++\n 2 files changed, 15 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex faf8e30..0e9b631 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -906,7 +906,7 @@ static void parse_traditional_patch(const char *first, const char *second, struc\n \t\t\tpatch->old_name = name;\n \t\t} else {\n \t\t\tpatch->old_name = name;\n-\t\t\tpatch->new_name = xstrdup(name);\n+\t\t\tpatch->new_name = null_strdup(name);\n \t\t}\n \t}\n \tif (!name)\ndiff --git a/t/t4111-apply-subdir.sh b/t/t4111-apply-subdir.sh\nindex 7c39843..1618a6d 100755\n--- a/t/t4111-apply-subdir.sh\n+++ b/t/t4111-apply-subdir.sh\n@@ -86,6 +86,20 @@ test_expect_success 'apply --index from subdir of toplevel' '\n \ttest_cmp expected sub/dir/file\n '\n \n+test_expect_success 'apply half-broken patch from subdir of toplevel' '\n+\t(\n+\t\tcd sub/dir &&\n+\t\ttest_must_fail git apply <<-EOF\n+\t\t--- sub/dir/file\n+\t\t+++ sub/dir/file\n+\t\t@@ -1,0 +1,0 @@\n+\t\t--- file_in_root\n+\t\t+++ file_in_root\n+\t\t@@ -1,0 +1,0 @@\n+\t\tEOF\n+\t)\n+'\n+\n test_expect_success 'apply from .git dir' '\n \tcp postimage expected &&\n \tcp preimage .git/file &&\n-- \n1.8.3.1.664.gae9f72a\n"}]}