@matheusbsbs / matheus-bagliano / commits / d2dadfe890
Fork 0

git-show: do not segfault when showing a bad tag

When a tag points at a bad or nonexistent object, we should diagnose the breakage and exit. An earlier commit 4f3dcc2 (Fix 'git show' on signed tag of signed tag of commit, 2008-07-01) lost this check and made it segfault instead; not good. This fixes it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 15, 2008 at 00:36 UTC d2dadfe890b5da6f65fe061a414b6ec67c5efe9c
2 files changed +27 -1
builtin-log.c
+7 -1
@@ -356,7 +356,13 @@ int cmd_show(int argc, const char **argv, const char *prefix)
356 t->tag,
357 diff_get_color_opt(&rev.diffopt, DIFF_RESET));
358 ret = show_object(o->sha1, 1, &rev);
359 - objects[i].item = parse_object(t->tagged->sha1);
359 + if (ret)
360 + break;
361 + o = parse_object(t->tagged->sha1);
362 + if (!o)
363 + ret = error("Could not read object %s",
364 + sha1_to_hex(t->tagged->sha1));
365 + objects[i].item = o;
366 i--;
367 break;
368 }
t/t7007-show.sh new
+20
@@ -0,0 +1,20 @@
1 +#!/bin/sh
2 +
3 +test_description='git show'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + echo hello world >foo &&
9 + H=$(git hash-object -w foo) &&
10 + git tag -a foo-tag -m "Tags $H" $H &&
11 + HH=$(expr "$H" : "\(..\)") &&
12 + H38=$(expr "$H" : "..\(.*\)") &&
13 + rm -f .git/objects/$HH/$H38
14 +'
15 +
16 +test_expect_success 'showing a tag that point at a missing object' '
17 + test_must_fail git --no-pager show foo-tag
18 +'
19 +
20 +test_done