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,12 +122,17 @@ 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 */
if (*buffer_len < strlen (*buffer) + value_len + 2)
{
*buffer = realloc (*buffer, *buffer_len * 2);
if (*buffer == NULL)
/* XXX Here be dragons */
return false;
size_t end_offset = *end - *buffer;
char *tmp = realloc (*buffer, *buffer_len * 2);
*buffer_len = *buffer_len * 2;
if (tmp != NULL)
{
*buffer = tmp;
*end = tmp + end_offset;
*buffer_len = *buffer_len * 2;
}
else
return false;
}
/* Append value to buffer */