From 7dbbca70a2dd10bab69a5b2269623439269ba33f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sun, 26 Aug 2012 11:44:10 +0200 Subject: [PATCH] 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. --- readlog_common.c | 7 +++++++ readlog_sarg.c | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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'; -- 2.47.3