From 32d1b967fcbcd5ea3b906d256b1041da3df6441b Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 17 Jul 2026 21:56:23 +0000 Subject: [PATCH] Ensure vars updated by signal handlers are volatile and atomic. Fixes #2245 --- ncat/ncat_listen.c | 2 +- ncat/ncat_posix.c | 2 +- ncat/ncat_proxy.c | 2 ++ nmap_tty.cc | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 503733281..be476980f 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -146,7 +146,7 @@ static char *chat_filter(char *buf, size_t size, int fd, int *nwritten); (synchronously) only in the main program. get_conn_count loops while conn_dec is being modified. */ static unsigned int conn_inc = 0; -static volatile unsigned int conn_dec = 0; +static volatile sig_atomic_t conn_dec = 0; static volatile sig_atomic_t conn_dec_changed; static void decrease_conn_count(void) diff --git a/ncat/ncat_posix.c b/ncat/ncat_posix.c index b980482bc..25a4fda3d 100644 --- a/ncat/ncat_posix.c +++ b/ncat/ncat_posix.c @@ -66,7 +66,7 @@ char **cmdline_split(const char *cmdexec); -static int child_alive = 0; +volatile sig_atomic_t child_alive = 0; static void sigchld_watcher(int signum) { diff --git a/ncat/ncat_proxy.c b/ncat/ncat_proxy.c index e58f785ca..327dcf309 100644 --- a/ncat/ncat_proxy.c +++ b/ncat/ncat_proxy.c @@ -72,8 +72,10 @@ /* SIG_CHLD handler */ static void proxyreaper(int signo) { + int saved_errno = errno; while (waitpid(-1, NULL, WNOHANG) > 0) ; + errno = saved_errno; } #endif diff --git a/nmap_tty.cc b/nmap_tty.cc index 50cc3ca45..7ada19e36 100644 --- a/nmap_tty.cc +++ b/nmap_tty.cc @@ -125,7 +125,7 @@ extern int tcsetattr(int fd, int actions, struct termios *termios_p); #endif #endif -static int tty_fd = 0; +static volatile sig_atomic_t tty_fd = 0; static struct termios saved_ti; static int tty_getchar()