Skip to content

Commit a59545d

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#4122 from pks-t/pks/signature-dbl-free
Signature cleanups
2 parents c576d4f + ade0d9c commit a59545d

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

include/git2/commit.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
255255
/**
256256
* Get an arbitrary header field
257257
*
258-
* @param out the buffer to fill
258+
* @param out the buffer to fill; existing content will be
259+
* overwritten
259260
* @param commit the commit to look in
260261
* @param field the header field to return
261262
* @return 0 on succeess, GIT_ENOTFOUND if the field does not exist,
@@ -270,8 +271,10 @@ GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit,
270271
* `GITERR_INVALID`. If the commit does not have a signature, the
271272
* error class will be `GITERR_OBJECT`.
272273
*
273-
* @param signature the signature block
274-
* @param signed_data signed data; this is the commit contents minus the signature block
274+
* @param signature the signature block; existing content will be
275+
* overwritten
276+
* @param signed_data signed data; this is the commit contents minus the signature block;
277+
* existing content will be overwritten
275278
* @param repo the repository in which the commit exists
276279
* @param commit_id the commit from which to extract the data
277280
* @param field the name of the header field containing the signature

src/buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ extern int git_buf_try_grow(
6666
* library, when providing git_buf's, may wish to provide a NULL ptr for
6767
* ease of handling. The buffer routines, however, expect a non-NULL ptr
6868
* always. This helper method simply handles NULL input, converting to a
69-
* git_buf__initbuf.
69+
* git_buf__initbuf. If a buffer with a non-NULL ptr is passed in, this method
70+
* assures that the buffer is '\0'-terminated.
7071
*/
7172
extern void git_buf_sanitize(git_buf *buf);
7273

src/commit.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
642642
{
643643
const char *eol, *buf = commit->raw_header;
644644

645-
git_buf_sanitize(out);
645+
git_buf_clear(out);
646646

647647
while ((eol = strchr(buf, '\n'))) {
648648
/* We can skip continuations here */
@@ -706,8 +706,8 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
706706
const char *h, *eol;
707707
int error;
708708

709-
git_buf_sanitize(signature);
710-
git_buf_sanitize(signed_data);
709+
git_buf_clear(signature);
710+
git_buf_clear(signed_data);
711711

712712
if (!field)
713713
field = "gpgsig";
@@ -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)