[icinga-checkins] icinga.org: icinga-core/mfriedrich/workers: libicinga: fix faulty brackets in kvvec; possible segfault on worker_result_handler [ WIP]

git at icinga.org git at icinga.org
Sun Aug 5 23:32:13 CEST 2012


Module: icinga-core
Branch: mfriedrich/workers
Commit: 8bfadf52654c29b28f338d261bec70e06bc6f052
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=8bfadf52654c29b28f338d261bec70e06bc6f052

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Aug  5 23:27:45 2012 +0200

libicinga: fix faulty brackets in kvvec; possible segfault on worker_result_handler [WIP]

refs #2961
refs #2955

---

 base/utils.c  |   10 ++++++----
 lib/iocache.c |    6 +++---
 lib/kvvec.c   |    7 ++++---
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/base/utils.c b/base/utils.c
index e25951b..e8ab18e 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -2445,14 +2445,15 @@ int process_check_result_queue(char *dirname) {
 		return ERROR;
 	}
 
+	log_debug_info(DEBUGL_CHECKS, 1, "Starting to read check result queue '%s'...\n", dirname);
+
 	/* open the directory for reading */
 	if ((dirp = opendir(dirname)) == NULL) {
 		logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not open check result queue directory '%s' for reading.\n", dirname);
+		log_debug_info(DEBUGL_CHECKS, 1, "Error: Could not open check result queue directory '%s' for reading.\n", dirname);
 		return ERROR;
 	}
 
-	log_debug_info(DEBUGL_CHECKS, 1, "Starting to read check result queue '%s'...\n", dirname);
-
 	start = time(NULL);
 
 	/* process all files in the directory... */
@@ -2465,8 +2466,9 @@ int process_check_result_queue(char *dirname) {
 		}
 
 		/* break out if we've been here too long */
-		if ((int)(time(NULL) - start) < max_check_reaper_time) {
-			log_debug_info(DEBUGL_CHECKS, 0, "Breaking out of check result reaper: max time exceeded\n");
+		int reap_time = (int)(time(NULL) - start);
+		if (reap_time > max_check_reaper_time) {
+			log_debug_info(DEBUGL_CHECKS, 0, "Breaking out of check result reaper: max time (%d<%d) exceeded\n", (int)(time(NULL) - start), max_check_reaper_time);
 			break;
 		}
 
diff --git a/lib/iocache.c b/lib/iocache.c
index ce38c70..1d4b127 100644
--- a/lib/iocache.c
+++ b/lib/iocache.c
@@ -215,8 +215,8 @@ int iocache_add (iocache *ioc, char *buf, unsigned int len) {
 	if (!ioc || iocache_capacity(ioc) < len)
 		return -1;
 
-	memcpy (ioc->ioc_buf + ioc->ioc_offset, buf, len);
-	ioc->ioc_buflen +=len;
+	memcpy(ioc->ioc_buf + ioc->ioc_offset, buf, len);
+	ioc->ioc_buflen += len;
 
 	return ioc->ioc_buflen - ioc->ioc_offset;
 }
@@ -227,7 +227,7 @@ int iocache_add (iocache *ioc, char *buf, unsigned int len) {
  *  - iocache has data, bug doesn't
  *  - both buf and iocache have data
  */
-int iocache_sendto (iocache *ioc, int fd, char *buf, unsigned int len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
+int iocache_sendto(iocache *ioc, int fd, char *buf, unsigned int len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
 	int sent;
 
 	errno = 0;
diff --git a/lib/kvvec.c b/lib/kvvec.c
index 6e32ea1..f871c6c 100644
--- a/lib/kvvec.c
+++ b/lib/kvvec.c
@@ -65,6 +65,7 @@ int kvvec_resize(struct kvvec *kvv, int hint) {
 
 	if (!kvv)
 		return -1;
+
 	if (hint <= kvv->kv_alloc)
 		return 0;
 
@@ -170,11 +171,11 @@ void kvvec_free_kvpairs(struct kvvec *kvv, int flags) {
 			free(kvv->kv[i].key);
 			free(kvv->kv[i].value);
 		}
-	} else if (flags == KVVEC_FREE_KEYS)
+	} else if (flags == KVVEC_FREE_KEYS) {
 		for (i = 0; i < kvv->kv_pairs; i++) {
 			free(kvv->kv[i].key);
 		}
-	else if (flags == KVVEC_FREE_VALUES) {
+	} else if (flags == KVVEC_FREE_VALUES) {
 		for (i = 0; i < kvv->kv_pairs; i++) {
 			free(kvv->kv[i].value);
 		}
@@ -280,7 +281,7 @@ int buf2kvvec_prealloc(struct kvvec *kvv, char *str,
 	/* make sure the key/value vector is large enough */
 	if (!(flags & KVVEC_APPEND)) {
 		kvvec_init(kvv, num_pairs);
-	} else if (kvvec_capacity(kvv) < num_pairs && kvvec_resize(kvv, num_pairs < 0)) {
+	} else if (kvvec_capacity(kvv) < num_pairs && kvvec_resize(kvv, num_pairs) < 0) {
 		return -1;
 	}
 





More information about the icinga-checkins mailing list