Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] ebuild.sh: Completely ban external commands in global scope
Date: Thu, 07 Sep 2017 07:36:46
Message-Id: B1473DDD-D196-4D89-BD40-80EDFA442268@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] ebuild.sh: Completely ban external commands in global scope by "Michał Górny"
1 Dnia 31 sierpnia 2017 22:45:42 CEST, "Michał Górny" <mgorny@g.o> napisał(a):
2 >Set PATH to /dev/null when sourcing the ebuild for dependency
3 >resolution
4 >in order to prevent shell from finding external commands via PATH
5 >lookup. While this does not prevent executing programs via full path,
6 >it
7 >should catch the majority of accidental uses.
8 >
9 >Closes: https://github.com/gentoo/portage/pull/199
10 >
11 >// Note: this can't be merged right now since we still have ebuilds
12 >// calling external commands; see:
13 >// https://bugs.gentoo.org/show_bug.cgi?id=629222
14
15 Update: gentoo is green now
16
17 >---
18 > bin/ebuild.sh | 6 +++++-
19 > bin/isolated-functions.sh | 4 ++++
20 > 2 files changed, 9 insertions(+), 1 deletion(-)
21 >
22 >diff --git a/bin/ebuild.sh b/bin/ebuild.sh
23 >index c23561651..94a44d534 100755
24 >--- a/bin/ebuild.sh
25 >+++ b/bin/ebuild.sh
26 >@@ -80,8 +80,12 @@ else
27 > done
28 > unset funcs x
29 >
30 >+ # prevent the shell from finding external executables
31 >+ # note: we can't use empty because it implies current directory
32 >+ _PORTAGE_ORIG_PATH=${PATH}
33 >+ export PATH=/dev/null
34 > command_not_found_handle() {
35 >- die "Command not found while sourcing ebuild: ${*}"
36 >+ die "External commands disallowed while sourcing ebuild: ${*}"
37 > }
38 > fi
39 >
40 >diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
41 >index e320f7132..b28e44f18 100644
42 >--- a/bin/isolated-functions.sh
43 >+++ b/bin/isolated-functions.sh
44 >@@ -121,6 +121,10 @@ __helpers_die() {
45 > }
46 >
47 > die() {
48 >+ # restore PATH since die calls basename & sed
49 >+ # TODO: make it pure bash
50 >+ [[ -n ${_PORTAGE_ORIG_PATH} ]] && PATH=${_PORTAGE_ORIG_PATH}
51 >+
52 > set +x # tracing only produces useless noise here
53 > local IFS=$' \t\n'
54 >
55
56
57 --
58 Best regards,
59 Michał Górny (by phone)

Replies