From b7994af0f92e6cf150544aebe3c3fc526faaf2c3 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 17 Apr 2015 10:52:48 -0400 Subject: type_from_string_gently: make sure length matches When commit fe8e3b7 refactored type_from_string to allow input that was not NUL-terminated, it switched to using strncmp instead of strcmp. But this means we check only the first "len" bytes of the strings, and ignore any remaining bytes in the object_type_string. We should make sure that it is also "len" bytes, or else we would accept "comm" as "commit", and so forth. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'object.c') diff --git a/object.c b/object.c index aedac243f..91bdde253 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) -- cgit v1.2.1