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

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Andreas Schwab <hidden>
Date: 2016-06-15 22:53:32

Ben Walton [off-list ref] writes:
The sed provided by Solaris in /usr/xpg4/bin has a bug whereby an
unanchored regex using * for zero or more repetitions sees two
separate matches fed to the substitution engine in some cases.

This is evidenced by:

$ for sed in /usr/xpg4/bin/sed /usr/bin/sed /opt/csw/gnu/sed; do \
echo 'ab' | $sed -e 's|[a]*|X|g'; \
done
XXbX
XbX
XbX

This bug was triggered during a git submodule clone operation as
exercised in the setup stage of t5526-fetch-submodules when using the
default SANE_TOOL_PATH for Solaris.  It led to paths such as
..../.. being used in the submodule .git gitdir reference.

Using the expression 's|\([^/]*\(/*\)\)|..\2|g' provides the desired
How about using 's|[^/][^/]*|..|g' instead, which should avoid the bug
as well.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

From: Ben Walton <hidden>
Date: 2016-06-15 22:53:32

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.

I'd need to look more closely to see if this is a problem in reality.
Others more familiar with this code likely know the answer already.

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help