Skip to content

Commit 6562cdd

Browse files
committed
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 parent 6956a95 commit 6562cdd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/object.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ int git_object__from_raw(
9191
def = &git_objects_table[type];
9292
assert(def->free && def->parse_raw);
9393

94-
if ((error = def->parse_raw(object, data, size)) < 0)
94+
if ((error = def->parse_raw(object, data, size)) < 0) {
9595
def->free(object);
96+
return error;
97+
}
9698

9799
git_cached_obj_incref(object);
98100
*object_out = object;

0 commit comments

Comments
 (0)