libifupdown: Fixed bug where end pointer is not updated after realloc

This commit is contained in:
Erik Kooistra 2020-12-21 22:42:02 +01:00 committed by Ariadne Conill
parent 1ee485666f
commit 4c64b5138b

View file

@ -122,13 +122,18 @@ append_to_buffer(char **buffer, size_t *buffer_len, char **end, const char *valu
/* Make sure there is enough room to add the value to the buffer */ /* Make sure there is enough room to add the value to the buffer */
if (*buffer_len < strlen (*buffer) + value_len + 2) if (*buffer_len < strlen (*buffer) + value_len + 2)
{ {
*buffer = realloc (*buffer, *buffer_len * 2); size_t end_offset = *end - *buffer;
if (*buffer == NULL) char *tmp = realloc (*buffer, *buffer_len * 2);
/* XXX Here be dragons */
return false;
if (tmp != NULL)
{
*buffer = tmp;
*end = tmp + end_offset;
*buffer_len = *buffer_len * 2; *buffer_len = *buffer_len * 2;
} }
else
return false;
}
/* Append value to buffer */ /* Append value to buffer */
size_t printed = snprintf (*end, value_len + 2, "%s ", value); size_t printed = snprintf (*end, value_len + 2, "%s ", value);