mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
logging: fix off-by-one bug
Valgrind caught that our log wrap-around was going 1 past the end. Regression introduced in commit b16f47a; previously the buffer was static and size+1 bytes, but now it is dynamic and exactly size bytes. * src/util/logging.c (virLogStr): Don't write past end of log.
This commit is contained in:
parent
3c2b210a3c
commit
dd5564f218
@ -326,7 +326,7 @@ static void virLogStr(const char *str, int len) {
|
|||||||
return;
|
return;
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
if (len > virLogSize)
|
if (len >= virLogSize)
|
||||||
return;
|
return;
|
||||||
virLogLock();
|
virLogLock();
|
||||||
|
|
||||||
@ -336,13 +336,13 @@ static void virLogStr(const char *str, int len) {
|
|||||||
if (virLogEnd + len >= virLogSize) {
|
if (virLogEnd + len >= virLogSize) {
|
||||||
tmp = virLogSize - virLogEnd;
|
tmp = virLogSize - virLogEnd;
|
||||||
memcpy(&virLogBuffer[virLogEnd], str, tmp);
|
memcpy(&virLogBuffer[virLogEnd], str, tmp);
|
||||||
virLogBuffer[virLogSize] = 0;
|
|
||||||
memcpy(&virLogBuffer[0], &str[tmp], len - tmp);
|
memcpy(&virLogBuffer[0], &str[tmp], len - tmp);
|
||||||
virLogEnd = len - tmp;
|
virLogEnd = len - tmp;
|
||||||
} else {
|
} else {
|
||||||
memcpy(&virLogBuffer[virLogEnd], str, len);
|
memcpy(&virLogBuffer[virLogEnd], str, len);
|
||||||
virLogEnd += len;
|
virLogEnd += len;
|
||||||
}
|
}
|
||||||
|
virLogBuffer[virLogEnd] = 0;
|
||||||
/*
|
/*
|
||||||
* Update the log length, and if full move the start index
|
* Update the log length, and if full move the start index
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user