]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tag: fix sign_buffer() call to create a signed tag
authorJunio C Hamano <gitster@pobox.com>
Wed, 7 Feb 2024 18:46:54 +0000 (10:46 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Feb 2024 18:47:25 +0000 (10:47 -0800)
The command "git tag -s" internally calls sign_buffer() to make a
cryptographic signature using the chosen backend like GPG and SSH.
The internal helper functions used by "git tag" implementation seem
to use a "negative return values are errors, zero or positive return
values are not" convention, and there are places (e.g., verify_tag()
that calls gpg_verify_tag()) that these internal helper functions
translate return values that signal errors to conform to this
convention, but do_sign() that calls sign_buffer() forgets to do so.

Fix it, so that a failed call to sign_buffer() that can return the
exit status from pipe_command() will not be overlooked.

Reported-by: Sergey Kosukhin <skosukhin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/tag.c
gpg-interface.h

index 3918eacbb57bd9e0d2b90ecbbf6cc07c16fad73b..b28ead06eac90e7b9020640d02b6ea5b81445027 100644 (file)
@@ -176,7 +176,7 @@ static int verify_tag(const char *name, const char *ref UNUSED,
 
 static int do_sign(struct strbuf *buffer)
 {
-       return sign_buffer(buffer, buffer, get_signing_key());
+       return sign_buffer(buffer, buffer, get_signing_key()) ? -1 : 0;
 }
 
 static const char tag_template[] =
index 143cdc1c02d4b31fa08f92fbcae1691c80d2c2d6..7cd98161f7f21b5946daa6834617d4876745119f 100644 (file)
@@ -66,7 +66,7 @@ size_t parse_signed_buffer(const char *buf, size_t size);
  * Create a detached signature for the contents of "buffer" and append
  * it after "signature"; "buffer" and "signature" can be the same
  * strbuf instance, which would cause the detached signature appended
- * at the end.
+ * at the end.  Returns 0 on success, non-zero on failure.
  */
 int sign_buffer(struct strbuf *buffer, struct strbuf *signature,
                const char *signing_key);