Skip to content

Commit

Permalink
Makefile: fix shell quoting
Browse files Browse the repository at this point in the history
Makefile records paths to a few programs in GIT-BUILD-OPTIONS file.  These
paths need to be quoted twice: once to protect specials from the shell
that runs the generated GIT-BUILD-OPTIONS file, and again to protect them
(and the first level of quoting itself) from the shell that runs the
"echo" inside the Makefile.

You can test this by trying:

    $ ln -s /bin/tar "$HOME/Tes' program/tar"
    $ make TAR="$HOME/Tes' program/tar" test

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
gitster committed Jul 25, 2008
1 parent c30e699 commit bfce508
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -1210,9 +1210,12 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
echo "$$FLAGS" >GIT-CFLAGS; \
fi

# We need to apply sq twice, once to protect from the shell
# that runs GIT-BUILD-OPTIONS, and then again to protect it
# and the first level quoting from the shell that runs "echo".
GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPTIONS
@echo SHELL_PATH=\''$(SHELL_PATH_SQ)'\' >$@
@echo TAR=\''$(subst ','\'',$(TAR))'\' >>$@
@echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@
@echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@

### Detect Tck/Tk interpreter path changes
ifndef NO_TCLTK
Expand Down
10 changes: 5 additions & 5 deletions t/t5000-tar-tree.sh
Expand Up @@ -67,7 +67,7 @@ test_expect_success \
test_expect_success \
'validate file modification time' \
'mkdir extract &&
$TAR xf b.tar -C extract a/a &&
"$TAR" xf b.tar -C extract a/a &&
perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
echo "1117231200" >expected.mtime &&
diff expected.mtime b.mtime'
Expand All @@ -79,7 +79,7 @@ test_expect_success \

test_expect_success \
'extract tar archive' \
'(cd b && $TAR xf -) <b.tar'
'(cd b && "$TAR" xf -) <b.tar'

test_expect_success \
'validate filenames' \
Expand All @@ -96,7 +96,7 @@ test_expect_success \

test_expect_success \
'extract tar archive with prefix' \
'(cd c && $TAR xf -) <c.tar'
'(cd c && "$TAR" xf -) <c.tar'

test_expect_success \
'validate filenames with prefix' \
Expand All @@ -116,7 +116,7 @@ test_expect_success \

test_expect_success \
'extract substfiles' \
'(mkdir f && cd f && $TAR xf -) <f.tar'
'(mkdir f && cd f && "$TAR" xf -) <f.tar'

test_expect_success \
'validate substfile contents' \
Expand All @@ -128,7 +128,7 @@ test_expect_success \

test_expect_success \
'extract substfiles from archive with prefix' \
'(mkdir g && cd g && $TAR xf -) <g.tar'
'(mkdir g && cd g && "$TAR" xf -) <g.tar'

test_expect_success \
'validate substfile contents from archive with prefix' \
Expand Down

0 comments on commit bfce508

Please sign in to comment.