[PATCH] send_nsca segfault on timeout
Holger Weiss
holger at CIS.FU-Berlin.DE
Wed Jan 9 20:52:10 CET 2008
If send_nsca runs into the timeout while it's in encrypt_init(), it can
segfault because encrypt_cleanup() (which is called from the signal
handler) calls mcrypt_generic_end() although mcrypt_generic_init()
wasn't done yet. This happens every now and then for us, for some
reason send_nsca sometimes timeouts while it's in mcrypt_generic_init().
The attached patch checks whether mcrypt_generic_init() was called
before calling mcrypt_generic_end().
Holger
-------------- next part --------------
Index: configure.in
===================================================================
RCS file: /cvsroot/nagios/nsca/configure.in,v
retrieving revision 1.22
diff -u -r1.22 configure.in
--- configure.in 23 Nov 2007 17:32:14 -0000 1.22
+++ configure.in 9 Jan 2008 19:42:21 -0000
@@ -32,6 +32,7 @@
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
+AC_C_VOLATILE
AC_STRUCT_TM
AC_TYPE_MODE_T
AC_TYPE_PID_T
@@ -92,6 +93,16 @@
AC_SUBST(LIBWRAPLIBS)
AC_CHECK_FUNCS(strdup strstr strtoul)
+dnl Define sig_atomic_t to int if it's not available.
+AC_CHECK_TYPE([sig_atomic_t],[],[
+ AC_DEFINE([sig_atomic_t],[int],
+ [Define to 'int' if <signal.h> does not define.])
+ ],[
+ #if HAVE_SIGNAL_H
+ #include <signal.h>
+ #endif
+ ])
+
dnl socklen_t check - from curl
AC_CHECK_TYPE([socklen_t], ,[
AC_MSG_CHECKING([for socklen_t equivalent])
Index: src/utils.c
===================================================================
RCS file: /cvsroot/nagios/nsca/src/utils.c,v
retrieving revision 1.6
diff -u -r1.6 utils.c
--- src/utils.c 2 Feb 2006 18:45:06 -0000 1.6
+++ src/utils.c 9 Jan 2008 19:42:21 -0000
@@ -36,6 +36,9 @@
/*#define DEBUG*/
static unsigned long crc32_table[256];
+#ifdef HAVE_LIBMCRYPT
+static volatile sig_atomic_t mcrypt_initialized=FALSE;
+#endif
@@ -235,7 +238,7 @@
/* initialize encryption buffers */
mcrypt_generic_init(CI->td,CI->key,CI->keysize,CI->IV);
-
+ mcrypt_initialized=TRUE;
#endif
return OK;
@@ -253,7 +256,8 @@
#ifdef HAVE_LIBMCRYPT
/* mcrypt cleanup */
if(encryption_method!=ENCRYPT_NONE && encryption_method!=ENCRYPT_XOR){
- mcrypt_generic_end(CI->td);
+ if(mcrypt_initialized==TRUE)
+ mcrypt_generic_end(CI->td);
free(CI->key);
CI->key=NULL;
free(CI->IV);
-------------- next part --------------
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel
More information about the Developers
mailing list