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