Commit 6562cdda5073ac96f7f04324fd47c95a196957f2

Patrick Steinhardt 2018-10-11T12:43:08

object: properly propagate errors on parsing failures When failing to parse a raw object fromits data, we free the partially parsed object but then fail to propagate the error to the caller. This may lead callers to operate on objects with invalid memory, which will sooner or later cause the program to segfault. Fix the issue by passing up the error code returned by `parse_raw`.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/src/object.c b/src/object.c
index c1f3ea9..87a8d1a 100644
--- a/src/object.c
+++ b/src/object.c
@@ -91,8 +91,10 @@ int git_object__from_raw(
 	def = &git_objects_table[type];
 	assert(def->free && def->parse_raw);
 
-	if ((error = def->parse_raw(object, data, size)) < 0)
+	if ((error = def->parse_raw(object, data, size)) < 0) {
 		def->free(object);
+		return error;
+	}
 
 	git_cached_obj_incref(object);
 	*object_out = object;