remap.sh uses /bin/sh to first change the working directory and then
execute the given program in the remap context. But the arguments
given on the command line were not properly escaped:

% '/bin/sh' '-c' 'echo $0'
/bin/sh
% remap '/bin/sh' '-c' 'echo $0'
<empty line>
% remap-fixed '/bin/sh' '-c' 'echo $0'
/bin/sh

* utils/remap.sh: Escape arguments handed to /bin/sh so that they are
  not evaluated prematurely.
---
 utils/remap.sh |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/utils/remap.sh b/utils/remap.sh
index d799759..064f0f5 100644
--- a/utils/remap.sh
+++ b/utils/remap.sh
@@ -57,10 +57,16 @@ if [ $# -eq 0 ]; then
   set -- ${SHELL:-/bin/sh}
 fi
 
+TARGET=
+until [ $# -eq 0 ]; do
+  TARGET="${TARGET} '$(echo "$1" | sed -e "s/'/'\\\\''/g")'"
+  shift
+done
+
 # We exec settrans, which execs the "fakeauth" command in the chroot context.
 # The `pwd` is evaluated here and now, and that result interpreted inside
 # the shell running under fakeauth to chdir there inside the chroot world.
 # That shell then execs our arguments as a command line.
 exec /bin/settrans --chroot \
-     /bin/sh -c "cd `pwd`; $*" \
+     /bin/sh -c "cd `pwd`; exec ${TARGET}" \
      -- / /hurd/remap $MAPPED
-- 
1.7.10.4


-- 
To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/1377245375-8184-2-git-send-email-4win...@informatik.uni-hamburg.de

Reply via email to