Title: [opsview] [5351] Fixed nagios SEGV when removing some downtimes
Revision
5351
Author
dferguson
Date
2010-11-12 13:55:04 +0000 (Fri, 12 Nov 2010)

Log Message

Fixed nagios SEGV when removing some downtimes

Attempting to remove downtime using API commands CMD_DEL_HOST_DOWNTIME, CMD_DEL_HOST_SVC_DOWNTIME or CMD_DEL_SVC_DOWNTIME and using an IP address instead of a hostname or downtime id causes a SEGV

Modified Paths

Added Paths

Modified: trunk/opsview-base/Makefile
===================================================================
--- trunk/opsview-base/Makefile	2010-11-12 13:55:00 UTC (rev 5350)
+++ trunk/opsview-base/Makefile	2010-11-12 13:55:04 UTC (rev 5351)
@@ -452,6 +452,8 @@
 	# Below in Nagios 3.2.4+
 	cd ${NAGIOS} && patch -p1 < ../patches/nagios_extinfo_tidyups.patch
 	cd ${NAGIOS} && patch -p1 < ../patches/nagios_test_events_more_tolerant.patch
+	cd ${NAGIOS} && patch -p1 < ../patches/nagios_remove_downtime_by_name_causes_SEGV.patch
+	cd ${NAGIOS} && cp ../patches/nagios_test_strtoul.c t-tap/test_strtoul.c
 	if [ `uname -s` = Linux ] ; then \
 		cd ${NAGIOS} && CFLAGS="${CFLAGS}" ./configure --with-nagios-user=$(NAGIOS_USER) --with-nagios-group=$(NAGIOS_GROUP) --with-command-group=$(NAGIOS_GROUP) --with-cgiurl=/cgi-bin --with-htmurl=/ --enable-libtap ; \
 	elif [ `uname -s` = Darwin ] ; then \

Added: trunk/opsview-base/patches/nagios_remove_downtime_by_name_causes_SEGV.patch
===================================================================
--- trunk/opsview-base/patches/nagios_remove_downtime_by_name_causes_SEGV.patch	                        (rev 0)
+++ trunk/opsview-base/patches/nagios_remove_downtime_by_name_causes_SEGV.patch	2010-11-12 13:55:04 UTC (rev 5351)
@@ -0,0 +1,55 @@
+diff -ur nagios-3.2.3.orig/base/commands.c nagios-3.2.3/base/commands.c
+--- nagios-3.2.3.orig/base/commands.c	2010-11-12 09:35:35.000000000 +0000
++++ nagios-3.2.3/base/commands.c	2010-11-12 12:20:31.000000000 +0000
+@@ -2594,6 +2594,7 @@
+ int cmd_delete_downtime(int cmd, char *args){
+ 	unsigned long downtime_id=0L;
+ 	char *temp_ptr=NULL;
++	char *end_ptr=NULL;
+ 	char *hostgroup_name=NULL;
+ 	host *temp_host=NULL;
+ 	hostgroup *temp_hostgroup=NULL;
+@@ -2609,8 +2610,8 @@
+ 		if(temp_ptr==NULL)
+ 			return ERROR;
+ 
+-		downtime_id=strtoul(temp_ptr,NULL,10);
+-		if(downtime_id == 0) {
++		downtime_id=strtoul(temp_ptr,&end_ptr,10);
++		if(downtime_id == 0 || strlen(end_ptr) != 0) {
+ 			temp_host=find_host(temp_ptr);
+ 			if(temp_host==NULL)
+ 				return ERROR;
+@@ -2623,8 +2624,8 @@
+         if(temp_ptr==NULL) {
+             return ERROR;
+         } else {
+-            downtime_id=strtoul(temp_ptr,NULL,10);
+-            if(downtime_id == 0) {
++            downtime_id=strtoul(temp_ptr,&end_ptr,10);
++            if(downtime_id == 0 || strlen(end_ptr) != 0) {
+                 temp_host=find_host(temp_ptr);
+                 if(temp_host==NULL)
+                     return ERROR;
+diff -ur nagios-3.2.3.orig/t-tap/Makefile.in nagios-3.2.3/t-tap/Makefile.in
+--- nagios-3.2.3.orig/t-tap/Makefile.in	2010-05-07 11:45:20.000000000 +0000
++++ nagios-3.2.3/t-tap/Makefile.in	2010-11-12 12:16:20.000000000 +0000
+@@ -11,7 +11,7 @@
+ c...@cc@
+ cfla...@cflags@ @DEFS@ -DNSCORE -I../include -I../tap/src
+ 
+-TESTS = test_logging test_events test_timeperiods test_nagios_config test_xsddefault
++TESTS = test_logging test_events test_timeperiods test_nagios_config test_xsddefault test_strtoul
+ 
+ test_xsddefault_OBJS = ${SRC_CGI}/xstatusdata-cgi.o ${SRC_CGI}/cgiutils.o ${SRC_CGI}/comments-cgi.o ${SRC_CGI}/objects-cgi.o ${SRC_CGI}/skiplist.o ${SRC_CGI}/statusdata-cgi.o ${SRC_CGI}/downtime-cgi.o ${SRC_CGI}/xobjects-cgi.o
+ test_nagios_config_OBJS = $(SRC_BASE)/utils.o ${SRC_BASE}/config.o ${SRC_BASE}/macros-base.o ${SRC_BASE}/objects-base.o ${SRC_BASE}/skiplist.o ${SRC_BASE}/xobjects-base.o ${SRC_BASE}/retention-base.o ${SRC_BASE}/xretention-base.o ${SRC_BASE}/comments-base.o ${SRC_BASE}/downtime-base.o ${SRC_BASE}/xdowntime-base.o ${SRC_BASE}/xcomments-base.o
+@@ -91,6 +91,9 @@
+ test_xsddefault: test_xsddefault.c ${test_xsddefault_OBJS}
+ 	$(CC) $(CFLAGS) -o $@ test_xsddefault.c $(TAPOBJ) ${test_xsddefault_OBJS}
+ 
++test_strtoul: test_strtoul.c
++	$(CC) $(CFLAGS) -o $@ test_strtoul.c $(TAPOBJ)
++
+ test: $(TESTS)
+ 	HARNESS_PERL=./test_each.t perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map { "./$$_" } @ARGV)' $(TESTS)
+ 

Added: trunk/opsview-base/patches/nagios_test_strtoul.c
===================================================================
--- trunk/opsview-base/patches/nagios_test_strtoul.c	                        (rev 0)
+++ trunk/opsview-base/patches/nagios_test_strtoul.c	2010-11-12 13:55:04 UTC (rev 5351)
@@ -0,0 +1,65 @@
+/*****************************************************************************
+*
+* test_strtoul.c - Test strtoul function for downtime
+*
+* Program: Nagios Core Testing
+* License: GPL
+* Copyright (c) 2009 Nagios Core Development Team and Community Contributors
+* Copyright (c) 1999-2009 Ethan Galstad
+*
+* First Written:   12-Mov-2010
+* Last Modified:   12-Nov-2010
+*
+* Description:
+*
+* Tests system strtoul - to ensure that it works as expected as some systems 
+* may differ in usage
+*
+* License:
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*
+*****************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include "tap.h"
+
+char *svr_hostname="hostname";
+char *svr_fqdn="hostname.domain.name";
+char *svr_ip="192.168.1.1";
+char *svr_downtime_id="1234";
+char *end_ptr=NULL;
+unsigned long downtime_id=0L;
+
+int main(int argc, char **argv){
+
+    downtime_id=strtoul(svr_hostname,&end_ptr,10);
+    ok( downtime_id == 0, "hostname downtime_id is 0");
+    ok( strlen(end_ptr) == 8, "hostname end_ptr is 8 chars");
+
+    downtime_id=strtoul(svr_fqdn,&end_ptr,10);
+    ok( downtime_id == 0, "fqdn downtime_id is 0");
+    ok( strlen(end_ptr) == 20, "fqdn end_ptr is 20 chars");
+
+    downtime_id=strtoul(svr_ip,&end_ptr,10);
+    ok( downtime_id == 192, "ip downtime_id is 192");
+    ok( strlen(end_ptr) == 8, "ip end_ptr is 8 chars");
+
+    downtime_id=strtoul(svr_downtime_id,&end_ptr,10);
+    ok( downtime_id == 1234, "svr_downtime_id downtime_id is 1234");
+    ok( strlen(end_ptr) == 0, "svr_downtime_id end_ptr is 0 chars");
+
+    return exit_status();
+}

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to