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

Re: [PATCH v2 1/2] object-name: fix resolution of object names containing curly braces

From
Elijah Newren <newren@gmail.com>
Date
Jan 4, 2025, 18:54 UTC
Message-ID
<CABPp-BHACrtkMJAKpOsPw5bw8Fvnhe_wFLMNntsPifmg8yomfw@mail.gmail.com>
In-Reply-To
<xmqq34hy4hii.fsf@gitster.g>
On Sat, Jan 4, 2025 at 9:26 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> >       for (cp = name, bracket_depth = 0; *cp; cp++) {
> > -             if (*cp == '{')
> > +             if (*(cp+1) == '{' && (*cp == '@' || *cp == '^')) {
> > +                     cp++;
> >                       bracket_depth++;
>
> Checking cp[1] before even knowing if cp[0] is the end of the string
> (hence cp[1] is an out of bounds access) smells fishy.

We checked *cp in the loop already, so we know cp[0] != '\0'. Combined with the fact that this is a NUL-terminated string, we therefore also know that cp[1] is not an out-of-bounds access.

> If it were
> something like ...
>
>         if (cp[0] && strchr("@^", cp[0]) && cp[1] == '{')
Since we know cp[0] != '\0' already, couldn't this be simplified to
    if (strchr("@^", *cp) && cp[1] == '{')
?
I do like this form better though, yes.
Show 5 quoted lines
> ... it may be a bit more palatable, perhaps?  At least writing it
> this way we can easily scale when we find the third character we
> need to special case, hopefully, but again, I do prefer if we can
> find a solution that does not have such an intimate knowledge about
> "@^", which I just failed to do here X-<.

Yeah, I have failed to come up with an alternative as well. If I and others can't come up with something better in a few days, I'll resubmit with the above change and a comment in the commit message that we'd prefer something better but were unable to come up with anything.

Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 25 in “object-name: fix resolution of object names containing curly braces”
  1. object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 1, 2025
  2. Junio C HamanoJan 1, 2025
  3. Elijah NewrenJan 3, 2025
  4. Junio C HamanoJan 4, 2025
  5. Patrick SteinhardtJan 3, 2025
  6. Junio C HamanoJan 3, 2025
  7. Elijah NewrenJan 3, 2025
  8. 0/2 object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 4, 2025
  9. 1/2 object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 4, 2025
  10. Junio C HamanoJan 4, 2025
  11. Elijah NewrenJan 4, 2025
  12. Junio C HamanoJan 5, 2025
  13. 2/2 object-name: be more strict in parsing describe-like outputElijah Newren via GitGitGadget, Jan 4, 2025
  14. Junio C HamanoJan 4, 2025
  15. Elijah NewrenJan 4, 2025
  16. Junio C HamanoJan 4, 2025
  17. Elijah NewrenJan 4, 2025
  18. Junio C HamanoJan 6, 2025
  19. Elijah NewrenJan 6, 2025
  20. Junio C HamanoJan 6, 2025
  21. 0/2 object-name: fix a pair of object name resolution issuesElijah Newren via GitGitGadget, Jan 13, 2025
  22. 1/2 object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 13, 2025
  23. 2/2 object-name: be more strict in parsing describe-like outputElijah Newren via GitGitGadget, Jan 13, 2025
  24. Junio C HamanoJan 13, 2025
  25. Elijah NewrenJan 13, 2025

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.