Commit 8914529dc5d3a0f394dbcc3e90fd63ba329bb824

Stefan Sperling 2019-04-13T18:55:07

make parse_tree_entry() require a mode field

diff --git a/lib/object_parse.c b/lib/object_parse.c
index 20bd1a1..0fe7cbd 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -595,7 +595,7 @@ static const struct got_error *
 parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
     size_t maxlen)
 {
-	char *p = buf, *space;
+	char *p, *space;
 	const struct got_error *err = NULL;
 
 	*te = got_alloc_tree_entry_partial();
@@ -610,14 +610,15 @@ parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
 	}
 
 	space = memchr(buf, ' ', *elen);
-	if (space == NULL) {
+	if (space == NULL || space <= buf) {
 		err = got_error(GOT_ERR_BAD_OBJ_DATA);
 		free(*te);
 		*te = NULL;
 		return err;
 	}
 	(*te)->mode = 0;
-	while (*p != ' ') {
+	p = buf;
+	while (p < space) {
 		if (*p < '0' && *p > '7') {
 			err = got_error(GOT_ERR_BAD_OBJ_DATA);
 			goto done;