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

Re: [PATCH v2] gpg-interface: trim CR from ssh-keygen

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jan 4, 2022, 03:06 UTC
Message-ID
<CAPig+cR93GyN53JoZbaiROrNtzGjiet7eTPQOk-26G+mB0KaCA@mail.gmail.com>
In-Reply-To
<xmqqmtkcguvm.fsf@gitster.g>
On Mon, Jan 3, 2022 at 8:19 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > On Mon, Jan 3, 2022 at 6:34 PM Junio C Hamano <gitster@pobox.com> wrote:
> >> Eric Sunshine <sunshine@sunshineco.com> writes:
> >> > On Mon, Jan 3, 2022 at 9:24 AM Fabian Stelzer <fs@gigacodes.de> wrote:
> >> >> -                       trust_size = strcspn(line, "\n");
> >> >> +                       trust_size = strcspn(line, "\n"); /* truncate at LF */
> >> >> +                       if (trust_size && trust_size != strlen(line) &&
> >> >> +                           line[trust_size - 1] == '\r')
> >> >> +                               trust_size--; /* the LF was part of CRLF at the end */
> >> >
> >> > I may be misunderstanding, but isn't the strlen() unnecessary?
> >> >
> >> >     if (trust_size && line[trust_size] &&
> >> >         line[trust_size - 1] == '\r')
> >> >             trust_size--;
> >>
> >> That changes behaviour when "line" has more than one lines in it.
> >> strcspn() finds the first LF, and the posted patch ignores CRLF not
> >> at the end of line[].  Your variant feels more correct if the
> >> objective is to find the end of the first line (regardless of the
> >> choice of the end-of-line convention, either LF or CRLF) and omit
> >> the line terminator.
> >
> > Okay, that makes sense if that's the intention of the patch. Perhaps
> > the commit message should mention that `line` might contain multiple
> > lines and that it's only interested in the very last LF (unless it's
> > already obvious to everyone else, even though it wasn't to me).
>
> I do not think that is the case.  strcspn(line, "\n") will stop at
> the first one, so unless it is guaranteed that "line" has only one
> line in it, the patch as posted is not correct.  Your variant
> without strlen() feels more correct, as I said.

Okay, sorry for my unclear thinking. The existing code (before this patch) does indeed seem to be interested only in the first line of `line`, in which case I agree that the patch's use of strlen() does not appear to be correct if `line` could ever contain more than one line.

Previous: Junio C HamanoNext: Fabian Stelzer
Message 13 of 30 in “gpg-interface: trim CR from ssh-keygen -Y find-principals”
  1. gpg-interface: trim CR from ssh-keygen -Y find-principalsJohannes Schindelin via GitGitGadget, Dec 3, 2021
  2. Fabian StelzerDec 3, 2021
  3. Jeff KingDec 3, 2021
  4. Fabian StelzerDec 4, 2021
  5. Junio C HamanoDec 5, 2021
  6. Damien MillerDec 5, 2021
  7. Fabian StelzerDec 6, 2021
  8. gpg-interface: trim CR from ssh-keygenFabian Stelzer, Jan 3, 2022
  9. Eric SunshineJan 3, 2022
  10. Junio C HamanoJan 3, 2022
  11. Eric SunshineJan 4, 2022
  12. Junio C HamanoJan 4, 2022
  13. Eric SunshineJan 4, 2022
  14. Fabian StelzerJan 4, 2022
  15. Junio C HamanoJan 4, 2022
  16. Eric SunshineJan 5, 2022
  17. Fabian StelzerJan 5, 2022
  18. Junio C HamanoJan 5, 2022
  19. Fabian StelzerJan 6, 2022
  20. Junio C HamanoJan 6, 2022
  21. Eric SunshineJan 9, 2022
  22. Fabian StelzerJan 10, 2022
  23. gpg-interface: trim CR from ssh-keygenFabian Stelzer, Jan 7, 2022
  24. Eric SunshineJan 9, 2022
  25. Fabian StelzerJan 10, 2022
  26. Junio C HamanoJan 10, 2022
  27. Junio C HamanoJan 10, 2022
  28. Fabian StelzerDec 9, 2021
  29. Fabian StelzerDec 9, 2021
  30. Fabian StelzerDec 30, 2021

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.