Anonymous avatar Anonymous committed 3b44f15

connect.c: check the commit buffer boundary while parsing.

Signed-off-by: Junio C Hamano <junkio@cox.net>;

Comments (0)

Files changed (1)

 
 int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
 {
+	char *tail = buffer;
 	char *bufptr = buffer;
 	unsigned char parent[20];
 	struct commit_list **pptr;
 	if (item->object.parsed)
 		return 0;
 	item->object.parsed = 1;
-	if (memcmp(bufptr, "tree ", 5))
+	tail += size;
+	if (tail <= bufptr + 5 || memcmp(bufptr, "tree ", 5))
 		return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
-	if (get_sha1_hex(bufptr + 5, parent) < 0)
+	if (tail <= bufptr + 45 || get_sha1_hex(bufptr + 5, parent) < 0)
 		return error("bad tree pointer in commit %s",
 			     sha1_to_hex(item->object.sha1));
 	item->tree = lookup_tree(parent);
 	pptr = &item->parents;
 
 	graft = lookup_commit_graft(item->object.sha1);
-	while (!memcmp(bufptr, "parent ", 7)) {
+	while (bufptr + 48 < tail && !memcmp(bufptr, "parent ", 7)) {
 		struct commit *new_parent;
 
-		if (get_sha1_hex(bufptr + 7, parent) || bufptr[47] != '\n')
+		if (tail <= bufptr + 48 ||
+		    get_sha1_hex(bufptr + 7, parent) ||
+		    bufptr[47] != '\n')
 			return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
 		bufptr += 48;
 		if (graft)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.