From d1faf7ca0a9ecbc7f89998638e5cf08d3dca6e84 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 5 Mar 2020 14:57:47 +1030 Subject: [PATCH] PR25629, objcopy : SIGSEGV in filter_symbols PR 25629 * objcopy.c (filter_symbols): Don't segfault on NULL prefix_symbols_string. --- binutils/ChangeLog | 6 ++++++ binutils/objcopy.c | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 35d3fada640..7ce0326ac49 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2020-03-05 Alan Modra + + PR 25629 + * objcopy.c (filter_symbols): Don't segfault on NULL + prefix_symbols_string. + 2020-03-04 Christian Eggers * objcopy.c (copy_object): Convert from bytes to octets for diff --git a/binutils/objcopy.c b/binutils/objcopy.c index daee5707637..3b9f1b73ca9 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1580,9 +1580,14 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms, if (add_leading_char || prefix_symbols_string) { char *n, *ptr; + size_t len = strlen (name) + 1; - ptr = n = (char *) xmalloc (1 + strlen (prefix_symbols_string) - + strlen (name) + 1); + if (add_leading_char) + len++; + if (prefix_symbols_string) + len += strlen (prefix_symbols_string); + + ptr = n = (char *) xmalloc (len); if (add_leading_char) *ptr++ = bfd_get_symbol_leading_char (obfd); -- 2.30.2