summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-05-05 21:00:29 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-05-05 21:00:29 -0700
commit1156097296e584bd05a9feeb14cb9fcf98093dc8 (patch)
tree8ab64f854692cef634e05fd2b4ff706c927ffa10
parentMerge branch 'sb/test-bitmap-free-at-end' (diff)
parenttype_from_string_gently: make sure length matches (diff)
downloadtgif-1156097296e584bd05a9feeb14cb9fcf98093dc8.tar.xz
Merge branch 'jk/type-from-string-gently'
"git cat-file bl $blob" failed to barf even though there is no object type that is "bl". * jk/type-from-string-gently: type_from_string_gently: make sure length matches
-rw-r--r--object.c3
-rwxr-xr-xt/t1007-hash-object.sh8
2 files changed, 10 insertions, 1 deletions
diff --git a/object.c b/object.c
index 23d6c96719..980ac5fcdf 100644
--- a/object.c
+++ b/object.c
@@ -41,7 +41,8 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
len = strlen(str);
for (i = 1; i < ARRAY_SIZE(object_type_strings); i++)
- if (!strncmp(str, object_type_strings[i], len))
+ if (!strncmp(str, object_type_strings[i], len) &&
+ object_type_strings[i][len] == '\0')
return i;
if (gentle)
diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
index f83df8eb8b..ebb3a69c8c 100755
--- a/t/t1007-hash-object.sh
+++ b/t/t1007-hash-object.sh
@@ -201,4 +201,12 @@ test_expect_success 'corrupt tag' '
test_must_fail git hash-object -t tag --stdin </dev/null
'
+test_expect_success 'hash-object complains about bogus type name' '
+ test_must_fail git hash-object -t bogus --stdin </dev/null
+'
+
+test_expect_success 'hash-object complains about truncated type name' '
+ test_must_fail git hash-object -t bl --stdin </dev/null
+'
+
test_done