Commit b9caa1859d9116959a1aafdb8dc3f6578d692459

J. David Ibáñez 2011-09-30T19:50:13

oid: now git_oid_fromstrn checks whether the given string is too short Signed-off-by: J. David Ibáñez <jdavid.ibp@gmail.com>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/oid.c b/src/oid.c
index 1f72274..08e9305 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -36,6 +36,9 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
 	size_t p;
 	int v;
 
+	if (length < 4)
+		return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is too short");
+
 	if (length > GIT_OID_HEXSZ)
 		length = GIT_OID_HEXSZ;