From aee69f3a2d8c01b0029cf860e765efcd2d59906f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sun, 26 Aug 2012 15:41:52 +0200 Subject: [PATCH] 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. --- readlog.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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]; -- 2.47.3