git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Walton <bwalton@artsci.utoronto.ca>
To: gitster@pobox.com, schwab@linux-m68k.org
Cc: git@vger.kernel.org, Ben Walton <bwalton@artsci.utoronto.ca>
Subject: [PATCH] Avoid bug in Solaris xpg4/sed as used in submodule
Date: Mon,  9 Apr 2012 20:13:20 -0400	[thread overview]
Message-ID: <1334016800-11574-1-git-send-email-bwalton@artsci.utoronto.ca> (raw)
In-Reply-To: <7vy5q4tw3i.fsf@alter.siamese.dyndns.org>

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.

As we do not need to handle fully qualfied paths we can make the
regex match 1 or more instead of 0 or more non-/ characters so use
's|[^/]\{1,\}|..|g' instead, which is correctly handled by all tested
sed implementations.  This expression is semantically different than
the original one.  It will not place leading '..' on a fully qualified
path as the original expression did.  None of the paths passed to the
regex relied on this behaviour so changing it shouldn't have negative
impact.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---

For some reason, I thought that using {x,y} range notation wasn't
valid in this scenario, but I think I was mistaken.  It seems to be
widely used elsewhere throughout the code.  I prefer that to the
[^/][^/]* notation and as they're equivalent, I switched to it.

 git-submodule.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index efc86ad..2c18e0c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -167,10 +167,11 @@ module_clone()
 	a=${a%/}
 	b=${b%/}
 
-	rel=$(echo $b | sed -e 's|[^/]*|..|g')
+	# Turn path components into .. 
+	rel=$(echo $b | sed -e 's|[^/]\{1,\}|..|g')
 	echo "gitdir: $rel/$a" >"$path/.git"
 
-	rel=$(echo $a | sed -e 's|[^/]*|..|g')
+	rel=$(echo $a | sed -e 's|[^/]\{1,\}|..|g')
 	(clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
 }
 
-- 
1.7.9

  reply	other threads:[~2012-04-10  0:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-09  1:36 [PATCH] Avoid bug in Solaris xpg4/sed as used in submodule Ben Walton
2012-04-09  6:40 ` Andreas Schwab
2012-04-09 13:30   ` Ben Walton
2012-04-09 15:09     ` Andreas Schwab
2012-04-09 18:44       ` Junio C Hamano
2012-04-09 18:47       ` Ben Walton
2012-04-09 20:08         ` Ben Walton
2012-04-09 21:07           ` Andreas Schwab
2012-04-09 21:48             ` Junio C Hamano
2012-04-10  0:13               ` Ben Walton [this message]
2012-04-10  0:31                 ` Junio C Hamano
2012-04-10  0:40                   ` Ben Walton
2012-04-10  1:05                     ` Junio C Hamano
2012-04-10  8:31                       ` Andreas Schwab
2012-04-10 16:10                         ` Junio C Hamano
2012-04-13  0:46                           ` Ben Walton
2012-04-13  0:48                             ` Ben Walton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334016800-11574-1-git-send-email-bwalton@artsci.utoronto.ca \
    --to=bwalton@artsci.utoronto.ca \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).