On Mon, Nov 30, 2015 at 08:31:15AM +0100, Pavel Hrdina wrote:
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 <phrd...@redhat.com>
---
src/util/virrotatingfile.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)


Makes sense, ACK.  Would you care to add a test in the
tests/virrotatingfiletest.c file?  Thanks.

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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to