git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] tag: fix sign_buffer() call to create a signed tag

From
Jeff King <peff@peff.net>
Date
Feb 8, 2024, 00:47 UTC
Message-ID
<20240208004757.GA1059751@coredump.intra.peff.net>
In-Reply-To
<xmqq4jek9ko1.fsf@gitster.g>
On Wed, Feb 07, 2024 at 10:46:54AM -0800, Junio C Hamano wrote:
Show 20 quoted lines
> 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>
> ---
> 
>  * We alternatively could fix individual sign_buffer() backend that
>    signals an error with a positive value (sign_buffer_ssh() in this
>    case) to return a negative value, but this would hopefully be
>    more future-proof.

FWIW, I would have gone the other way, and fixed sign_buffer_ssh(). Your solution here is future-proofing the tag code against other sign_buffer_*() functions behaving like ssh. But it is also leaving other sign_buffer() callers to introduce the same bug.

Your documentation change at least makes that less likely. But given how much of our code uses the "negative is error" convention, I wouldn't be surprised to see it happen anyway.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 6 in “tag: fix sign_buffer() call to create a signed tag”
  1. tag: fix sign_buffer() call to create a signed tagJunio C Hamano, Feb 7, 2024
  2. Jeff KingFeb 8, 2024
  3. Junio C HamanoFeb 8, 2024
  4. Junio C HamanoFeb 8, 2024
  5. Jeff KingFeb 8, 2024
  6. Jeff KingFeb 8, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.