Page 1 of 1

[PATCH] fix save_custom_variables o_id type, size of es array

Posted: Thu Feb 11, 2010 10:59 pm
by Guest
This is a multi-part message in MIME format.
--------------080600050905020703020700
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

I recently ran into those problems and fixed them in IDOUtils. I thought
it would be nice to get them resolved in NDOUtils too.

1/ There was a patch regarding save custom variables function, which
takes o_id as argument of type int. This is wrong because internal
handling of this variable is unsigned long - handed over to function
call and internally used as asprintf %lu too. This patch fixes that.

2/ Having custom variables defined, they will be written to the
database. There are two handlers for es[] - es[0] and es[1]. But the
definition only defines size 1, not 2. When writing es[1] = ... this
will lead to a segfault of ndo2db causing ndomod to produce "error
writing to datasink" outputs in syslog.

By applying this fix, those issues will resolve.
Attached is a git diff patch (I don't use cvs).

Kind regards,
Michael



--------------080600050905020703020700
Content-Type: text/x-diff;
name="0001-fix-save_custom_variables-o_id-type-size-of-es-arra.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename*0="0001-fix-save_custom_variables-o_id-type-size-of-es-arra.pat";
filename*1="ch"

From 255353cbeafc7b0bdd8bd28df97cc87aea94bd57 Mon Sep 17 00:00:00 2001
From: Michael Friedrich
Date: Thu, 11 Feb 2010 23:50:08 +0100
Subject: [PATCH] fix save_custom_variables o_id type, size of es array

* o_id is unsigned long, not int
* array size of es must be 2
when trying to write es[1] ndo2db segfaults, resulting
in "error writing to datasink" of ndomod
---
include/dbhandlers.h | 2 +-
src/dbhandlers.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/dbhandlers.h b/include/dbhandlers.h
index 2ca2b85..3605bb4 100644
--- a/include/dbhandlers.h
+++ b/include/dbhandlers.h
@@ -70,5 +70,5 @@ int ndo2db_handle_commanddefinition(ndo2db_idi *);
int ndo2db_handle_timeperiodefinition(ndo2db_idi *);
int ndo2db_handle_contactdefinition(ndo2db_idi *);
int ndo2db_handle_contactgroupdefinition(ndo2db_idi *);
-int ndo2db_save_custom_variables(ndo2db_idi *,int, int, char *);
+int ndo2db_save_custom_variables(ndo2db_idi *,int, unsigned long, char *);
#endif
diff --git a/src/dbhandlers.c b/src/dbhandlers.c
index fa17180..2e03092 100644
--- a/src/dbhandlers.c
+++ b/src/dbhandlers.c
@@ -4929,11 +4929,11 @@ int ndo2db_handle_contactgroupdefinition(ndo2db_idi *idi){
return NDO_OK;
}

-int ndo2db_save_custom_variables(ndo2db_idi *idi,int table_idx, int o_id, char *ts ){
+int ndo2db_save_custom_variables(ndo2db_idi *idi,int table_idx, unsigned long o_id, char *ts ){
char *buf=NULL;
char *buf1=NULL;
ndo2db_mbuf mbuf;
- char *es[1];
+ char *es[2];
char *ptr1=NULL;
char *ptr2=NULL;
char *ptr3=NULL;
--
1.5.5.6


--------------080600050905020703020700--





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