From: Frédéric Marchal Date: Sun, 26 Aug 2012 09:44:10 +0000 (+0200) Subject: Validate the entry time from the input log X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7dbbca70a2dd10bab69a5b2269623439269ba33f;p=thirdparty%2Fsarg.git Validate the entry time from the input log The date and time found in the input log file are validated. Moreover, additional fields such as the week day are computed. --- diff --git a/readlog_common.c b/readlog_common.c index 5cd1074..b05e4cb 100644 --- a/readlog_common.c +++ b/readlog_common.c @@ -128,6 +128,7 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru Entry->EntryTime.tm_hour=Hour; Entry->EntryTime.tm_min=Minute; Entry->EntryTime.tm_sec=Second; + Entry->EntryTime.tm_isdst=-1; // the URL is enclosed between double qhotes ++Line; @@ -163,6 +164,12 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru while (isdigit(*Line)) Entry->DataSize=Entry->DataSize*10+(*Line++-'0'); if (*Line!=' ' || Begin==Line) return(RLRC_Unknown); + // check the entry time + if (mktime(&Entry->EntryTime)==-1) { + debuga(_("Invalid date or time found in the common log file\n")); + return(RLRC_InternalError); + } + // it is safe to alter the line buffer now that we are returning a valid entry Entry->Ip[IpLen]='\0'; Entry->HttpCode[HttpCodeLen]='\0'; diff --git a/readlog_sarg.c b/readlog_sarg.c index 015b2d6..b00dfe8 100644 --- a/readlog_sarg.c +++ b/readlog_sarg.c @@ -104,6 +104,7 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct Entry->EntryTime.tm_hour=Hour; Entry->EntryTime.tm_min=Minute; Entry->EntryTime.tm_sec=Second; + Entry->EntryTime.tm_isdst=-1; // the ID of the user Entry->User=++Line; @@ -138,7 +139,14 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct if (*Line!='\t' || Line==Begin) return(RLRC_Unknown); // get the smart filter - + //! \bug Smart filter ignored from sarg log format. + + // check the entry time + if (mktime(&Entry->EntryTime)==-1) { + debuga(_("Invalid date or time found in the common log file\n")); + return(RLRC_InternalError); + } + // it is safe to alter the line buffer now that we are returning a valid entry Entry->Ip[IpLen]='\0'; Entry->HttpCode[HttpCodeLen]='\0';