Skip to content

Commit 1156097

Browse files
committed
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
2 parents b9032b2 + b7994af commit 1156097

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

object.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
4141
len = strlen(str);
4242

4343
for (i = 1; i < ARRAY_SIZE(object_type_strings); i++)
44-
if (!strncmp(str, object_type_strings[i], len))
44+
if (!strncmp(str, object_type_strings[i], len) &&
45+
object_type_strings[i][len] == '\0')
4546
return i;
4647

4748
if (gentle)

t/t1007-hash-object.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,12 @@ test_expect_success 'corrupt tag' '
201201
test_must_fail git hash-object -t tag --stdin </dev/null
202202
'
203203

204+
test_expect_success 'hash-object complains about bogus type name' '
205+
test_must_fail git hash-object -t bogus --stdin </dev/null
206+
'
207+
208+
test_expect_success 'hash-object complains about truncated type name' '
209+
test_must_fail git hash-object -t bl --stdin </dev/null
210+
'
211+
204212
test_done

0 commit comments

Comments
 (0)