Merge branch 'jk/type-from-string-gently' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 13 May 2015 21:05:54 +0000 (14:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 May 2015 21:05:54 +0000 (14:05 -0700)
"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

object.c
t/t1007-hash-object.sh
index 23d6c9671904cfe273fc16de8a4d2db56b91c3b4..980ac5fcdfa7654667c9902aa56407f1ce7053ba 100644 (file)
--- 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)
index f83df8eb8b143086df00e163a30ad96e43404001..ebb3a69c8cd68a51184f809357bb60cb7b35f928 100755 (executable)
@@ -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