PR22230, buffer overflow in display_debug_macro
authorAlan Modra <amodra@gmail.com>
Sun, 1 Oct 2017 01:37:07 +0000 (12:07 +1030)
committerAlan Modra <amodra@gmail.com>
Sun, 1 Oct 2017 01:37:07 +0000 (12:07 +1030)
PR 22230
* objdump.c (load_specific_debug_section): Allocate an extra byte
for a terminating NUL.

binutils/ChangeLog
binutils/objdump.c

index d9f08991f900e9913560f54ab7fb079e1abc4be1..d45eeaf9b5ad72ea2717521359a7b472d67ca83f 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-01  Alan Modra  <amodra@gmail.com>
+
+       PR 22230
+       * objdump.c (load_specific_debug_section): Allocate an extra byte
+       for a terminating NUL.
+
 2017-09-30  Alan Modra  <amodra@gmail.com>
 
        PR 21978
index 3b2c7a38788b66f58965b2b8cf45657f4b8f7d8e..83b8b2a273b3998fa64f95b41c39827d86fe80b7 100644 (file)
@@ -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, &section->start);
-
-  if (! ret)
+  if (section->start == NULL
+      || !bfd_get_full_section_contents (abfd, sec, &section->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)
     {
This page took 0.030274 seconds and 4 git commands to generate.