]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix a crash when no log formats are found suitable
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 13:41:52 +0000 (15:41 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 14:00:38 +0000 (16:00 +0200)
If no log formats can decode a line from the input log, an index would
exceed its bound and produce a crash.

readlog.c

index 1543de4bf72a0abcfd8aa35fb9d4de84e0a0a95c..31658304689ca00668cb4627f241f49e40fae129 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -294,15 +294,18 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
 
                        // find out what line format to use
                        if (log_entry_status==RLRC_Unknown) {
-                               x=-1;
-                               while (log_entry_status==RLRC_Unknown && x<(int)(sizeof(LogFormats)/sizeof(*LogFormats))) {
+                               x=0;
+                               while (x<(int)(sizeof(LogFormats)/sizeof(*LogFormats))) {
+                                       if (LogFormats[x]!=current_format)
+                                       {
+                                               memset(&log_entry,0,sizeof(log_entry));
+                                               log_entry_status=LogFormats[x]->ReadEntry(linebuf,&log_entry);
+                                               if (log_entry_status!=RLRC_Unknown) break;
+                                       }
                                        x++;
-                                       if (LogFormats[x]==current_format) continue;
-                                       memset(&log_entry,0,sizeof(log_entry));
-                                       log_entry_status=LogFormats[x]->ReadEntry(linebuf,&log_entry);
                                }
                                if (x<0 || x>=(int)(sizeof(LogFormats)/sizeof(*LogFormats))) {
-                                       debuga(_("Unknown line format found in input log file %s\n"),arq);
+                                       debuga(_("Unknown line format found in input log file %s:\n%s\n"),arq,linebuf);
                                        exit(EXIT_FAILURE);
                                }
                                current_format=LogFormats[x];