]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Validate the entry time from the input log
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 09:44:10 +0000 (11:44 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 09:44:10 +0000 (11:44 +0200)
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
readlog_sarg.c

index 5cd1074f27c54907e0d9e493ebcaef2add996436..b05e4cb10999c9acbe2aee8ec6c7b3d8394f0a19 100644 (file)
@@ -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';
index 015b2d61af018e7ad830af4b668cf3875691f845..b00dfe8712473391625e3886bf7fbf327c408cc8 100644 (file)
@@ -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';