From f2530c80db7b29b95368fce956b3a778f096b368 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 4 Feb 2020 21:16:41 +0000 Subject: [PATCH] elfcopy: Handle multiple data descriptors properly. The code clearly meant to resize the buffer in the case where a section was backed by multiple data descriptors. In practice this shouldn't have been a problem since libelf would return a single data descriptor for each section in a newly opened file. CID: 1262522 MFC after: 1 week Sponsored by: The FreeBSD Foundation --- contrib/elftoolchain/elfcopy/sections.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/elftoolchain/elfcopy/sections.c b/contrib/elftoolchain/elfcopy/sections.c index 3ffa3858eba5..a3ebfe126721 100644 --- a/contrib/elftoolchain/elfcopy/sections.c +++ b/contrib/elftoolchain/elfcopy/sections.c @@ -1137,7 +1137,7 @@ read_section(struct section *s, size_t *size) if (b == NULL) b = malloc(id->d_size); else - b = malloc(sz + id->d_size); + b = realloc(b, sz + id->d_size); if (b == NULL) err(EXIT_FAILURE, "malloc or realloc failed");