public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, binutils/ARM] Fix leak of local internal symbols in elf32_arm_size_stubs
@ 2015-10-20  2:32 Thomas Preud'homme
  2015-10-28 14:55 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Preud'homme @ 2015-10-20  2:32 UTC (permalink / raw)
  To: binutils

In elf32_arm_size_stubs, when encountering a relocation against a local symbol for the first time in a given input section, bfd_elf_get_elf_syms is called if symtab_hdr->contents is NULL. However, the allocation performed by this function is never freed, hence a potential leak if such a situation occurs. This patch adds a free before exiting the scope in which local_syms is valid.

ChangeLog entry is as follows:

*** bfd/ChangeLog ***

2015-09-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

        * elf32-arm.c (elf32_arm_size_stubs): Free local_syms before exiting
        the block where it's valid.


diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index aa01a59..f3fe773 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -5126,6 +5126,8 @@ elf32_arm_size_stubs (bfd *output_bfd,
 		    error_ret_free_internal:
 		      if (elf_section_data (section)->relocs == NULL)
 			free (internal_relocs);
+		      if (!symtab_hdr->contents)
+			free (local_syms);
 		      goto error_ret_free_local;
 		    }
 
@@ -5420,6 +5422,12 @@ elf32_arm_size_stubs (bfd *output_bfd,
 		free (internal_relocs);
 	    }
 
+	  if (!symtab_hdr->contents)
+	    {
+	      free (local_syms);
+	      local_syms = NULL;
+	    }
+
 	  if (htab->fix_cortex_a8)
 	    {
 	      /* Sort relocs which might apply to Cortex-A8 erratum.  */
@@ -5433,7 +5441,11 @@ elf32_arm_size_stubs (bfd *output_bfd,
 					  a8_relocs, num_a8_relocs,
 					  prev_num_a8_fixes, &stub_changed)
 		  != 0)
-		goto error_ret_free_local;
+		{
+		  if (!symtab_hdr->contents)
+		    free (local_syms);
+		  goto error_ret_free_local;
+		}
 	    }
 	}


The testsuite shows no regression when run for arm-none-eabi target.

Is this ok for master branch?

Best regards,

Thomas


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-04-05 23:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-20  2:32 [PATCH, binutils/ARM] Fix leak of local internal symbols in elf32_arm_size_stubs Thomas Preud'homme
2015-10-28 14:55 ` Nick Clifton
2015-10-29  0:04   ` Alan Modra
2016-04-05 17:00     ` Thomas Preudhomme
2016-04-05 23:50       ` 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).