Skip to content

Commit ade0d9c

Browse files
committed
commit: avoid possible use-after-free
When extracting a commit's signature, we first free the object and only afterwards put its signature contents into the result buffer. This works in most cases - the free'd object will normally be cached anyway, so we only end up decrementing its reference count without actually freeing its contents. But in some more exotic setups, where caching is disabled, this can definitly be a problem, as we might be the only instance currently holding a reference to this object. Fix this issue by first extracting the contents and freeing the object afterwards only.
1 parent dc851d9 commit ade0d9c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,9 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
766766
if (git_buf_oom(signature))
767767
goto oom;
768768

769+
error = git_buf_puts(signed_data, eol+1);
769770
git_odb_object_free(obj);
770-
return git_buf_puts(signed_data, eol+1);
771+
return error;
771772
}
772773

773774
giterr_set(GITERR_OBJECT, "this commit is not signed");

0 commit comments

Comments
 (0)