Commit 4793d91bf3b955dcc0dab2308ff9ebea06504de3

Stefan Sperling 2019-09-22T15:16:33

have got_object_parse_* check for zero-length input

diff --git a/lib/object_parse.c b/lib/object_parse.c
index 8a94189..b6cd712 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -495,6 +495,9 @@ got_object_parse_commit(struct got_commit_object **commit, char *buf,
 	size_t label_len;
 	ssize_t remain = (ssize_t)len;
 
+	if (remain == 0)
+		return got_error(GOT_ERR_BAD_OBJ_DATA);
+
 	*commit = got_object_commit_alloc_partial();
 	if (*commit == NULL)
 		return got_error_from_errno("got_object_commit_alloc_partial");
@@ -724,6 +727,9 @@ got_object_parse_tree(struct got_tree_object **tree, uint8_t *buf, size_t len)
 
 	TAILQ_INIT(&pathlist);
 
+	if (remain == 0)
+		return got_error(GOT_ERR_BAD_OBJ_DATA);
+
 	*tree = calloc(1, sizeof(**tree));
 	if (*tree == NULL)
 		return got_error_from_errno("calloc");
@@ -789,6 +795,9 @@ got_object_parse_tag(struct got_tag_object **tag, uint8_t *buf, size_t len)
 	char *s = buf;
 	size_t label_len;
 
+	if (remain == 0)
+		return got_error(GOT_ERR_BAD_OBJ_DATA);
+
 	*tag = calloc(1, sizeof(**tag));
 	if (*tag == NULL)
 		return got_error_from_errno("calloc");