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

Re: [PATCH 5/5] checkout-index: fix --temp relative path mangling

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 28, 2014, 03:19 UTC
Message-ID
<CAPig+cTCQgdX0FgZCiL921bAycEoceeKXT5UpnD7_Ro=NJH0Yg@mail.gmail.com>
In-Reply-To
<1419414196-58587-6-git-send-email-sunshine@sunshineco.com>
On Wed, Dec 24, 2014 at 4:43 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 30 quoted lines
> checkout-index --temp only properly prints relative paths which are
> descendants of the current directory. Paths in ancestor or sibling
> directories (or their children) are often printed in mangled form. For
> example:
>
>     mkdir a bbb &&
>     >file &&
>     >bbb/file &&
>     git update-index --add file bbb/file &&
>     cd a &&
>     git checkout-index --temp ../file ../bbb/file
>
> prints:
>
>     .merge_file_ooblek  le
>     .merge_file_igloo0  b/file
>
> rather than the correct:
>
>     .merge_file_ooblek  ../file
>     .merge_file_igloo0  ../bbb/file
>
> Internally, given the above example, checkout-index prefixes each input
> argument with the name of the current directory ("a/", in this case),
> and then assumes that it can simply skip forward by strlen("a/") bytes
> to recover the original name. This works for files in the current
> directory or its descendants, but fails for files in ancestors or
> siblings (or their children) due to path normalization.
>
> For instance, given "../file", "a/" is appended, giving "a/../file".
s/appended/prepended/
Show 25 quoted lines
> Path normalization folds out "a/../", resulting in "file". Attempting
> to recover the original name by skipping strlen("a/") bytes gives the
> incorrect "le" rather than the desired "../file".
>
> Fix this by taking advantage of write_name_quoted_relative() to recover
> the original name properly, rather than assuming that it can be
> recovered by skipping strlen(prefix) bytes.
>
> As a bonus, this also fixes a bug in which checkout-index --temp
> accessed and printed memory beyond the end-of-string. For instance,
> within a subdirectory named "subdirectory", and given argument
> "../file", prefixing would give "subdirectory/../file", which would
> become "file" after normalization. checkout-index would then attempt to
> recover the original name by skipping strlen("subdirectory/") bytes of
> "file", which placed it well beyond end-of-string. Despite this error,
> it often appeared to give the correct result, but only due to an
> accident of implementation which left an apparently correct copy of the
> path in memory following the normalized value. In particular, handed
> "subdirectory/../file", in-place processing by normalize_path_copy_len()
> resulted in "file\0rectory/../file". When checkout-index skipped
> strlen("subdirectory/") bytes, it ended up back at "../file" and thus
> appeared to give the correct answer, despite being past end-of-string.
>
> Reported-by: Russ Cox <rsc@golang.org>
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Previous: Eric SunshineNext: Junio C Hamano
Message 7 of 8 in “resolve checkout-index --temp path mangling”
  1. 0/5 resolve checkout-index --temp path manglingEric Sunshine, Dec 24, 2014
  2. 1/5 t2004: modernize styleEric Sunshine, Dec 24, 2014
  3. 2/5 t2004: drop unnecessary write-tree/read-treeEric Sunshine, Dec 24, 2014
  4. 3/5 t2004: standardize file naming in symlink testEric Sunshine, Dec 24, 2014
  5. 4/5 t2004: demonstrate broken relative path printingEric Sunshine, Dec 24, 2014
  6. 5/5 checkout-index: fix --temp relative path manglingEric Sunshine, Dec 24, 2014
  7. Eric SunshineDec 28, 2014
  8. Junio C HamanoDec 29, 2014

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.