Package: nsca
Version: 2.9.1-2
Severity: important
Tags: upstream, patch
Control: found -1 2.7.2
Hi,
I tripped over this bug because send_nsca was SEGVing on a machine
where another high-priority process was chewing up nearly all the
CPU. Our cron scripts just complained about SEGV, but running it on
the console resulted in:
Error: Timeout after 10 seconds
Segmentation fault
On investigation, this is because send_nsca's alarm_handler function
(installed as the handler for SIGALRM) does all sorts of things that
are undefined in a signal handler, such as printf, memset, free.
I attach a simple patch that replaces the buggy signal handler with
one that emits an error message and then exits. I'm not convinced that
there's enough merit in the memory-"cleaning" that do_exit does to do
the harder work of trying to sort that out.
Regards,
Matthew
-- System Information:
Debian Release: 7.4
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 3.2.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages nsca depends on:
ii confget 1.03-1
ii debconf [debconf-2.0] 1.5.49
ii libc6 2.13-38+deb7u1
ii libmcrypt4 2.5.8-3.1
ii nsca-client 2.9.1-2
nsca recommends no packages.
Versions of packages nsca suggests:
pn nagios-plugins-basic | nagios-plugins <none>
pn nagios3 <none>
-- debconf information excluded
diff -ruN nsca-2.9.1/src/send_nsca.c nsca-2.9.1-mcv/src/send_nsca.c
--- nsca-2.9.1/src/send_nsca.c 2012-01-27 13:20:58.000000000 +0000
+++ nsca-2.9.1-mcv/src/send_nsca.c 2014-04-03 12:54:55.449140814 +0100
@@ -467,10 +467,11 @@
/* handle timeouts */
void alarm_handler(int sig){
+ static const char message[] = "Error: Timeout\n";
- printf("Error: Timeout after %d seconds\n",socket_timeout);
+ write(stderr,message,sizeof(message) - 1);
- do_exit(STATE_CRITICAL);
+ _exit(STATE_CRITICAL);
}