bug-bash
[Top][All Lists]
Advanced

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

improper bashrc sourcing with closed stdin


From: Andrew Gregory
Subject: improper bashrc sourcing with closed stdin
Date: Sat, 20 Feb 2016 04:25:46 -0500
User-agent: Mutt/1.5.24 (2015-08-30)

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-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_FORTIFY_SOURCE=2 
-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong 
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' 
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' 
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout'
uname output: Linux localhost 4.4.1-2-ARCH #1 SMP PREEMPT Wed Feb 3 13:12:33 
UTC 2016 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

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

Description:
    If run non-interactively with stdin closed and SHLVL=0, bash will
    source ~/.bashrc, due to run_startup_files() thinking that bash is
    being run by rshd.

Repeat-By:

#include <unistd.h>
#include <stdlib.h>

void main(void) {
    close(0);
    setenv("SHLVL", "0", 1);
    execl("/bin/bash", "/bin/bash", "-c", "echo foo", NULL);
}

Fix:
    It looks like isnetconn needs to be modified to not count an fd
    that returns EBADF as a socket:

diff --git a/lib/sh/netconn.c b/lib/sh/netconn.c
index 36e5bf5..f4ffe6c 100644
--- a/lib/sh/netconn.c
+++ b/lib/sh/netconn.c
@@ -52,7 +52,7 @@ isnetconn (fd)
   l = sizeof(sa);
   rv = getpeername(fd, &sa, &l);
   /* Posix.2 says getpeername can return these errors. */
-  return ((rv < 0 && (errno == ENOTSOCK || errno == ENOTCONN || errno == 
EINVAL)) ? 0 : 1);
+  return ((rv < 0 && (errno == ENOTSOCK || errno == ENOTCONN || errno == 
EINVAL || errno == EBADF)) ? 0 : 1);
 #else /* !HAVE_GETPEERNAME || SVR4_2 || __BEOS__ */
 #  if defined (SVR4) || defined (SVR4_2)
   /* Sockets on SVR4 and SVR4.2 are character special (streams) devices. */



reply via email to

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