From 9fc8320fc39616e034b6c73cbbb49c9a0c493dfb Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 21 Mar 2020 14:45:03 +0000 Subject: [PATCH] uxpty: handle $SHELL not being set. This is unlikely in most situations, but 'psusan' in particular is intended to be run in a lot of weird environments where things aren't properly set up yet. I just found out that if you use a Cygwin-built psusan as the proxy process for Windows PuTTY (to get a local Cygwin xterm) then it starts up with SHELL unset, and uxpty's forked subprocess segfaults when it tries to exec a null pointer. --- unix/uxpty.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/unix/uxpty.c b/unix/uxpty.c index e0a492e5..e2a11444 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1208,16 +1208,18 @@ Backend *pty_backend_create( execl(shell, shell, "-c", cmd, (void *)NULL); } } else { - char *shell = getenv("SHELL"); + const char *shell = getenv("SHELL"); + if (!shell) + shell = "/bin/sh"; char *shellname; if (conf_get_bool(conf, CONF_login_shell)) { - char *p = strrchr(shell, '/'); + const char *p = strrchr(shell, '/'); shellname = snewn(2+strlen(shell), char); p = p ? p+1 : shell; sprintf(shellname, "-%s", p); } else - shellname = shell; - execl(getenv("SHELL"), shellname, (void *)NULL); + shellname = (char *)shell; + execl(shell, shellname, (void *)NULL); } /*