Commit f327dbce authored by Mark Wooding's avatar Mark Wooding Committed by Junio C Hamano

Shell utilities: Guard against expr' magic tokens.

Some words, e.g., `match', are special to expr(1), and cause strange
parsing effects.  Track down all uses of expr and mangle the arguments
so that this isn't a problem.
Signed-off-by: default avatarMark Wooding <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 2283645b
......@@ -20,7 +20,7 @@ case "$1" in -v) verbose=t; shift ;; esac
case "$#,$1" in
1,*..*)
upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
upstream=$(expr "z$1" : 'z\(.*\)\.\.') ours=$(expr "z$1" : '.*\.\.\(.*\)$')
set x "$upstream" "$ours"
shift ;;
esac
......
......@@ -38,12 +38,12 @@ Perhaps git-update-server-info needs to be run there?"
}
while read sha1 refname
do
name=`expr "$refname" : 'refs/\(.*\)'` &&
name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
case "$name" in
*^*) continue;;
esac
if test -n "$use_separate_remote" &&
branch_name=`expr "$name" : 'heads/\(.*\)'`
branch_name=`expr "z$name" : 'zheads/\(.*\)'`
then
tname="remotes/$origin/$branch_name"
else
......@@ -346,7 +346,7 @@ then
# new style repository with a symref HEAD).
# Ideally we should skip the guesswork but for now
# opt for minimum change.
head_sha1=`expr "$head_sha1" : 'ref: refs/heads/\(.*\)'`
head_sha1=`expr "z$head_sha1" : 'zref: refs/heads/\(.*\)'`
head_sha1=`cat "$GIT_DIR/$remote_top/$head_sha1"`
;;
esac
......
......@@ -549,8 +549,8 @@ fi >>"$GIT_DIR"/COMMIT_EDITMSG
# Author
if test '' != "$force_author"
then
GIT_AUTHOR_NAME=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
GIT_AUTHOR_EMAIL=`expr "$force_author" : '.*\(<.*\)'` &&
GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
test '' != "$GIT_AUTHOR_NAME" &&
test '' != "$GIT_AUTHOR_EMAIL" ||
die "malformatted --author parameter"
......
......@@ -112,7 +112,7 @@ append_fetch_head () {
*)
note_="$remote_name of " ;;
esac
remote_1_=$(expr "$remote_" : '\(.*\)\.git/*$') &&
remote_1_=$(expr "z$remote_" : 'z\(.*\)\.git/*$') &&
remote_="$remote_1_"
note_="$note_$remote_"
......@@ -245,22 +245,22 @@ fetch_main () {
# These are relative path from $GIT_DIR, typically starting at refs/
# but may be HEAD
if expr "$ref" : '\.' >/dev/null
if expr "z$ref" : 'z\.' >/dev/null
then
not_for_merge=t
ref=$(expr "$ref" : '\.\(.*\)')
ref=$(expr "z$ref" : 'z\.\(.*\)')
else
not_for_merge=
fi
if expr "$ref" : '\+' >/dev/null
if expr "z$ref" : 'z\+' >/dev/null
then
single_force=t
ref=$(expr "$ref" : '\+\(.*\)')
ref=$(expr "z$ref" : 'z\+\(.*\)')
else
single_force=
fi
remote_name=$(expr "$ref" : '\([^:]*\):')
local_name=$(expr "$ref" : '[^:]*:\(.*\)')
remote_name=$(expr "z$ref" : 'z\([^:]*\):')
local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)')
rref="$rref$LF$remote_name"
......@@ -276,7 +276,7 @@ fetch_main () {
print "$u";
' "$remote_name")
head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted") &&
expr "$head" : "$_x40\$" >/dev/null ||
expr "z$head" : "z$_x40\$" >/dev/null ||
die "Failed to fetch $remote_name from $remote"
echo >&2 Fetching "$remote_name from $remote" using http
git-http-fetch -v -a "$head" "$remote/" || exit
......@@ -362,7 +362,7 @@ fetch_main () {
break ;;
esac
done
local_name=$(expr "$found" : '[^:]*:\(.*\)')
local_name=$(expr "z$found" : 'z[^:]*:\(.*\)')
append_fetch_head "$sha1" "$remote" \
"$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
done
......
......@@ -126,8 +126,8 @@ for revpair
do
case "$revpair" in
?*..?*)
rev1=`expr "$revpair" : '\(.*\)\.\.'`
rev2=`expr "$revpair" : '.*\.\.\(.*\)'`
rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
;;
*)
rev1="$revpair^"
......
......@@ -26,7 +26,7 @@ case "${1:-.}${2:-.}${3:-.}" in
fi
if test -f "$4"; then
rm -f -- "$4" &&
rmdir -p "$(expr "$4" : '\(.*\)/')" 2>/dev/null || :
rmdir -p "$(expr "z$4" : 'z\(.*\)/')" 2>/dev/null || :
fi &&
exec git-update-index --remove -- "$4"
;;
......
......@@ -8,8 +8,8 @@ get_data_source () {
case "$1" in
*/*)
# Not so fast. This could be the partial URL shorthand...
token=$(expr "$1" : '\([^/]*\)/')
remainder=$(expr "$1" : '[^/]*/\(.*\)')
token=$(expr "z$1" : 'z\([^/]*\)/')
remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
if test -f "$GIT_DIR/branches/$token"
then
echo branches-partial
......@@ -43,8 +43,8 @@ get_remote_url () {
branches)
sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;;
branches-partial)
token=$(expr "$1" : '\([^/]*\)/')
remainder=$(expr "$1" : '[^/]*/\(.*\)')
token=$(expr "z$1" : 'z\([^/]*\)/')
remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
url=$(sed -e 's/#.*//' "$GIT_DIR/branches/$token")
echo "$url/$remainder"
;;
......@@ -77,13 +77,13 @@ canon_refs_list_for_fetch () {
force=
case "$ref" in
+*)
ref=$(expr "$ref" : '\+\(.*\)')
ref=$(expr "z$ref" : 'z\+\(.*\)')
force=+
;;
esac
expr "$ref" : '.*:' >/dev/null || ref="${ref}:"
remote=$(expr "$ref" : '\([^:]*\):')
local=$(expr "$ref" : '[^:]*:\(.*\)')
expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
remote=$(expr "z$ref" : 'z\([^:]*\):')
local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
case "$remote" in
'') remote=HEAD ;;
refs/heads/* | refs/tags/* | refs/remotes/*) ;;
......@@ -97,7 +97,7 @@ canon_refs_list_for_fetch () {
*) local="refs/heads/$local" ;;
esac
if local_ref_name=$(expr "$local" : 'refs/\(.*\)')
if local_ref_name=$(expr "z$local" : 'zrefs/\(.*\)')
then
git-check-ref-format "$local_ref_name" ||
die "* refusing to create funny ref '$local_ref_name' locally"
......@@ -171,7 +171,7 @@ get_remote_refs_for_fetch () {
resolve_alternates () {
# original URL (xxx.git)
top_=`expr "$1" : '\([^:]*:/*[^/]*\)/'`
top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
while read path
do
case "$path" in
......
......@@ -94,7 +94,7 @@ case "$#" in
;;
*)
branch_name=`git symbolic-ref HEAD` || die "No current branch"
branch_name=`expr "$branch_name" : 'refs/heads/\(.*\)'`
branch_name=`expr "z$branch_name" : 'zrefs/heads/\(.*\)'`
;;
esac
branch=$(git-rev-parse --verify "${branch_name}^0") || exit
......
......@@ -75,7 +75,7 @@ git-check-ref-format "tags/$name" ||
object=$(git-rev-parse --verify --default HEAD "[email protected]") || exit 1
type=$(git-cat-file -t $object) || exit 1
tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
: ${username:=$(expr "$tagger" : '\(.*>\)')}
: ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment