summaryrefslogtreecommitdiff
path: root/tests/virrotatingfiletest.c
diff options
context:
space:
mode:
authorPavel Hrdina <phrdina@redhat.com>2015-11-28 09:03:40 +0100
committerPavel Hrdina <phrdina@redhat.com>2015-11-30 10:45:45 +0100
commitcb97426208b47ac9f5f376311407ce4ebd80858d (patch)
tree161a001a2fcad324c6f9d810cccc09ce08055422 /tests/virrotatingfiletest.c
parent163a781e63481499c6027beed017221e39ebdc0b (diff)
downloadlibvirt-cb97426208b47ac9f5f376311407ce4ebd80858d.tar.gz
virlogd: fix crash if log file exists and it's larger the maxlen
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@redhat.com>
Diffstat (limited to 'tests/virrotatingfiletest.c')
-rw-r--r--tests/virrotatingfiletest.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c
index 03e9664347..44a59cdb17 100644
--- a/tests/virrotatingfiletest.c
+++ b/tests/virrotatingfiletest.c
@@ -515,6 +515,48 @@ static int testRotatingFileWriterRolloverLineBreak(const void *data ATTRIBUTE_UN
}
+static int testRotatingFileWriterLargeFile(const void *data ATTRIBUTE_UNUSED)
+{
+ virRotatingFileWriterPtr file;
+ int ret = -1;
+ const char *buf = "The quick brown fox jumps over the lazy dog\n"
+ "The wizard quickly jinxed the gnomes before they vaporized\n";
+
+ if (testRotatingFileInitFiles(200,
+ (off_t)-1,
+ (off_t)-1) < 0)
+ return -1;
+
+ file = virRotatingFileWriterNew(FILENAME,
+ 160,
+ 2,
+ false,
+ 0700);
+ if (!file)
+ goto cleanup;
+
+ if (testRotatingFileWriterAssertFileSizes(200,
+ (off_t)-1,
+ (off_t)-1) < 0)
+ goto cleanup;
+
+ virRotatingFileWriterAppend(file, buf, strlen(buf));
+
+ if (testRotatingFileWriterAssertFileSizes(103,
+ 200,
+ (off_t)-1) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ virRotatingFileWriterFree(file);
+ unlink(FILENAME);
+ unlink(FILENAME0);
+ unlink(FILENAME1);
+ return ret;
+}
+
+
static int testRotatingFileReaderOne(const void *data ATTRIBUTE_UNUSED)
{
virRotatingFileReaderPtr file;
@@ -681,6 +723,9 @@ mymain(void)
if (virtTestRun("Rotating file write rollover line break", testRotatingFileWriterRolloverLineBreak, NULL) < 0)
ret = -1;
+ if (virtTestRun("Rotating file write to file larger then maxlen", testRotatingFileWriterLargeFile, NULL) < 0)
+ ret = -1;
+
if (virtTestRun("Rotating file read one", testRotatingFileReaderOne, NULL) < 0)
ret = -1;