{"thread":{"id":"37443","subject":"[PATCH v2 2/2] fast-import: fix segfault in store_tree()","startedAt":"2014-08-29T11:53:35Z","lastAt":"2014-08-29T11:53:37Z","messageCount":3,"participants":["Maxim Bublis"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"248543","messageId":"1409313217-23198-1-git-send-email-satori@yandex-team.ru","threadId":"37443","inReplyTo":null,"subject":"[PATCH v2 0/2] fast-import: fix segfault and filedelete tests","fromName":"Maxim Bublis","fromEmail":"satori@yandex-team.ru","sentAt":"2014-08-29T11:53:35Z","receivedAt":"2014-08-29T11:53:35Z","isPatch":true,"sender":{"key":"satori@yandex-team.ru","avatar":null},"body":"Removing root tree with filedelete command would lead to segmentation fault\nin store_tree(). First patch from patch series adds filedelete command\ntests with test case to show incorrect behaviour on filedelete root operation.\nSecond one fixes bug by sanity check and load_tree() usage.\n\nMaxim Bublis (2):\n  t9300: test filedelete command\n  fast-import: fix segfault in store_tree()\n\n fast-import.c          |   6 ++-\n t/t9300-fast-import.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 109 insertions(+), 1 deletion(-)\n\n-- \n1.8.5.2 (Apple Git-48)\n"},{"id":"248542","messageId":"1409313217-23198-2-git-send-email-satori@yandex-team.ru","threadId":"37443","inReplyTo":"1409313217-23198-1-git-send-email-satori@yandex-team.ru","subject":"[PATCH v2 1/2] t9300: test filedelete command","fromName":"Maxim Bublis","fromEmail":"satori@yandex-team.ru","sentAt":"2014-08-29T11:53:36Z","receivedAt":"2014-08-29T11:53:36Z","isPatch":true,"sender":{"key":"satori@yandex-team.ru","avatar":null},"body":"Add new fast-import test series for filedelete command.\n\nSigned-off-by: Maxim Bublis <satori@yandex-team.ru>\n---\n t/t9300-fast-import.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 104 insertions(+)\n\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex 5fc9ef2..9cf5e45 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -3017,4 +3017,108 @@ test_expect_success 'T: empty reset doesnt delete branch' '\n \tgit rev-parse --verify refs/heads/not-to-delete\n '\n \n+###\n+### series U (filedelete)\n+###\n+\n+cat >input <<INPUT_END\n+commit refs/heads/U\n+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n+data <<COMMIT\n+test setup\n+COMMIT\n+M 100644 inline hello.c\n+data <<BLOB\n+blob 1\n+BLOB\n+M 100644 inline good/night.txt\n+data <<BLOB\n+sleep well\n+BLOB\n+M 100644 inline good/bye.txt\n+data <<BLOB\n+au revoir\n+BLOB\n+\n+INPUT_END\n+\n+test_expect_success 'U: initialize for U tests' '\n+\tgit fast-import <input\n+'\n+\n+cat >input <<INPUT_END\n+commit refs/heads/U\n+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n+data <<COMMIT\n+delete good/night.txt\n+COMMIT\n+from refs/heads/U^0\n+D good/night.txt\n+\n+INPUT_END\n+\n+test_expect_success 'U: filedelete file succeeds' '\n+\tgit fast-import <input\n+'\n+\n+cat >expect <<EOF\n+:100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D\tgood/night.txt\n+EOF\n+\n+git diff-tree -M -r U^1 U >actual\n+\n+test_expect_success 'U: validate file delete result' '\n+\tcompare_diff_raw expect actual\n+'\n+\n+cat >input <<INPUT_END\n+commit refs/heads/U\n+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n+data <<COMMIT\n+delete good dir\n+COMMIT\n+from refs/heads/U^0\n+D good\n+\n+INPUT_END\n+\n+test_expect_success 'U: filedelete directory succeeds' '\n+\tgit fast-import <input\n+'\n+\n+cat >expect <<EOF\n+:100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D\tgood/bye.txt\n+EOF\n+\n+git diff-tree -M -r U^1 U >actual\n+\n+test_expect_success 'U: validate directory delete result' '\n+\tcompare_diff_raw expect actual\n+'\n+\n+cat >input <<INPUT_END\n+commit refs/heads/U\n+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n+data <<COMMIT\n+must succeed\n+COMMIT\n+from refs/heads/U^0\n+D \"\"\n+\n+INPUT_END\n+\n+test_expect_failure 'U: filedelete root succeeds' '\n+    git fast-import <input\n+'\n+\n+cat >expect <<EOF\n+:100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D\thello.c\n+EOF\n+\n+git diff-tree -M -r U^1 U >actual\n+\n+test_expect_failure 'U: validate root delete result' '\n+\tcompare_diff_raw expect actual\n+'\n+\n test_done\n-- \n1.8.5.2 (Apple Git-48)\n"},{"id":"248541","messageId":"1409313217-23198-3-git-send-email-satori@yandex-team.ru","threadId":"37443","inReplyTo":"1409313217-23198-1-git-send-email-satori@yandex-team.ru","subject":"[PATCH v2 2/2] fast-import: fix segfault in store_tree()","fromName":"Maxim Bublis","fromEmail":"satori@yandex-team.ru","sentAt":"2014-08-29T11:53:37Z","receivedAt":"2014-08-29T11:53:37Z","isPatch":true,"sender":{"key":"satori@yandex-team.ru","avatar":null},"body":"Branch tree is NULLified by filedelete command if we are trying\nto delete root tree. Add sanity check and use load_tree() in that case.\n\nSigned-off-by: Maxim Bublis <satori@yandex-team.ru>\n---\n fast-import.c          | 6 +++++-\n t/t9300-fast-import.sh | 4 ++--\n 2 files changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex d73f58c..e380804 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1419,7 +1419,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)\n \n static void store_tree(struct tree_entry *root)\n {\n-\tstruct tree_content *t = root->tree;\n+\tstruct tree_content *t;\n \tunsigned int i, j, del;\n \tstruct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };\n \tstruct object_entry *le = NULL;\n@@ -1427,6 +1427,10 @@ static void store_tree(struct tree_entry *root)\n \tif (!is_null_sha1(root->versions[1].sha1))\n \t\treturn;\n \n+\tif (!root->tree)\n+\t\tload_tree(root);\n+\tt = root->tree;\n+\n \tfor (i = 0; i < t->entry_count; i++) {\n \t\tif (t->entries[i]->tree)\n \t\t\tstore_tree(t->entries[i]);\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex 9cf5e45..d400442 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -3107,7 +3107,7 @@ D \"\"\n \n INPUT_END\n \n-test_expect_failure 'U: filedelete root succeeds' '\n+test_expect_success 'U: filedelete root succeeds' '\n     git fast-import <input\n '\n \n@@ -3117,7 +3117,7 @@ EOF\n \n git diff-tree -M -r U^1 U >actual\n \n-test_expect_failure 'U: validate root delete result' '\n+test_expect_success 'U: validate root delete result' '\n \tcompare_diff_raw expect actual\n '\n \n-- \n1.8.5.2 (Apple Git-48)\n"}]}