Sanitize PYTHONPATH for helpers, bug #477764
authorZac Medico <zmedico@gentoo.org>
Mon, 22 Jul 2013 16:42:48 +0000 (09:42 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 22 Jul 2013 16:42:48 +0000 (09:42 -0700)
bin/bashrc-functions.sh
bin/ebuild-helpers/dohtml
bin/ebuild-helpers/portageq
bin/ebuild-helpers/xattr/install
bin/ebuild-ipc
bin/misc-functions.sh
bin/phase-functions.sh
bin/save-ebuild-env.sh
pym/portage/__init__.py
pym/portage/package/ebuild/_config/special_env_vars.py
pym/portage/package/ebuild/config.py

index f1b6bb538a20ab89d4cdf6ad07be2ea67ebdedd3..503b1722473812dec0c9b3bb35e2afbbbc470629 100644 (file)
@@ -1,9 +1,9 @@
 #!/bin/bash
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 portageq() {
-       PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+       PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}}\
        "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
 }
 
index fd9efd26700d59bc04c295e6e793efb1db5bc5e3..75d3d00ab2d0a23919e12b2dabd82537fe029b18 100755 (executable)
@@ -9,7 +9,7 @@ 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 \
+PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \
        "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/dohtml.py" "$@"
 
 ret=$?
index 7bd330bec517e9c63f01f66af4816368f00d6b8e..b67b03f3351c8369af329802caa8a0ae958e60f2 100755 (executable)
@@ -6,5 +6,5 @@ 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.
 cd "${PORTAGE_PYM_PATH}"
-PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \
+PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \
        exec "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/portageq" "$@"
index 51a477468918b38ca462cdc5919f618c247052f9..f51f621bc738d8cb4c7be6f626fefac975649bc4 100755 (executable)
@@ -8,5 +8,5 @@ PORTAGE_PYM_PATH=${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}
 export __PORTAGE_HELPER_CWD=${PWD}
 cd "${PORTAGE_PYM_PATH}"
 export __PORTAGE_HELPER_PATH=${BASH_SOURCE[0]}
-PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}$PYTHONPATH \
+PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \
        exec "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/install.py" "$@"
index 9ff6f1ccbbd38b4fd7a3995fce55ba32e08fc027..820005fbb6d7183a4261aa8daa1ffc79cd37fe3b 100755 (executable)
@@ -6,5 +6,5 @@ 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.
 cd "${PORTAGE_PYM_PATH}"
-PYTHONPATH=$PORTAGE_PYM_PATH${PYTHONPATH:+:}$PYTHONPATH \
+PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \
        exec "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/ebuild-ipc.py" "$@"
index 9375734cb944f98d6faaa1e150e4edbc65657f47..ee21444535ed0d80e4912f0d9373aa7674d2eccb 100755 (executable)
@@ -1157,7 +1157,7 @@ __dyn_package() {
        tar $tar_options -cf - $PORTAGE_BINPKG_TAR_OPTS -C "${PROOT}" . | \
                $PORTAGE_BZIP2_COMMAND -c > "$PORTAGE_BINPKG_TMPFILE"
        assert "failed to pack binary package: '$PORTAGE_BINPKG_TMPFILE'"
-       PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+       PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \
                "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH"/xpak-helper.py recompose \
                "$PORTAGE_BINPKG_TMPFILE" "$PORTAGE_BUILDDIR/build-info"
        if [ $? -ne 0 ]; then
index dc4da6a4e4d1541e0d8131344acffec98e0bc702..8a52f3007df0b0a9736375ef81f75199b7a73074 100644 (file)
@@ -23,7 +23,7 @@ PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC \
        PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
        PORTAGE_INTERNAL_CALLER PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
        PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_OVERRIDE_EPREFIX \
-       PORTAGE_PYM_PATH PORTAGE_PYTHON \
+       PORTAGE_PYM_PATH PORTAGE_PYTHON PORTAGE_PYTHONPATH \
        PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
        PORTAGE_REPO_NAME PORTAGE_REPOSITORIES PORTAGE_RESTRICT \
        PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
index 72055c9e675fa763b66e8fa6e7e7fb721433db1f..f6952450e7e9623434e49e114c1ac27e5c33d204 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 # @FUNCTION: __save_ebuild_env
index 1fb35bb96b799f320c47ae376e36f0e9584340af..51aa61b41ec7033fad2532119d82ddc40dbf84af 100644 (file)
@@ -607,7 +607,7 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None,
                # with ROOT != "/", so pass a nearly empty dict for the env parameter.
                clean_env = {}
                for k in ('PATH', 'PORTAGE_GRPNAME', 'PORTAGE_REPOSITORIES', 'PORTAGE_USERNAME',
-                       'SSH_AGENT_PID', 'SSH_AUTH_SOCK', 'TERM',
+                       'PYTHONPATH', 'SSH_AGENT_PID', 'SSH_AUTH_SOCK', 'TERM',
                        'ftp_proxy', 'http_proxy', 'no_proxy',
                        '__PORTAGE_TEST_HARDLINK_LOCKS'):
                        v = settings.get(k)
index 85b699eaee8a17a6b7e512b568fdc0f76b624ef3..35f80e3dd735ba4514d8a7f8c0117e7d899c8edb 100644 (file)
@@ -68,7 +68,8 @@ environ_whitelist += [
        "PORTAGE_INST_GID", "PORTAGE_INST_UID",
        "PORTAGE_IPC_DAEMON", "PORTAGE_IUSE",
        "PORTAGE_LOG_FILE", "PORTAGE_OVERRIDE_EPREFIX", "PORTAGE_PIPE_FD",
-       "PORTAGE_PYM_PATH", "PORTAGE_PYTHON", "PORTAGE_QUIET",
+       "PORTAGE_PYM_PATH", "PORTAGE_PYTHON",
+       "PORTAGE_PYTHONPATH", "PORTAGE_QUIET",
        "PORTAGE_REPO_NAME", "PORTAGE_REPOSITORIES", "PORTAGE_RESTRICT",
        "PORTAGE_SIGPIPE_STATUS",
        "PORTAGE_TMPDIR", "PORTAGE_UPDATE_ENV", "PORTAGE_USERNAME",
index 39a60968fe36cfd44e39e2193bdf03242b970451..506600823293ab52594f9f142d14333555db0fc0 100644 (file)
@@ -146,7 +146,7 @@ class config(object):
        """
 
        _constant_keys = frozenset(['PORTAGE_BIN_PATH', 'PORTAGE_GID',
-               'PORTAGE_PYM_PATH'])
+               'PORTAGE_PYM_PATH', 'PORTAGE_PYTHONPATH'])
 
        _setcpv_aux_keys = ('DEFINED_PHASES', 'DEPEND', 'EAPI', 'HDEPEND',
                'INHERITED', 'IUSE', 'REQUIRED_USE', 'KEYWORDS', 'LICENSE', 'PDEPEND',
@@ -2489,6 +2489,20 @@ class config(object):
                        elif mykey == "PORTAGE_PYM_PATH":
                                return portage._pym_path
 
+                       elif mykey == "PORTAGE_PYTHONPATH":
+                               value = [x for x in \
+                                       self.backupenv.get("PYTHONPATH", "").split(":") if x]
+                               need_pym_path = True
+                               if value:
+                                       try:
+                                               need_pym_path = not os.path.samefile(value[0],
+                                                       portage._pym_path)
+                                       except OSError:
+                                               pass
+                               if need_pym_path:
+                                       value.insert(0, portage._pym_path)
+                               return ":".join(value)
+
                        elif mykey == "PORTAGE_GID":
                                return "%s" % portage_gid