This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH, binutils/ARM] Fix leak of local internal symbols in elf32_arm_size_stubs
- From: "Thomas Preud'homme" <thomas dot preudhomme at arm dot com>
- To: <binutils at sourceware dot org>
- Date: Tue, 20 Oct 2015 10:32:11 +0800
- Subject: [PATCH, binutils/ARM] Fix leak of local internal symbols in elf32_arm_size_stubs
- Authentication-results: sourceware.org; auth=none
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