From 4c64b5138b0498f61a640d664bd7da0253635a85 Mon Sep 17 00:00:00 2001 From: Erik Kooistra Date: Mon, 21 Dec 2020 22:42:02 +0100 Subject: [PATCH] libifupdown: Fixed bug where end pointer is not updated after realloc --- libifupdown/lifecycle.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libifupdown/lifecycle.c b/libifupdown/lifecycle.c index 056783f..f0bd2b3 100644 --- a/libifupdown/lifecycle.c +++ b/libifupdown/lifecycle.c @@ -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 */