dohtml: safe cwd, bug #469338
authorZac Medico <zmedico@gentoo.org>
Sun, 12 May 2013 20:47:42 +0000 (13:47 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 12 May 2013 20:47:42 +0000 (13:47 -0700)
bin/dohtml.py
bin/ebuild-helpers/dohtml

index 3af27050997b89f26742c33bbdbc308cbc61adde..1b6ba89f1d6e295cd44f5e2a75947ebd46a3b2f2 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 #
@@ -33,6 +33,9 @@ from __future__ import print_function
 import os
 import sys
 
+# Change back to original cwd _after_ all imports (bug #469338).
+os.chdir(os.environ["__PORTAGE_HELPER_CWD"])
+
 def dodir(path):
        os.spawnlp(os.P_WAIT, "install", "install", "-d", path)
 
index aec5e79bd0af2c917c8b9ab8cc7b956f932322a3..4be9bc2eb8de0088722f2bebc0a9f0d8c5b3ff5f 100755 (executable)
@@ -6,6 +6,9 @@ source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
 
 PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}
 PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}
+# Use safe cwd, avoiding unsafe import for bug #469338.
+export __PORTAGE_HELPER_CWD=${PWD}
+cd "${PORTAGE_PYM_PATH}"
 PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \
        "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/dohtml.py" "$@"