threads / patch / 37443

v2, 2 partsfast-import: fix segfault in store_tree()

Subject: [PATCH v2 2/2] fast-import: fix segfault in store_tree()

## tl;dr

3 messages between Aug 29, 2014 and Aug 29, 2014. Diffs are folded; open one to read it.

replies: 2people: 1as markdown or json

Maxim Bublis· Aug 29, 2014, 11:53 UTC · lore

[PATCH v2 0/2] fast-import: fix segfault and filedelete tests

Removing root tree with filedelete command would lead to segmentation fault in store_tree(). First patch from patch series adds filedelete command tests with test case to show incorrect behaviour on filedelete root operation. Second one fixes bug by sanity check and load_tree() usage.

Maxim Bublis (2):
  t9300: test filedelete command
  fast-import: fix segfault in store_tree()
 fast-import.c          |   6 ++-
 t/t9300-fast-import.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+), 1 deletion(-)
-- 
1.8.5.2 (Apple Git-48)
Maxim Bublis· Aug 29, 2014, 11:53 UTC · re: Maxim Bublis · lore

[PATCH v2 1/2] t9300: test filedelete command

Add new fast-import test series for filedelete command.
Signed-off-by: Maxim Bublis <satori@yandex-team.ru>
---
 t/t9300-fast-import.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
Show changes to t/t9300-fast-import.sh +104 −0
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 5fc9ef2..9cf5e45 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -3017,4 +3017,108 @@ test_expect_success 'T: empty reset doesnt delete branch' '
 	git rev-parse --verify refs/heads/not-to-delete
 '
 
+###
+### series U (filedelete)
+###
+
+cat >input <<INPUT_END
+commit refs/heads/U
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+test setup
+COMMIT
+M 100644 inline hello.c
+data <<BLOB
+blob 1
+BLOB
+M 100644 inline good/night.txt
+data <<BLOB
+sleep well
+BLOB
+M 100644 inline good/bye.txt
+data <<BLOB
+au revoir
+BLOB
+
+INPUT_END
+
+test_expect_success 'U: initialize for U tests' '
+	git fast-import <input
+'
+
+cat >input <<INPUT_END
+commit refs/heads/U
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+delete good/night.txt
+COMMIT
+from refs/heads/U^0
+D good/night.txt
+
+INPUT_END
+
+test_expect_success 'U: filedelete file succeeds' '
+	git fast-import <input
+'
+
+cat >expect <<EOF
+:100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D	good/night.txt
+EOF
+
+git diff-tree -M -r U^1 U >actual
+
+test_expect_success 'U: validate file delete result' '
+	compare_diff_raw expect actual
+'
+
+cat >input <<INPUT_END
+commit refs/heads/U
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+delete good dir
+COMMIT
+from refs/heads/U^0
+D good
+
+INPUT_END
+
+test_expect_success 'U: filedelete directory succeeds' '
+	git fast-import <input
+'
+
+cat >expect <<EOF
+:100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D	good/bye.txt
+EOF
+
+git diff-tree -M -r U^1 U >actual
+
+test_expect_success 'U: validate directory delete result' '
+	compare_diff_raw expect actual
+'
+
+cat >input <<INPUT_END
+commit refs/heads/U
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+must succeed
+COMMIT
+from refs/heads/U^0
+D ""
+
+INPUT_END
+
+test_expect_failure 'U: filedelete root succeeds' '
+    git fast-import <input
+'
+
+cat >expect <<EOF
+:100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D	hello.c
+EOF
+
+git diff-tree -M -r U^1 U >actual
+
+test_expect_failure 'U: validate root delete result' '
+	compare_diff_raw expect actual
+'
+
 test_done
-- 
1.8.5.2 (Apple Git-48)
Maxim Bublis· Aug 29, 2014, 11:53 UTC · re: Maxim Bublis · lore

Branch tree is NULLified by filedelete command if we are trying to delete root tree. Add sanity check and use load_tree() in that case.

Signed-off-by: Maxim Bublis <satori@yandex-team.ru>
---
 fast-import.c          | 6 +++++-
 t/t9300-fast-import.sh | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)
Show changes to 2 files +7 −3

fast-import.c, t/t9300-fast-import.sh

diff --git a/fast-import.c b/fast-import.c
index d73f58c..e380804 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1419,7 +1419,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)
 
 static void store_tree(struct tree_entry *root)
 {
-	struct tree_content *t = root->tree;
+	struct tree_content *t;
 	unsigned int i, j, del;
 	struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };
 	struct object_entry *le = NULL;
@@ -1427,6 +1427,10 @@ static void store_tree(struct tree_entry *root)
 	if (!is_null_sha1(root->versions[1].sha1))
 		return;
 
+	if (!root->tree)
+		load_tree(root);
+	t = root->tree;
+
 	for (i = 0; i < t->entry_count; i++) {
 		if (t->entries[i]->tree)
 			store_tree(t->entries[i]);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 9cf5e45..d400442 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -3107,7 +3107,7 @@ D ""
 
 INPUT_END
 
-test_expect_failure 'U: filedelete root succeeds' '
+test_expect_success 'U: filedelete root succeeds' '
     git fast-import <input
 '
 
@@ -3117,7 +3117,7 @@ EOF
 
 git diff-tree -M -r U^1 U >actual
 
-test_expect_failure 'U: validate root delete result' '
+test_expect_success 'U: validate root delete result' '
 	compare_diff_raw expect actual
 '
 
-- 
1.8.5.2 (Apple Git-48)

← back to recent threads