[Nagios-devel] PATCH: /cgi/cmd.c -> string_to_time()

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: /cgi/cmd.c -> string_to_time()

Post by Guest »

This is a multi-part message in MIME format.
--------------010001050801060609030704
Content-Type: multipart/alternative;
boundary="------------040905000006080103050506"


--------------040905000006080103050506
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi

If user submits time with bad format (e.g. Re-schedule the next check
for this host) there is no checking function for that.
Even in this case the input string is evaluated as "OK".

I've attached little fix for $SUBJECT.

kind regards,

Mizu




--------------040905000006080103050506
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit







Hi

  If user submits time
with bad format (e.g. Re-schedule the next check for
this host) there is no checking function
for that.
Even in this case the input string is evaluated as "OK".

I've
attached little fix for $SUBJECT.

kind
regards,

               
Mizu







--------------040905000006080103050506--

--------------010001050801060609030704
Content-Type: text/x-patch;
name="cmd.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="cmd.c.diff"

--- cmd-orig.c 2006-05-19 14:25:03.000000000 +0000
+++ cmd.c 2007-02-19 11:28:57.000000000 +0000
@@ -1544,7 +1544,7 @@
/* make sure we have check time (if necessary) */
if(cmd==CMD_SCHEDULE_SVC_CHECK && start_time==(time_t)0){
if(!error_string)
- error_string=strdup("Start time must be non-zero");
+ error_string=strdup("Start time must be non-zero or bad format has been submitted.");
}

/* make sure we have start/end times for downtime (if necessary) */
@@ -1649,7 +1649,7 @@
/* make sure we have check time (if necessary) */
if((cmd==CMD_SCHEDULE_HOST_CHECK || cmd==CMD_SCHEDULE_HOST_SVC_CHECKS)&& start_time==(time_t)0){
if(!error_string)
- error_string=strdup("Start time must be non-zero");
+ error_string=strdup("Start time must be non-zero or bad format has been submitted.");
}

/* make sure we have passive check info (if necessary) */
@@ -2684,6 +2684,7 @@
/* converts a time string to a UNIX timestamp, respecting the date_format option */
int string_to_time(char *buffer, time_t *t){
struct tm lt;
+ int ret=0;


/* Initialize some variables just in case they don't get parsed
@@ -2700,12 +2701,16 @@
lt.tm_wday=0;
lt.tm_yday=0;

+
if(date_format==DATE_FORMAT_EURO)
- sscanf(buffer,"%02d-%02d-%04d %02d:%02d:%02d",&lt.tm_mday,&lt.tm_mon,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+ ret=sscanf(buffer,"%02d-%02d-%04d %02d:%02d:%02d",&lt.tm_mday,&lt.tm_mon,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
else if(date_format==DATE_FORMAT_ISO8601 || date_format==DATE_FORMAT_STRICT_ISO8601)
- sscanf(buffer,"%04d-%02d-%02d%*[ T]%02d:%02d:%02d",&lt.tm_year,&lt.tm_mon,&lt.tm_mday,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+ ret=sscanf(buffer,"%04d-%02d-%02d%*[ T]%02d:%02d:%02d",&lt.tm_year,&lt.tm_mon,&lt.tm_mday,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
else
- sscanf(buffer,"%02d-%02d-%04d %02d:%02d:%02d",&lt.tm_mon,&lt.tm_mday,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+ ret=sscanf(buffer,"%02d-%02d-%04d %02d:%02d:%02d",&lt.tm_mon,&lt.tm_mday,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+
+ if (ret!=6)
+ return ERROR;

lt.tm_mon--;
lt.tm_year-=1900;

--------------010001050801060609

...[email truncated]...


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