git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Catch errors when writing an index that contains invalid objects.
  2006-11-13 13:50 [PATCH] test-lib.sh: A command dying due to a signal is an unexpected failure Johannes Sixt
@ 2006-11-13 13:50 ` Johannes Sixt
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Sixt @ 2006-11-13 13:50 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt

From: Johannes Sixt <johannes.sixt@telecom.at>

If git-write-index is called without --missing-ok, it reports invalid
objects that it finds in the index. But without this patch it dies
right away or may run into an infinite loop.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 cache-tree.c     |    2 ++
 t/t0000-basic.sh |   22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/cache-tree.c b/cache-tree.c
index a803262..9b73c86 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -282,6 +282,8 @@ static int update_one(struct cache_tree 
 				    baselen + sublen + 1,
 				    missing_ok,
 				    dryrun);
+		if (subcnt < 0)
+			return subcnt;
 		i += subcnt - 1;
 		sub->used = 1;
 	}
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 2c9bbb5..6aff0b8 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -209,6 +209,28 @@ test_expect_success \
     'validate object ID for a known tree.' \
     'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
 
+cat >badobjects <<EOF
+100644 blob 1000000000000000000000000000000000000000	dir/file1
+100644 blob 2000000000000000000000000000000000000000	dir/file2
+100644 blob 3000000000000000000000000000000000000000	dir/file3
+100644 blob 4000000000000000000000000000000000000000	dir/file4
+100644 blob 5000000000000000000000000000000000000000	dir/file5
+EOF
+
+rm .git/index
+test_expect_success \
+    'put invalid objects into the index.' \
+    'git-update-index --index-info < badobjects'
+
+test_expect_failure \
+    'writing this tree without --missing-ok.' \
+    'git-write-tree'
+
+test_expect_success \
+    'writing this tree with --missing-ok.' \
+    'git-write-tree --missing-ok'
+
+
 ################################################################
 rm .git/index
 test_expect_success \
-- 
1.4.1.rc1.g47e5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] test-lib.sh: A command dying due to a signal is an unexpected failure.
@ 2006-11-13 13:50 Johannes Sixt
  2006-11-13 13:50 ` [PATCH] Catch errors when writing an index that contains invalid objects Johannes Sixt
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Sixt @ 2006-11-13 13:50 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt

From: Johannes Sixt <johannes.sixt@telecom.at>

When test_expect_failure detects that a command failed, it still has to
treat a program that crashed from a signal as unexpected failure.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 t/test-lib.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 07cb706..3895f16 100755
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -129,7 +129,7 @@ test_expect_failure () {
 	error "bug in the test script: not 2 parameters to test-expect-failure"
 	say >&3 "expecting failure: $2"
 	test_run_ "$2"
-	if [ "$?" = 0 -a "$eval_ret" != 0 ]
+	if [ "$?" = 0 -a "$eval_ret" != 0 -a "$eval_ret" -lt 129 ]
 	then
 		test_ok_ "$1"
 	else
-- 
1.4.1.rc1.g47e5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-13 13:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-13 13:50 [PATCH] test-lib.sh: A command dying due to a signal is an unexpected failure Johannes Sixt
2006-11-13 13:50 ` [PATCH] Catch errors when writing an index that contains invalid objects Johannes Sixt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).