mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
virconf: fix off-by-1 when appending \n to config file
If the config file does not end with a \n, the parser will append one. When re-allocating the array though, it is mistakenly assuming that 'len' is the length including the trailing NUL, but it does not. So we must add 2 to len, when reallocating, not 1. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
776925096d
commit
fe2d37295e
@ -779,7 +779,7 @@ virConfReadFile(const char *filename, unsigned int flags)
|
||||
|
||||
if (len && len < MAX_CONFIG_FILE_SIZE && content[len - 1] != '\n') {
|
||||
VIR_DEBUG("appending newline to busted config file %s", filename);
|
||||
if (VIR_REALLOC_N(content, len + 1) < 0)
|
||||
if (VIR_REALLOC_N(content, len + 2) < 0)
|
||||
goto cleanup;
|
||||
content[len++] = '\n';
|
||||
content[len] = '\0';
|
||||
|
Loading…
Reference in New Issue
Block a user