Skip to content

Commit

Permalink
Merge branch 'jk/type-from-string-gently'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed May 6, 2015
2 parents b9032b2 + b7994af commit 1156097
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions t/t1007-hash-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1156097

Please sign in to comment.