Skip to content

Commit 4b88685

Browse files
committed
Makefile: escape single-quotes in VERBOSE $(ECHO) argument
When the command string run through $(call VERBOSE,…) contains a single-quote character followed by shell metacharacters, the shell executing the VERBOSE template's $(ECHO) command will attempt to interpret those metacharacters. This could be disastrous, such as if someone were to put in a Makefile recipe: $(call VERBOSE, , $(ECHO) 'Will not `rm -rf ~`') When run with V=1, which causes VERBOSE to be defined as… VERBOSE = $(ECHO) '$(2)'; $(2) …Make would evaluate the above call into: echo 'echo 'Will not `rm -rf ~`''; echo 'Will not `rm -rf ~`' And oops, there goes the neighborhood. The real-world motivating case for this fix is the sed call in the recipe for doc/index.rst in doc/Makefile. It contains a sed expression enclosed in single quotes, containing parentheses. When run through VERBOSE with V=1, the single quotes around the sed expression actually escape _out_ of the single-quoted string that is intended to be the whole command line, and you get: /bin/sh: -c: line 1: syntax error near unexpected token `(' The fix is for VERBOSE to escape any single quotes embedded in the command line argument when echoing it: VERBOSE = $(ECHO) '$(subst ','\'',$(2))'; $(2) Note that this is still wrong, as it will not do the right thing if $(2) happens to begin with a hyphen, but I didn't want to introduce a new "PRINTF" variable (or do something unsavory like calling cat with a here-doc) to squash a bug that currently has no known manifestations. Changelog-None
1 parent 23388c4 commit 4b88685

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SORT=LC_ALL=C sort
3636

3737

3838
ifeq ($V,1)
39-
VERBOSE = $(ECHO) '$(2)'; $(2)
39+
VERBOSE = $(ECHO) '$(subst ','\'',$(2))'; $(2)
4040
else
4141
VERBOSE = $(ECHO) $(1); $(2)
4242
endif

0 commit comments

Comments
 (0)