From: Frédéric Marchal Date: Sun, 26 Aug 2012 13:41:52 +0000 (+0200) Subject: Fix a crash when no log formats are found suitable X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aee69f3a2d8c01b0029cf860e765efcd2d59906f;p=thirdparty%2Fsarg.git Fix a crash when no log formats are found suitable If no log formats can decode a line from the input log, an index would exceed its bound and produce a crash. --- diff --git a/readlog.c b/readlog.c index 1543de4..3165830 100644 --- 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];