From 31ce070c297753f576d0d1e76c69ac9ba91c6763 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 11 Oct 2024 13:33:46 -0700 Subject: [PATCH] server: check SHELL if (and only if) neither --sh nor --csh is specified The previous check was checking if the enums returned by getopt were non-zero, which they always are, regardless of whether the option has been specified or not. Fixes: e7d1c91 ("server: Check SHELL only when neither --sh nor --csh is specified") Signed-off-by: Alan Coopersmith --- p11-kit/server.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/p11-kit/server.c b/p11-kit/server.c index 05302d73..553ed02b 100644 --- a/p11-kit/server.c +++ b/p11-kit/server.c @@ -213,7 +213,7 @@ static bool need_children_cleanup = false; static bool terminate = false; static unsigned children_avail = 0; static bool quiet = false; -static bool csh_opt = false; +static int shell_opt = 0; #define P11_KIT_SERVER_ADDRESS_ENV "P11_KIT_SERVER_ADDRESS" #define P11_KIT_SERVER_PID_ENV "P11_KIT_SERVER_PID" @@ -502,7 +502,7 @@ server_loop (Server *server, close (STDOUT_FILENO); } if (pid != 0) { - if (!print_environment (pid, server, csh_opt)) + if (!print_environment (pid, server, shell_opt == 'c')) return 1; exit (0); } @@ -536,7 +536,7 @@ server_loop (Server *server, /* for testing purposes, even when started in foreground, * print the envvars */ if (foreground) { - if (!print_environment (getpid (), server, csh_opt)) + if (!print_environment (getpid (), server, shell_opt == 'c')) return 1; fflush (stdout); } @@ -763,10 +763,10 @@ main (int argc, kill_opt = true; break; case opt_csh: - csh_opt = true; + shell_opt = opt_csh; break; case opt_sh: - csh_opt = false; + shell_opt = opt_sh; break; case opt_help: case '?': @@ -786,12 +786,12 @@ main (int argc, return 2; } - if (!opt_sh && !opt_csh) { + if (!shell_opt) { const char *shell = secure_getenv ("SHELL"); size_t len; if (shell != NULL && (len = strlen (shell)) > 2 && strncmp (shell + len - 3, "csh", 3) == 0) - csh_opt = true; + shell_opt = opt_csh; } if (kill_opt) { @@ -815,7 +815,7 @@ main (int argc, exit (1); } - if (csh_opt) { + if (shell_opt == opt_csh) { printf ("unsetenv %s;\n", P11_KIT_SERVER_ADDRESS_ENV); printf ("unsetenv %s;\n",