All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Fabian Stelzer <fs@gigacodes.de>
Cc: git@vger.kernel.org, Pedro Martelletto <pedro@yubico.com>,
	Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH v3] gpg-interface: trim CR from ssh-keygen
Date: Sun, 9 Jan 2022 16:37:49 -0500	[thread overview]
Message-ID: <YdtVrT4gBvnXfNr6@flurp.local> (raw)
In-Reply-To: <20220107090735.580225-1-fs@gigacodes.de>

On Fri, Jan 07, 2022 at 10:07:35AM +0100, Fabian Stelzer wrote:
> We need to trim \r from the output of 'ssh-keygen -Y find-principals' on
> Windows, or we end up calling 'ssh-keygen -Y verify' with a bogus signer
> identity. ssh-keygen.c:2841 contains a call to puts(3), which confirms
> this hypothesis. Signature verification passes with the fix.
>
> Helped-by: Pedro Martelletto <pedro@yubico.com>
> Signed-off-by: Fabian Stelzer <fs@gigacodes.de>

Should this also have a "Helped-by: Junio" since this code was heavily
inspired by his suggestion[1]?

[1]: https://lore.kernel.org/git/xmqqo84rcn3j.fsf@gitster.g/

> ---
> diff --git a/gpg-interface.c b/gpg-interface.c
> @@ -502,15 +501,30 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,
> +		const char *next;
> +		for (line = ssh_principals_out.buf;
> +		     *line;
> +		     line = next) {
> +			const char *end_of_text;
> +
> +			next = end_of_text = strchrnul(line, '\n');
> +
> +			 /* Did we find a LF, and did we have CR before it? */
> +			if (*end_of_text &&
> +			    line < end_of_text &&
> +			    end_of_text[-1] == '\r')
> +				end_of_text--;
> +
> +			/* Unless we hit NUL, skip over the LF we found */
> +			if (*next)
> +				next++;
> +
> +			/* Not all lines are data.  Skip empty ones */
> +			if (line == end_of_text)
> +				continue;
> +
> +			/* We now know we have an non-empty line. Process it */
> +			principal = xmemdupz(line, end_of_text - line);

Considering that this code makes a copy of the line _anyhow_ which it
assigns to `principal`, it still seems like it would be simpler and
far easier to understand at-a-glance to instead take advantage of one
of the existing string-splitting functions. For instance, something
like this:

    struct strbuf **line, **to_free;
    line = to_free = strbuf_split(&ssh_principals_out, '\n');
    for (; *line; line++) {
        strbuf_trim_trailing_newline(*line);
        if (!(*line)->len)
            continue;
        principal = (*line)->buf;

keeping in mind that strbuf_trim_trailing_newline() takes care of
CR/LF, and with appropriate cleanup at the end of the loop:

        strbuf_list_free(to_free);

(and removal of `FREE_AND_NULL(principal)` which is no longer needed).

Something similar can be done with string_list_split(), as well.

  reply	other threads:[~2022-01-09 21:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03 13:31 [PATCH] gpg-interface: trim CR from ssh-keygen -Y find-principals Johannes Schindelin via GitGitGadget
2021-12-03 14:18 ` Fabian Stelzer
2021-12-03 15:58 ` Jeff King
2021-12-04 13:11   ` Fabian Stelzer
2021-12-05  5:50     ` Junio C Hamano
     [not found]       ` <CABPYr=y+sDDko9zPxQTOM6Tz4E7CafH7hJc6oB1zv7XYA9KH1A@mail.gmail.com>
2021-12-09 16:33         ` Fabian Stelzer
     [not found]           ` <CABPYr=xfotWvTQK9k1eKHa0kP4SsB=TKKuM0d8cpMb5BtuUZLA@mail.gmail.com>
2021-12-09 17:20             ` Fabian Stelzer
2021-12-30 10:25             ` Fabian Stelzer
2021-12-05 23:06     ` Damien Miller
2021-12-06  8:39       ` Fabian Stelzer
2022-01-03  9:53 ` [PATCH v2] gpg-interface: trim CR from ssh-keygen Fabian Stelzer
2022-01-03 17:17   ` Eric Sunshine
2022-01-03 23:34     ` Junio C Hamano
2022-01-04  0:41       ` Eric Sunshine
2022-01-04  1:19         ` Junio C Hamano
2022-01-04  3:06           ` Eric Sunshine
2022-01-04 12:55             ` Fabian Stelzer
2022-01-04 19:33               ` Junio C Hamano
2022-01-05  7:09                 ` Eric Sunshine
2022-01-05 10:36                   ` Fabian Stelzer
2022-01-05 20:40                     ` Junio C Hamano
2022-01-06 10:26                       ` Fabian Stelzer
2022-01-06 17:50                         ` Junio C Hamano
2022-01-09 20:49                     ` Eric Sunshine
2022-01-10 12:28                       ` Fabian Stelzer
2022-01-07  9:07   ` [PATCH v3] " Fabian Stelzer
2022-01-09 21:37     ` Eric Sunshine [this message]
2022-01-10 12:59       ` Fabian Stelzer
2022-01-10 17:51         ` Junio C Hamano
2022-01-10 17:03       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YdtVrT4gBvnXfNr6@flurp.local \
    --to=sunshine@sunshineco.com \
    --cc=fs@gigacodes.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=pedro@yubico.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.