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

Re: [PATCH] Avoid bug in Solaris xpg4/sed as used in submodule

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 9, 2012, 18:44 UTC
Message-ID
<7vbon0wxqs.fsf@alter.siamese.dyndns.org>
In-Reply-To
<m2fwcdc57q.fsf@igel.home>
Andreas Schwab <schwab@linux-m68k.org> writes:
Show 25 quoted lines
> Ben Walton <bwalton@artsci.utoronto.ca> writes:
>
>> Excerpts from Andreas Schwab's message of Mon Apr 09 02:40:03 -0400 2012:
>>
>>> How about using 's|[^/][^/]*|..|g' instead, which should avoid the bug
>>> as well.
>>
>> I'd be ok with that change if the changed semantics of the regex are
>> ok in this application.  It's essentially the same as s|[^/]+|..|g,
>> which requires at least one character.
>>
>> In the current code, if you do:
>>
>> echo '/' | sed -e 's|[^]*|..|g'
>>
>> you get: ../.. (from a working implementation).
>>
>> Your regex would see the result  be: /
>>
>> I don't think we'd ever be passing a plain /, but we might pass a
>> fully qualified path /path/to/foo, which would see the result change
>> from ../../../.. to /../../.. and that could have unintended impact.
>
> AFAICS the variables at this point never contain a value with a leading
> slash.

Correct. After $a and $b are initialized to "$(cd somewhere ; pwd)/", there is a loop:

	while test "${a%%/*}" = "${b%%/*}"
	do
		a=${a#*/}
		b=${b#*/}
	done

The test for the first iteration will see that they both start with '/' so stripping maximal trailing substring that match "/*" from them will yield two empty strings, and we always enter the body of the loop. The body during the first iteration will strip the leading '/'.

When pwd computed for both $a and $b were at '/', this loop may do something funky ($b will become empty), but that is covered by an earlier "is $a inside $b or vice versa?" check, so we should be OK.

Previous: Andreas SchwabNext: Ben Walton
Message 5 of 17 in “Avoid bug in Solaris xpg4/sed as used in submodule”
  1. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 9, 2012
  2. Andreas SchwabApr 9, 2012
  3. Ben WaltonApr 9, 2012
  4. Andreas SchwabApr 9, 2012
  5. Junio C HamanoApr 9, 2012
  6. Ben WaltonApr 9, 2012
  7. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 9, 2012
  8. Andreas SchwabApr 9, 2012
  9. Junio C HamanoApr 9, 2012
  10. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 10, 2012
  11. Junio C HamanoApr 10, 2012
  12. Ben WaltonApr 10, 2012
  13. Junio C HamanoApr 10, 2012
  14. Andreas SchwabApr 10, 2012
  15. Junio C HamanoApr 10, 2012
  16. Ben WaltonApr 13, 2012
  17. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 13, 2012

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.