public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* mmo.c leak in mmo_make_section
@ 2022-08-17  7:07 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-08-17  7:07 UTC (permalink / raw)
  To: binutils

	* mmo.c (mmo_make_section): Alloc name using bfd_alloc.  Use
	bfd_error_no_memory.
	(mmo_decide_section): Check for NULL return from mmo_make_section.

diff --git a/bfd/mmo.c b/bfd/mmo.c
index 1c901ae5c20..30af28c8bdc 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -463,17 +463,15 @@ mmo_make_section (bfd *abfd, const char *secname)
 
   if (sec == NULL)
     {
-      char *newsecname = strdup (secname);
+      size_t len = strlen (secname) + 1;
+      char *newsecname = bfd_alloc (abfd, len);
 
       if (newsecname == NULL)
 	{
-	  _bfd_error_handler
-	    /* xgettext:c-format */
-	    (_("%pB: no core to allocate section name %s"),
-	     abfd, secname);
-	  bfd_set_error (bfd_error_system_call);
+	  bfd_set_error (bfd_error_no_memory);
 	  return NULL;
 	}
+      memcpy (newsecname, secname, len);
       sec = bfd_make_section (abfd, newsecname);
     }
 
@@ -727,7 +725,7 @@ mmo_decide_section (bfd *abfd, bfd_vma vma)
   sprintf (sec_name, ".MMIX.sec.%d", abfd->tdata.mmo_data->sec_no++);
   sec = mmo_make_section (abfd, sec_name);
 
-  if (!sec->user_set_vma && !bfd_set_section_vma (sec, vma))
+  if (!sec || (!sec->user_set_vma && !bfd_set_section_vma (sec, vma)))
     return NULL;
 
   if (!bfd_set_section_flags (sec, (bfd_section_flags (sec)

-- 
Alan Modra
Australia Development Lab, IBM

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

only message in thread, other threads:[~2022-08-17  7:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-17  7:07 mmo.c leak in mmo_make_section 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).