summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2024-08-21 14:41:13 -0700
committerNobuyoshi Nakada <[email protected]>2024-08-22 11:20:47 +0900
commita3f5a043fa5b3cb9ae1c684708399f26716ae451 (patch)
treedc244f14ef8fc6c529a2922718bfb76808cbf17d
parentae886e0c83c0e3a3c838f48fb91efe253c027c6d (diff)
Handle getlogin failure in PTY.spawn
getlogin is only called if USER environment variable is not set, but if getlogin returns NULL in that case, then do not call getpwnam, and assume /bin/sh as shell. Mentioned in comment to bug 20586.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11427
-rw-r--r--ext/pty/pty.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 5ca55e41d6..49caa0b79f 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -215,9 +215,13 @@ establishShell(int argc, VALUE *argv, struct pty_info *info,
else {
#if defined HAVE_PWD_H
const char *username = getenv("USER");
- struct passwd *pwent = getpwnam(username ? username : getlogin());
- if (pwent && pwent->pw_shell)
- shellname = pwent->pw_shell;
+ if (username == NULL)
+ username = getlogin();
+ if (username != NULL) {
+ struct passwd *pwent = getpwnam(username);
+ if (pwent && pwent->pw_shell)
+ shellname = pwent->pw_shell;
+ }
#endif
}
v = rb_str_new2(shellname);