Commit 6562cdda by Patrick Steinhardt

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`.
parent 6956a954
...@@ -91,8 +91,10 @@ int git_object__from_raw( ...@@ -91,8 +91,10 @@ int git_object__from_raw(
def = &git_objects_table[type]; def = &git_objects_table[type];
assert(def->free && def->parse_raw); 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); def->free(object);
return error;
}
git_cached_obj_incref(object); git_cached_obj_incref(object);
*object_out = object; *object_out = object;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment