diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-10-11 12:43:08 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-10-11 12:43:08 +0200 |
commit | 6562cdda5073ac96f7f04324fd47c95a196957f2 (patch) | |
tree | af5360cc7788ac5a0f69bc011497f045530c1cda | |
parent | 6956a9547702e629915e3818b3fb48704052ac3f (diff) | |
download | libgit2-6562cdda5073ac96f7f04324fd47c95a196957f2.tar.gz |
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`.
-rw-r--r-- | src/object.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/object.c b/src/object.c index c1f3ea919..87a8d1aae 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; |