public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR25629, objcopy : SIGSEGV in filter_symbols
@ 2020-03-05  4:31 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2020-03-05  4:31 UTC (permalink / raw)
  To: binutils

	PR 25629
	* objcopy.c (filter_symbols): Don't segfault on NULL
	prefix_symbols_string.

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);
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-05  4:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05  4:31 PR25629, objcopy : SIGSEGV in filter_symbols Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).