[Nagios-devel] [PATCH] send_nsca segfault on timeout

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] [PATCH] send_nsca segfault on timeout

Post by Guest »


--yEPQxsgoJgBvi8ip
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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

--yEPQxsgoJgBvi8ip
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nsca-timeout.diff"

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 does not define.])
+ ],[
+ #if HAVE_SIGNAL_H
+ #include
+ #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);

--yEPQxsgoJgBvi8ip--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked