From 7342d3896446deaf89ab5582da81457571e48fe6 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Sat, 20 Jun 2009 23:22:41 +0200 Subject: Handle logs with NUL chars better It is not too rare that '\0' chars appear in /var/log/messages. I saw a real-life case where kerneloops would show a popup with the same old oops after every login. It turned out that there were NUL chars in the log which prevented kerneloops from seeing its marker, so it always treated the old oops in the log as new. This patch fixes it by always going through the whole known length of the buffer (not stopping on NUL chars) and using less string-oriented functions in fill_lineinfo(). --- lib/Plugins/KerneloopsScanner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/Plugins/KerneloopsScanner.cpp') diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index e95f259b..855213bc 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -104,7 +104,7 @@ void CKerneloopsScanner::ScanSysLogFile(const char *filename, int issyslog) FILE *file; int ret; int m_nFoundOopses; - size_t buflen; + size_t buflen, nread; memset(&statb, 0, sizeof(statb)); @@ -134,11 +134,11 @@ void CKerneloopsScanner::ScanSysLogFile(const char *filename, int issyslog) return; } fseek(file, -buflen, SEEK_END); - ret = fread(buffer, 1, buflen-1, file); + nread = fread(buffer, 1, buflen, file); fclose(file); - if (ret > 0) - m_nFoundOopses = m_pSysLog.ExtractOops(buffer, buflen-1, issyslog); + if (nread > 0) + m_nFoundOopses = m_pSysLog.ExtractOops(buffer, nread, issyslog); free(buffer); if (m_nFoundOopses > 0) { -- cgit