Skip to content

Commit d2dadfe

Browse files
committed
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 <[email protected]>
1 parent 544ddb0 commit d2dadfe

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

builtin-log.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,13 @@ int cmd_show(int argc, const char **argv, const char *prefix)
356356
t->tag,
357357
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
358358
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;
360366
i--;
361367
break;
362368
}

t/t7007-show.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)