git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Makefile: escape ' in bin-wrappers rule
@ 2017-03-16  6:17 Devin Lehmacher
  2017-03-16 11:24 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Devin Lehmacher @ 2017-03-16  6:17 UTC (permalink / raw)
  To: git

If the pwd contains a ' escape it as '\'' so that git will not fail
while building on a path containing '.
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ed68700ac..5cf5d8537 100644
--- a/Makefile
+++ b/Makefile
@@ -2276,7 +2276,7 @@ all:: $(NO_INSTALL)
 bin-wrappers/%: wrap-for-bin.sh
 	@mkdir -p bin-wrappers
 	$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-	     -e 's|@@BUILD_DIR@@|$(shell pwd)|' \
+	     -e 's|@@BUILD_DIR@@|$(shell pwd | sed -e "s/'/'\\\''/g")|' \
 	     -e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%,$(@F))|' < $< > $@ && \
 	chmod +x $@
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Makefile: escape ' in bin-wrappers rule
  2017-03-16  6:17 [PATCH] Makefile: escape ' in bin-wrappers rule Devin Lehmacher
@ 2017-03-16 11:24 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2017-03-16 11:24 UTC (permalink / raw)
  To: Devin Lehmacher; +Cc: git

On Thu, Mar 16, 2017 at 02:17:38AM -0400, Devin Lehmacher wrote:

> If the pwd contains a ' escape it as '\'' so that git will not fail
> while building on a path containing '.

I think this only fixes half the problem...

> diff --git a/Makefile b/Makefile
> index ed68700ac..5cf5d8537 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2276,7 +2276,7 @@ all:: $(NO_INSTALL)
>  bin-wrappers/%: wrap-for-bin.sh
>  	@mkdir -p bin-wrappers
>  	$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
> -	     -e 's|@@BUILD_DIR@@|$(shell pwd)|' \
> +	     -e 's|@@BUILD_DIR@@|$(shell pwd | sed -e "s/'/'\\\''/g")|' \

This escapes the single-quote against the shell run by make. But it does
a blind text substitution inside the wrap-for-bin script itself, which
means it's subject to another round of expansion. E.g.:

  $ git clone git foo\'git
  $ cd foo\'git
  $ make bin-wrappers/git
  GIT_VERSION = 2.12.0.623.g86ec6c963
  /bin/sh: 4: Syntax error: Unterminated quoted string
  Makefile:2296: recipe for target 'bin-wrappers/git' failed
  make: *** [bin-wrappers/git] Error 2

  $ git am /your/patch
  $ make bin-wrappers/git
  GIT_VERSION = 2.12.0.624.gc9787fbf0
      GEN bin-wrappers/git
  $ bin-wrappers/git
  bin-wrappers/git: 16: bin-wrappers/git: Syntax error: "fi" unexpected

So you'd need an extra layer of quoting. And then to top it all off,
passing backslashes through sed requires _another_ layer of quoting.
Something like this:

diff --git a/Makefile b/Makefile
index 17e381f0c..9c1357a77 100644
--- a/Makefile
+++ b/Makefile
@@ -2292,10 +2292,15 @@ test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(
 all:: $(TEST_PROGRAMS) $(test_bindir_programs)
 all:: $(NO_INSTALL)
 
+PWD = $(shell pwd)
+PWD_SQ = $(subst ','\'',$(PWD))
+PWD_SQ_SED = $(subst \,\\,$(PWD_SQ))
+PWD_SQ_SED_SQ = $(subst ','\'',$(PWD_SQ_SED))
+
 bin-wrappers/%: wrap-for-bin.sh
 	@mkdir -p bin-wrappers
 	$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-	     -e 's|@@BUILD_DIR@@|$(shell pwd)|' \
+	     -e 's|@@BUILD_DIR@@|$(PWD_SQ_SED_SQ)|' \
 	     -e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%,$(@F))|' < $< > $@ && \
 	chmod +x $@
 

That at least gets me as far as building a runnable git. I wouldn't be
surprised if there are other gotchas, though. Running "make test" dies
in t0060 due to similar substitutions.

I guess if somebody is really determined they can try to fix every spot.
But at some point I wonder if the answer is "if it hurts, don't do it".

-Peff

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-16 11:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16  6:17 [PATCH] Makefile: escape ' in bin-wrappers rule Devin Lehmacher
2017-03-16 11:24 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).