From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-903172-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id BD566138330
	for <garchives@archives.gentoo.org>; Mon, 26 Sep 2016 17:19:14 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 303E4E0B69;
	Mon, 26 Sep 2016 17:19:11 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id E5CC5E0B69
	for <gentoo-commits@lists.gentoo.org>; Mon, 26 Sep 2016 17:19:10 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 64D423408DD
	for <gentoo-commits@lists.gentoo.org>; Mon, 26 Sep 2016 17:19:09 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 145952486
	for <gentoo-commits@lists.gentoo.org>; Mon, 26 Sep 2016 17:19:07 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <1474909527.120deae6d7e63a35fc068aa92ff2e4263c98e5b6.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: bin/
X-VCS-Repository: proj/portage
X-VCS-Files: bin/ebuild.sh bin/phase-functions.sh
X-VCS-Directories: bin/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 120deae6d7e63a35fc068aa92ff2e4263c98e5b6
X-VCS-Branch: master
Date: Mon, 26 Sep 2016 17:19:07 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: ff75d02d-aaf5-4e54-a008-bdf49dbb2a09
X-Archives-Hash: 641c27b0286487650f416868e8a998c6

commit:     120deae6d7e63a35fc068aa92ff2e4263c98e5b6
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Sep 25 01:45:37 2016 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Sep 26 17:05:27 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=120deae6

ebuild.sh: start phases in temporary HOME if available (bug 595028)

This will avoid undesirable interactions with the python sitedir,
as reported in bug 574002. Since the temporary HOME is not guaranteed
to exist for some phases, use PORTAGE_PYM_PATH as a fallback. Also,
use PORTAGE_PYM_PATH inside __dyn_clean, since HOME is removed there.

X-Gentoo-Bug: 595028
X-Gentoo-Bug-URL: https://bugs.gentoo.org/595028
Acked-by: Alexander Berntsen <bernalex <AT> gentoo.org>

 bin/ebuild.sh          | 11 ++++++++---
 bin/phase-functions.sh |  8 +++++---
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index 5b3146d..a400ef7 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -167,9 +167,14 @@ export SANDBOX_ON=0
 
 # Ensure that $PWD is sane whenever possible, to protect against
 # exploitation of insecure search path for python -c in ebuilds.
-# See bug #239560 and bug #469338.
-cd "${PORTAGE_PYM_PATH}" || \
-	die "PORTAGE_PYM_PATH does not exist: '${PORTAGE_PYM_PATH}'"
+# See bug #239560, bug #469338, and bug #595028.
+if [[ -d ${HOME} ]]; then
+	# Use portage's temporary HOME directory if available.
+	cd "${HOME}" || die
+else
+	cd "${PORTAGE_PYM_PATH}" || \
+		die "PORTAGE_PYM_PATH does not exist: '${PORTAGE_PYM_PATH}'"
+fi
 
 #if no perms are specified, dirs/files will have decent defaults
 #(not secretive, but not stupid)

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index d75f43f..50f0fdb 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -261,6 +261,11 @@ __dyn_clean() {
 		chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
 	fi
 
+	# Some kernels, such as Solaris, return EINVAL when an attempt
+	# is made to remove the current working directory.
+	cd "${PORTAGE_PYM_PATH}" || \
+		die "PORTAGE_PYM_PATH does not exist: '${PORTAGE_PYM_PATH}'"
+
 	rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
 	rm -f "${PORTAGE_BUILDDIR}/.installed"
 
@@ -288,9 +293,6 @@ __dyn_clean() {
 	# result in it wiping the users distfiles directory (bad).
 	rm -rf "${PORTAGE_BUILDDIR}/distdir"
 
-	# Some kernels, such as Solaris, return EINVAL when an attempt
-	# is made to remove the current working directory.
-	cd "$PORTAGE_BUILDDIR"/../..
 	rmdir "$PORTAGE_BUILDDIR" 2>/dev/null
 
 	true