[libvirt] [PATCH] virlogd: fix crash if log file exists and it's larger the maxlen
Martin Kletzander
mkletzan at redhat.com
Mon Nov 30 07:50:16 UTC 2015
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 <phrdina at 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 at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20151130/51df3cac/attachment-0001.sig>
More information about the libvir-list
mailing list