PR25629, objcopy : SIGSEGV in filter_symbols

Message ID 20200305043149.GA5384@bubble.grove.modra.org
State New
Headers show
Series
  • PR25629, objcopy : SIGSEGV in filter_symbols
Related show

Commit Message

Alan Modra March 5, 2020, 4:31 a.m.
PR 25629
	* objcopy.c (filter_symbols): Don't segfault on NULL
	prefix_symbols_string.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index daee570763..3b9f1b73ca 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);