[libvirt] [PATCH] virlogd: fix crash if log file exists and it's larger the maxlen

Pavel Hrdina phrdina at redhat.com
Mon Nov 30 07:31:15 UTC 2015


If for some reason there is an existing log file, that is larger then
max length of log file, we need to rollover that file immediately.
Trying to figure out how much data we could write will resolve in
overflow of unsigned variable 'towrite' and this leads to segfault.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/virrotatingfile.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index 1260710..827b44b 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -443,7 +443,12 @@ virRotatingFileWriterAppend(virRotatingFileWriterPtr file,
         size_t towrite = len;
         bool forceRollover = false;
 
-        if ((file->entry->pos + towrite) > file->maxlen) {
+        if (file->entry->pos > file->maxlen) {
+            /* If existing file is for some reason larger then max length we
+             * won't write to this file anymore, but we rollover this file.*/
+            forceRollover = true;
+            towrite = 0;
+        } else if ((file->entry->pos + towrite) > file->maxlen) {
             towrite = file->maxlen - file->entry->pos;
 
             /*
-- 
2.6.3




More information about the libvir-list mailing list