PR25629, objcopy : SIGSEGV in filter_symbols
authorAlan Modra <amodra@gmail.com>
Thu, 5 Mar 2020 04:27:47 +0000 (14:57 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 5 Mar 2020 04:53:22 +0000 (15:23 +1030)
PR 25629
* objcopy.c (filter_symbols): Don't segfault on NULL
prefix_symbols_string.

binutils/ChangeLog
binutils/objcopy.c

index 35d3fada64060e829d59433be16fc786e820efb3..7ce0326ac49b5269f711446b6c54dcf328d9848c 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-05  Alan Modra  <amodra@gmail.com>
+
+       PR 25629
+       * objcopy.c (filter_symbols): Don't segfault on NULL
+       prefix_symbols_string.
+
 2020-03-04  Christian Eggers  <ceggers@gmx.de>
 
        * objcopy.c (copy_object): Convert from bytes to octets for
index daee57076379d1fd59500d2775c616d52479a0f8..3b9f1b73ca90b52d46091a39856ecf8e9a65bb57 100644 (file)
@@ -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);