bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

/bin/sh should set SHELL to /bin/sh


From: John Reiser
Subject: /bin/sh should set SHELL to /bin/sh
Date: Thu, 13 Jul 2017 15:05:30 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -DRECYCLES_PIDS -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin' -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic
uname output: Linux f25e64.local 4.11.7-200.fc25.x86_64 #1 SMP Mon Jun 26 
15:58:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.3
Patch Level: 43
Release Status: release

Description:
        When invoked as /bin/sh with SHELL unset, then bash should set SHELL
        to /bin/sh, not to the login shell for the current user.
        The current behavior can lead to surprises when descendants of /bin/sh
        invoke $SHELL.  There is even a reasonable argument that /bin/sh
        _always_ should set SHELL=/bin/sh, even (and especially) overriding
        an existing SHELL=/bin/bash.  This would agree with the manual page:
        "SHELL: The full pathname to the shell is kept in this environment 
variable."

        If it's not going to change, then please emphasize the current behavior
        on the manual page:  "SHELL: ... If it is not set when the  shell 
starts,
        bash assigns to it the full pathname of the current user's login shell,
        even if the result is SHELL=/bin/bash but the current shell was invoked
        as /bin/sh."

Repeat-By:
        # Verify that /bin/sh is a link to bash.
        $ ls -l /bin/sh
        lrwxrwxrwx. 1 root root 4 Sep 30  2016 /bin/sh -> bash

        # Remove SHELL from the environment, invoke /bin/sh,
        # ask for the new value of SHELL.
        # Note the single quotes to prevent expansion before invoking /bin/sh.
        $ env --unset=SHELL /bin/sh -c 'echo $SHELL'
        /bin/bash

        # Be pedantic: verify the comments above
        $ strace -e trace=execve -v -s 100 env --unset=SHELL /bin/sh -c 'echo 
$SHELL'
        execve("/usr/bin/env", ["env", "--unset=SHELL", "/bin/sh", "-c", "echo $SHELL"], 
[..., "SHELL=/bin/bash", ...]
        execve("/bin/sh", ["/bin/sh", "-c", "echo $SHELL"], [..., /* no SHELL= 
*/, ...]

Fix:
        Special case the setting of SHELL when the current shell
        was invoked as /bin/sh.

--



reply via email to

[Prev in Thread] Current Thread [Next in Thread]