This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR22230, buffer overflow in display_debug_macro
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sun, 1 Oct 2017 12:32:45 +1030
- Subject: PR22230, buffer overflow in display_debug_macro
- Authentication-results: sourceware.org; auth=none
PR 22230
* objdump.c (load_specific_debug_section): Allocate an extra byte
for a terminating NUL.
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 3b2c7a3..83b8b2a 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -2475,17 +2475,18 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
section->num_relocs = 0;
section->address = bfd_get_section_vma (abfd, sec);
section->size = bfd_get_section_size (sec);
- section->start = NULL;
+ section->start = malloc (section->size + 1);
section->user_data = sec;
- ret = bfd_get_full_section_contents (abfd, sec, §ion->start);
-
- if (! ret)
+ if (section->start == NULL
+ || !bfd_get_full_section_contents (abfd, sec, §ion->start))
{
free_debug_section (debug);
printf (_("\nCan't get contents for section '%s'.\n"),
section->name);
return 0;
}
+ /* Ensure any string section has a terminating NUL. */
+ section->start[section->size] = 0;
if (is_relocatable && debug_displays [debug].relocate)
{
--
Alan Modra
Australia Development Lab, IBM