commit:     a9096e5613816fbcfd2aa461d6c67285a710419b
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jun  3 06:44:18 2022 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jun  3 06:45:04 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a9096e56

dev-lang/python: Fix LD_LIBRARY_PATH leaking into Portage internals

Move setting LD_LIBRARY_PATH for just-built Python invocation
to a wrapper, to avoid it incidentally leaking into Python used inside
Portage helpers.  Currently, this could result in mixing system Python
executable with just-built libpython.

Closes: https://bugs.gentoo.org/849311
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 dev-lang/python/python-2.7.18_p15.ebuild   | 9 +++++++--
 dev-lang/python/python-3.10.4_p1.ebuild    | 9 +++++++--
 dev-lang/python/python-3.11.0_beta3.ebuild | 9 +++++++--
 dev-lang/python/python-3.8.13_p2.ebuild    | 9 +++++++--
 dev-lang/python/python-3.9.13.ebuild       | 9 +++++++--
 5 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/dev-lang/python/python-2.7.18_p15.ebuild 
b/dev-lang/python/python-2.7.18_p15.ebuild
index ca58766b005c..97ebaf232b12 100644
--- a/dev-lang/python/python-2.7.18_p15.ebuild
+++ b/dev-lang/python/python-2.7.18_p15.ebuild
@@ -310,8 +310,13 @@ src_install() {
        local -x EPYTHON=python${PYVER}
        # if not using a cross-compiler, use the fresh binary
        if ! tc-is-cross-compiler; then
-               local -x PYTHON=./python
-               local -x 
LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
+               cat > python.wrap <<-EOF || die
+                       #!/bin/sh
+                       export 
LD_LIBRARY_PATH=\${PWD}\${LD_LIBRARY_PATH+:\${LD_LIBRARY_PATH}}
+                       exec ./python "\${@}"
+               EOF
+               chmod +x python.wrap || die
+               local -x PYTHON=./python.wrap
        else
                local -x PYTHON=${EPREFIX}/usr/bin/${EPYTHON}
        fi

diff --git a/dev-lang/python/python-3.10.4_p1.ebuild 
b/dev-lang/python/python-3.10.4_p1.ebuild
index 45b349a487e6..87ba9d3a2e1d 100644
--- a/dev-lang/python/python-3.10.4_p1.ebuild
+++ b/dev-lang/python/python-3.10.4_p1.ebuild
@@ -369,8 +369,13 @@ src_install() {
        local -x EPYTHON=python${PYVER}
        # if not using a cross-compiler, use the fresh binary
        if ! tc-is-cross-compiler; then
-               local -x PYTHON=./python
-               local -x 
LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
+               cat > python.wrap <<-EOF || die
+                       #!/bin/sh
+                       export 
LD_LIBRARY_PATH=\${PWD}\${LD_LIBRARY_PATH+:\${LD_LIBRARY_PATH}}
+                       exec ./python "\${@}"
+               EOF
+               chmod +x python.wrap || die
+               local -x PYTHON=./python.wrap
        else
                local -x PYTHON=${EPREFIX}/usr/bin/${EPYTHON}
        fi

diff --git a/dev-lang/python/python-3.11.0_beta3.ebuild 
b/dev-lang/python/python-3.11.0_beta3.ebuild
index e756eecece06..57e6c4928123 100644
--- a/dev-lang/python/python-3.11.0_beta3.ebuild
+++ b/dev-lang/python/python-3.11.0_beta3.ebuild
@@ -381,8 +381,13 @@ src_install() {
        local -x EPYTHON=python${PYVER}
        # if not using a cross-compiler, use the fresh binary
        if ! tc-is-cross-compiler; then
-               local -x PYTHON=./python
-               local -x 
LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
+               cat > python.wrap <<-EOF || die
+                       #!/bin/sh
+                       export 
LD_LIBRARY_PATH=\${PWD}\${LD_LIBRARY_PATH+:\${LD_LIBRARY_PATH}}
+                       exec ./python "\${@}"
+               EOF
+               chmod +x python.wrap || die
+               local -x PYTHON=./python.wrap
        else
                local -x PYTHON=${EPREFIX}/usr/bin/${EPYTHON}
        fi

diff --git a/dev-lang/python/python-3.8.13_p2.ebuild 
b/dev-lang/python/python-3.8.13_p2.ebuild
index b5db263829e0..ef56899f1fee 100644
--- a/dev-lang/python/python-3.8.13_p2.ebuild
+++ b/dev-lang/python/python-3.8.13_p2.ebuild
@@ -319,8 +319,13 @@ src_install() {
        local -x EPYTHON=python${PYVER}
        # if not using a cross-compiler, use the fresh binary
        if ! tc-is-cross-compiler; then
-               local -x PYTHON=./python
-               local -x 
LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
+               cat > python.wrap <<-EOF || die
+                       #!/bin/sh
+                       export 
LD_LIBRARY_PATH=\${PWD}\${LD_LIBRARY_PATH+:\${LD_LIBRARY_PATH}}
+                       exec ./python "\${@}"
+               EOF
+               chmod +x python.wrap || die
+               local -x PYTHON=./python.wrap
        else
                local -x PYTHON=${EPREFIX}/usr/bin/${EPYTHON}
        fi

diff --git a/dev-lang/python/python-3.9.13.ebuild 
b/dev-lang/python/python-3.9.13.ebuild
index 600e82ffcc14..ace30db0b27b 100644
--- a/dev-lang/python/python-3.9.13.ebuild
+++ b/dev-lang/python/python-3.9.13.ebuild
@@ -363,8 +363,13 @@ src_install() {
        local -x EPYTHON=python${PYVER}
        # if not using a cross-compiler, use the fresh binary
        if ! tc-is-cross-compiler; then
-               local -x PYTHON=./python
-               local -x 
LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
+               cat > python.wrap <<-EOF || die
+                       #!/bin/sh
+                       export 
LD_LIBRARY_PATH=\${PWD}\${LD_LIBRARY_PATH+:\${LD_LIBRARY_PATH}}
+                       exec ./python "\${@}"
+               EOF
+               chmod +x python.wrap || die
+               local -x PYTHON=./python.wrap
        else
                local -x PYTHON=${EPREFIX}/usr/bin/${EPYTHON}
        fi

Reply via email to