From bc8f83a5afd858206efe518c31bbb1ac948a39a3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 17 Dec 2015 17:41:11 +0100 Subject: avoid evaluating shell in paths used in apt-key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apt-key creates internally a script (since ~1.1) which it will call to avoid dealing with an array of different options in the code itself, but while writing this script it wraps the values in "", which will cause the shell to evaluate its content upon execution. To make 'use' of this either set a absolute gpg command or TMPDIR to something as interesting as: "/tmp/This is fü\$\$ing cràzy, \$(man man | head -n1 | cut -d' ' -f1)\$!" If such paths can be encountered in reality is a different question… --- test/integration/framework | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'test/integration/framework') diff --git a/test/integration/framework b/test/integration/framework index 07b1f3236..8d0c9f5c3 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -54,7 +54,7 @@ msgprintf() { printf "$START " "$1" shift while [ -n "$1" ]; do - printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')" + printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')" shift done fi @@ -245,13 +245,23 @@ addtrap() { trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM } +escape_shell() { + echo "$@" | sed -e "s#'#'\"'\"'#g" +} + setupenvironment() { # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir) if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then unset TMPDIR fi TMPWORKINGDIRECTORY="$(mktemp -d)" - addtrap "cd /; rm -rf \"$TMPWORKINGDIRECTORY\";" + addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';" + if [ -n "$TMPDIR_ADD" ]; then + TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}" + mkdir -p "$TMPWORKINGDIRECTORY" + unset TMPDIR_ADD + export TMPDIR="$TMPWORKINGDIRECTORY" + fi msgninfo "Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…" mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded" @@ -1254,7 +1264,7 @@ EOF # start with an unmounted disk mv "${CD}" "${CD}-unmounted" # we don't want the disk to be modifiable - addtrap 'prefix' "chmod -f -R +w \"$PWD/rootdir/media/cdrom/dists/\" \"$PWD/rootdir/media/cdrom-unmounted/dists/\" || true;" + addtrap 'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;" chmod -R 555 rootdir/media/cdrom-unmounted/dists } -- cgit v1.2.3