Shell utilities: Guard against expr' magic tokens.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 13 Apr 2006 22:01:24 +0000 (22:01 +0000)
committerJunio C Hamano <junkio@cox.net>
Thu, 13 Apr 2006 23:45:48 +0000 (16:45 -0700)
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: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-cherry.sh
git-clone.sh
git-commit.sh
git-fetch.sh
git-format-patch.sh
git-merge-one-file.sh
git-parse-remote.sh
git-rebase.sh
git-tag.sh
index 1a6232013b471d9a3df6ab10705c263aa740c2f7..f0e8831fa49ae46eb7ad664b6ad489e3974c9f91 100755 (executable)
@@ -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
index c013e481d044b3b11155d970f785766bc4c18613..0805168057c871549d87ff4e9e30d654abbed0a4 100755 (executable)
@@ -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
index bd3dc71cd6302190839c5d78310576fb709792f9..01c73bdd08e075d650e58664650bcd7fe1cd1551 100755 (executable)
@@ -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"
index 954901ddce9404eeadb616c4b65b466c62d4b63f..711650f3bc49636b43c55e14134cb9f20656f8f9 100755 (executable)
@@ -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
index 2ebf7e8596eaf9253cf302a01d9f9fb8c08041cf..c7133bc12624a7d00ea8c36b8f55207c16127bf4 100755 (executable)
@@ -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^"
index 5349a1c0fc54eb0b7feaf6192d20b6c6b2ab5e3b..5619409f1c7ee9c694c2de59aff195f971502226 100755 (executable)
@@ -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"
        ;;
index 63f22818e6aa36b5f101af996941b0471ce3cbf3..65c66d5d7439481cf0ba32c05f1b96def0ad1f86 100755 (executable)
@@ -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
index 5956f0654e1b344db7893519e309a45aa22ae16f..86dfe9cb96aea2f52ea6dea51d89605530abfd08 100755 (executable)
@@ -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
index 76e51ed174c3f8e752d221374ec83b1f1db7fde5..dc6aa9576764d7c2da98fbe15339df685fd8b94c 100755 (executable)
@@ -75,7 +75,7 @@ git-check-ref-format "tags/$name" ||
 object=$(git-rev-parse --verify --default HEAD "$@") || 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