Skip to content

Commit

Permalink
Don't depend on getenv being reentrant in ssh.c.
Browse files Browse the repository at this point in the history
This is likely a standards bug and getenv should be re-entrant (it
should, after all, also be threadsafe if no one is writing to the
environment), but it didn't cost much to work around it.
  • Loading branch information
ericonr committed Mar 11, 2021
1 parent 46ea87e commit aa2817d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

void print_ssh(void)
{
/* expect ssh to have set these variables - we don't need to prompt if not using a tty */
const char *sshcon = getenv("SSH_CONNECTION"), *sshtty = getenv("SSH_TTY");
const char *sshcon, *sshtty;

if (sshcon && *sshcon && sshtty && *sshtty) {
/* expect ssh to have set these variables - we don't need to prompt if not using a tty.
* we do the conditional like this because getenv is not guaranteed to be re-entrant */
if ((sshcon = getenv("SSH_CONNECTION")) && *sshcon &&
(sshtty = getenv("SSH_TTY")) && *sshtty) {
struct utsname u;
/* don't print anything if uname fails or nodename is empty */
if (uname(&u) || !u.nodename[0])
Expand Down

0 comments on commit aa2817d

Please sign in to comment.