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

Re: [PATCH 0/6] Improved infrastructure for refname normalization

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Sep 9, 2011, 15:33 UTC
Message-ID
<4E6A31D1.5020404@alum.mit.edu>
In-Reply-To
<4E6A1D7D.6050602@gmail.com>
On 09/09/2011 04:06 PM, A Large Angry SCM wrote:
Show 19 quoted lines
> On 09/09/2011 07:46 AM, Michael Haggerty wrote:
>> As a prerequisite to storing references caches hierarchically (itself
>> needed for performance reasons), here is a patch series to help us get
>> refname normalization under control.
>>
>> The problem is that some UI accepts unnormalized reference names (like
>> "/foo/bar" or "foo///bar" instead of "foo/bar") and passes them on to
>> library routines without normalizing them.  The library, on the other
>> hand, assumes that the refnames are normalized.  Sometimes (mostly in
>> the case of loose references) unnormalized refnames happen to work,
>> but in other cases (like packed references or when looking up refnames
>> in the cache) they silently fail.  Given that refnames are sometimes
>> treated as path names, there is a chance that some security-relevant
>> bugs are lurking in this area, if not in git proper then in scripts
>> that interact with git.
> 
> Why can't the library do the normalization instead of expecting every
> other component that deals with reference names having to do it for the
> library?
The library could do the normalization, but
1. It would probably cost a lot of redundant checks as reference names
pass in and out of the library and back in again
2. Normalization requires copying or overwriting the incoming string, so
each time a refname crosses the library perimeter there might have to be
an extra memory allocation with the associated headaches of dealing with
the ownership of the memory.
3. The library doesn't encapsulate all uses of reference names; for
example, for_each_ref() invokes a callback function with the refname as
an argument.  The callback function is free to do a strcmp() of the
refname (normalized by the library) with some arbitrary string that it
got from the command line.  Either the caller has to do the
normalization itself (i.e., outside of the library) or the library has
to learn how to do every possible filtering operation with refnames.
Show 8 quoted lines
>> * Forbid ".lock" at the end of any refname component, as directories
>>    with such names can conflict with attempts to create lock files for
>>    other refnames.
> 
> I find this overly restrictive. If you need to create a lock based on a
> reference name or component, use a name for the lock object that starts
> with one of the characters that reference names or components are
> already forbidden from starting with.
I agree; this is unpleasantly restrictive.

But please remember that refnames already cannot end in ".lock" ("foo/bar.lock" is already forbidden; this change also prohibits "foo.lock/bar").

However, your suggested solution would cause problems if two versions of git are running on the same machine. An old version of git would not know to respect the new version's lock files. ISTM that this would be too dangerous. Suggestions welcome.

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: A Large Angry SCMNext: Junio C Hamano
Message 11 of 13 in “Improved infrastructure for refname normalization”
  1. 0/6 Improved infrastructure for refname normalizationMichael Haggerty, Sep 9, 2011
  2. 1/6 Change bad_ref_char() to return a boolean valueMichael Haggerty, Sep 9, 2011
  3. 2/6 git check-ref-format: add options --onelevel-ok and --refname-patternMichael Haggerty, Sep 9, 2011
  4. 3/6 Change check_ref_format() to take a flags argumentMichael Haggerty, Sep 9, 2011
  5. 4/6 Add a library function normalize_refname()Michael Haggerty, Sep 9, 2011
  6. 5/6 Do not allow ".lock" at the end of any refname componentMichael Haggerty, Sep 9, 2011
  7. 6/6 Add a REFNAME_ALLOW_UNNORMALIZED flag to check_ref_format()Michael Haggerty, Sep 9, 2011
  8. Junio C HamanoSep 9, 2011
  9. Michael HaggertySep 10, 2011
  10. A Large Angry SCMSep 9, 2011
  11. Michael HaggertySep 9, 2011
  12. Junio C HamanoSep 9, 2011
  13. Michael HaggertySep 10, 2011

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.