Segmentation fault when nebmodule returns with something else than 0
Tobias Mucke
tobias.mucke at googlemail.com
Tue Nov 27 08:12:21 CET 2007
Hi list,
found the problem, at least I think to have found the problem.
Actually function neb_set_module_info does not operate on the
nebmodule struct but on the mod_handle it got from its caller. The
latter is from type lt_dlhandle. To set an info of type
NEBMODULE_MODINFO_* does not make sense.
Two problems arose by this and I fall into both. Writing informations
to the module by neb_set_module_info works for some of the
NEBMODULE_MODINFO_*. Some other lead to a segfault. The second problem
is, if you have overwritten the NEBMODULE_MODINFO_TITLE you overwrite
the filename of the lt_dlhandle and the module can't be unloaded
anymore.
I have written a patch. Since I am not a very experienced C programmer
please review it carefully before applying to official Nagios code.
--- nagios-3.0b7/base/nebmods.c 2007-10-22 15:39:30.000000000 +0200
+++ nagios-3.0b7-mod/base/nebmods.c 2007-11-27 07:35:52.000000000 +0100
@@ -338,24 +338,29 @@
/****************************************************************************/
/* sets module information */
-int neb_set_module_info(void *handle, int type, char *data){
- nebmodule *mod=NULL;
+int neb_set_module_info(void *mod_handle, int type, char *data){
+ nebmodule *temp_module = NULL;
- if(handle==NULL)
+ if(mod_handle==NULL)
return NEBERROR_NOMODULE;
/* check type */
if(type<0 || type>=NEBMODULE_MODINFO_NUMITEMS)
return NEBERROR_MODINFOBOUNDS;
- /* get the module */
- mod=(nebmodule *)handle;
+ /* find corresponding nebmodule */
+ for(temp_module=neb_module_list;temp_module;temp_module=temp_module->next){
+ if((void *)temp_module->module_handle == (void *)mod_handle)
+ break;
+ }
+ if(temp_module==NULL)
+ return NEBERROR_BADMODULEHANDLE;
/* free any previously allocated memory */
- my_free(mod->info[type]);
+ my_free(temp_module->info[type]);
/* allocate memory for the new data */
- if((mod->info[type]=(char *)strdup(data))==NULL)
+ if((temp_module->info[type]=(char *)strdup(data))==NULL)
return NEBERROR_NOMEM;
return OK;
Thanks.
Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nebmods.c.patch
Type: text/x-patch
Size: 1247 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20071127/249add79/attachment.bin>
-------------- next part --------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel
More information about the Developers
mailing list