Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 279875 - app-admin/eselect-python wrapper scripts should have /bin/bash shebang
Summary: app-admin/eselect-python wrapper scripts should have /bin/bash shebang
Status: VERIFIED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Python Gentoo Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2009-08-01 08:24 UTC by Michał Górny
Modified: 2009-08-01 18:57 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
bash -> POSIX for the wrapper scripts (eselect-python-20090801-POSIX.patch,1.06 KB, patch)
2009-08-01 18:57 UTC, Martin Väth
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2009-08-01 08:24:31 UTC
eselect-python generated /usr/bin/python wrapper uses shebang pointing to /bin/sh while the same script uses heavy bashisms. Thus, if user has changed /bin/sh symlink to point to any shell stricter than bash, script fails to execute python and user becomes even unable to run emerge.

This script should be shebanged /bin/bash or changed to use only POSIX shell-compatible syntax.
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2009-08-01 08:41:26 UTC
AFAICS 'python' wrapper is very easy to unbashize (replace this pointless pattern match with '[ -z "${EPYTHON}" ] || [ "${EPYTHON}" = "python" ]') but second one uses bash in more serious way.

I would like to notice that both scripts should use 'exec' at the end, to avoid polluting pidspace.
Comment 2 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-08-01 12:20:18 UTC
We will change this wrapper to use /bin/bash.

(In reply to comment #1)
> I would like to notice that both scripts should use 'exec' at the end

I tested it and it breaks displaying application name in title bar of terminal.
Comment 3 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-08-01 12:23:10 UTC
(In reply to comment #1)
> replace this pointless pattern match with
> '[ -z "${EPYTHON}" ] || [ "${EPYTHON}" = "python" ]'

'[[ "${EPYTHON}" =~ (/|^python$) ]]' means that we don't support including '/' character in "${EPYTHON}". '^python$' is used to avoid infinite recursion.
Comment 4 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-08-01 12:38:21 UTC
Fixed.
Comment 5 Martin Väth 2009-08-01 13:02:21 UTC
(In reply to comment #3)
I do not understand which script you mean (eselect-python-20090606 generates
symlinks), so I cannot check it. However, the POSIX rewrite of
  [[ "${EPYTHON}" =~ (/|^python$) ]]
would be easy:
  ! case "${EPYTHON}" in */*|python) false;; esac
Comment 6 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-08-01 13:10:20 UTC
(In reply to comment #5)
> However, the POSIX rewrite of [[ "${EPYTHON}" =~ (/|^python$) ]]
> would be easy:
>   ! case "${EPYTHON}" in */*|python) false;; esac

And the code would be more ugly...
Comment 7 Martin Väth 2009-08-01 15:55:23 UTC
Now I got the new portage and finally could look at the actual script.
In the content of this script, there is a much simpler POSIX equivalent:

Instead of
  [[ "\${EPYTHON}" =~ (/|^python$) ]] && EPYTHON="${target}"
one could just use
  case "\${EPYTHON}" in */*|python) EPYTHON="${target}";; esac
or, if you really think readability is an issue here:

case "\${EPYTHON}" in
  */*|python) EPYTHON="${target}";;
esac

I do not want to discuss uglyness (although opinions may differ).
But the main advantage of pretty much any /bin/sh over bash is that it
needs less memory and less time for loading and initialization than bash:
For a wrapper script of an interpreter language which is presumable
called pretty often from user's scripts, time and memory usage is an
important point IMHO.
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2009-08-01 16:40:51 UTC
@Martin Väth: Take a look at python-config, I don't think we could do this nice without calling external tools or using bashisms.

(In reply to comment #2)
> I tested it and it breaks displaying application name in title bar of terminal.

I don't think that titlebar issue should be more important than keeping additional, useless process issue.

Could you provide some example how can I trigger this issue?
Comment 9 Martin Väth 2009-08-01 18:10:59 UTC
(In reply to comment #7)
> Take a look at python-config

I do not think that it is so important to avoid bash here, since this is
probably not called as frequently as python itself. Anyway, I see no problem:

python_config="${EPYTHON/python/python-config-}
   could be rewritten in POSIX only slightly more complicated:
python_config="${EPYTHON%%python*}python-config${EPYTHON#*python}"
Comment 10 Martin Väth 2009-08-01 18:57:16 UTC
Created attachment 199837 [details, diff]
bash -> POSIX for the wrapper scripts

In my previous remark, I made two small mistakes:
1. A typo: "-config" should be "-config-".
2. I forgot the trivial case when EPYTHON does not contain "python".

Instead of attaching further code pieces, I attach a full patch for
the eselect-python module. The patch assumes that comment #4 was
already applied - it did not hit my portage tree so far, so I have to
make some assumptions here...