patch: small segfault fixes
Andreas Ericsson
ae at op5.se
Sat Sep 11 23:03:49 CEST 2004
Matthew Kent wrote:
> Couple tiny fixes for latest copy in cvs. Fixes a segfault I was getting
> for not having host_perfdata_file/service_perfata_file defined in my
> nagios.cfg
>
Won't this cause segfault when the macro is actually substituted, seeing
as it will be set to either an invalid address or a NULL pointer?
Add an else clause with
str = malloc(1);
memset(str, 0, 1);
(where str is whatever variable we're talking about here) and the macro
should simply be removed. I don't know what impact that will have on
'surrounding' scripts, but that's for the script hackers to fix, I'd say.
It might be easier to just loop the entire macro_x tree and set all NULL
pointers to the void string after the table is loaded.
>
>
> ------------------------------------------------------------------------
>
> diff -u3r nagios_orig/base/utils.c nagios/base/utils.c
> --- nagios_orig/base/utils.c 2004-09-02 20:53:00.000000000 -0400
> +++ nagios/base/utils.c 2004-09-11 13:31:16.000000000 -0400
> @@ -2717,7 +2717,7 @@
> run_time-=3600;
>
> #ifdef DEBUG1
> - printf("\tNext Log Rotation Time: %s",ctime(run_time));
> + printf("\tNext Log Rotation Time: %s",ctime((time_t*) run_time));
> #endif
>
> #ifdef DEBUG0
> diff -u3r nagios_orig/xdata/xpddefault.c nagios/xdata/xpddefault.c
> --- nagios_orig/xdata/xpddefault.c 2004-09-02 20:53:00.000000000 -0400
> +++ nagios/xdata/xpddefault.c 2004-09-11 14:27:39.000000000 -0400
> @@ -181,14 +181,16 @@
> /* save the host perf data file macro */
> if(macro_x[MACRO_HOSTPERFDATAFILE]!=NULL)
> free(macro_x[MACRO_HOSTPERFDATAFILE]);
> - macro_x[MACRO_HOSTPERFDATAFILE]=(char *)strdup(xpddefault_host_perfdata_file);
> + if (xpddefault_host_perfdata_file!=NULL)
> + macro_x[MACRO_HOSTPERFDATAFILE]=(char *)strdup(xpddefault_host_perfdata_file);
> if(macro_x[MACRO_HOSTPERFDATAFILE]!=NULL)
> strip(macro_x[MACRO_HOSTPERFDATAFILE]);
>
> /* save the service perf data file macro */
> if(macro_x[MACRO_SERVICEPERFDATAFILE]!=NULL)
> free(macro_x[MACRO_SERVICEPERFDATAFILE]);
> - macro_x[MACRO_SERVICEPERFDATAFILE]=(char *)strdup(xpddefault_service_perfdata_file);
> + if (xpddefault_service_perfdata_file!=NULL)
> + macro_x[MACRO_SERVICEPERFDATAFILE]=(char *)strdup(xpddefault_service_perfdata_file);
> if(macro_x[MACRO_SERVICEPERFDATAFILE]!=NULL)
> strip(macro_x[MACRO_SERVICEPERFDATAFILE]);
>
--
Andreas Ericsson andreas.ericsson at op5.se
OP5 AB www.op5.se
Lead Developer
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
More information about the Developers
mailing list