[Nagios-devel] [PATCH] xodtemplate: Fix obscure crash while loading

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] xodtemplate: Fix obscure crash while loading

Post by Guest »

From: Robin Sonefors

We didn't initialize parent_map, meaning that it could have any value,
even though it appears it is not infrequently NULL, at least at first.

We then pointed it to a bitmap object iff
xodtemplate_servicedependency_list wasn't NULL, and finally freed it
unconditionally.

Thus, unless parent_map pointed at NULL or we have servicedependencies,
we'd get a crash.

Now, if we first add at least one servicedependency, run nagios, remove
all of them, and reload nagios, parent_map would still keep its old
value around, we wouldn't reallocate it, but we'd still free it, leading
to a crash.

This is prevented in the following ways:
* First, make sure all bitmaps are NULL-initialized, clearly and
obviously.
* Second, only free parent_map if we did set it.
* Third, set parent_map to NULL after we destroy() it - dangling
pointers are evil.

Signed-off-by: Robin Sonefors
---
xdata/xodtemplate.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index 5b3a099..34da566 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -118,9 +118,9 @@ static struct object_count xodcount;

#ifndef NSCGI
/* reusable bitmaps for expanding objects */
-static bitmap *host_map, *contact_map;
+static bitmap *host_map = NULL, *contact_map = NULL;
#endif
-static bitmap *service_map, *parent_map;
+static bitmap *service_map = NULL, *parent_map = NULL;


/*
@@ -6901,18 +6901,19 @@ int xodtemplate_register_objects(void) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Failed to create parent bitmap for service dependencies\n");
return ERROR;
}
- }
- for(sd = xodtemplate_servicedependency_list; sd; sd = next_sd) {
- next_sd = sd->next;
+ for(sd = xodtemplate_servicedependency_list; sd; sd = next_sd) {
+ next_sd = sd->next;
#ifdef NSCGI
- if(xodtemplate_register_servicedependency(sd) == ERROR)
- return ERROR;
+ if(xodtemplate_register_servicedependency(sd) == ERROR)
+ return ERROR;
#else
- if(xodtemplate_register_and_destroy_servicedependency(sd) == ERROR)
- return ERROR;
+ if(xodtemplate_register_and_destroy_servicedependency(sd) == ERROR)
+ return ERROR;
#endif
+ }
+ bitmap_destroy(parent_map);
+ parent_map = NULL;
}
- bitmap_destroy(parent_map);
timing_point("%u unique / %u total servicedependencies registered\n",
num_objects.servicedependencies, xodcount.servicedependencies);

--
1.7.11.7






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