Fix seg-fault running addr2line on a corrupt binary.
authorNick Clifton <nickc@redhat.com>
Thu, 1 Dec 2016 10:15:07 +0000 (10:15 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 1 Dec 2016 10:15:07 +0000 (10:15 +0000)
PR binutils/20891
* aoutx.h (find_nearest_line): Handle the case where the main file
name and the directory name are both empty.

bfd/ChangeLog
bfd/aoutx.h

index fc32759107baa370c4298b8e92099966b7542f7b..8de43e032c2a07472bf1da133f2abfcfd6732ffa 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-01  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/20891
+       * aoutx.h (find_nearest_line): Handle the case where the main file
+       name and the directory name are both empty.
+
 2016-11-30  Alan Modra  <amodra@gmail.com>
 
        * elf.c (get_program_header_size): Revert accidental change.
index 089fe570823023bfcb15fc0d46822ac4b6067d2c..614da21a771b7ac34b77a844a8919443b1f5e0a8 100644 (file)
@@ -2666,7 +2666,7 @@ NAME (aout, find_nearest_line) (bfd *abfd,
   char *buf;
 
   *filename_ptr = abfd->filename;
-  *functionname_ptr = 0;
+  *functionname_ptr = NULL;
   *line_ptr = 0;
   if (disriminator_ptr)
     *disriminator_ptr = 0;
@@ -2811,9 +2811,17 @@ NAME (aout, find_nearest_line) (bfd *abfd,
        *filename_ptr = main_file_name;
       else
        {
-         sprintf (buf, "%s%s", directory_name, main_file_name);
-         *filename_ptr = buf;
-         buf += filelen + 1;
+         if (buf == NULL)
+           /* PR binutils/20891: In a corrupt input file both
+              main_file_name and directory_name can be empty...  */
+           * filename_ptr = NULL;
+         else
+           {
+             snprintf (buf, filelen + 1, "%s%s", directory_name,
+                       main_file_name);
+             *filename_ptr = buf;
+             buf += filelen + 1;
+           }
        }
     }
 
This page took 0.028472 seconds and 4 git commands to generate.