PR25070, SEGV in function _bfd_dwarf2_find_nearest_line
authorAlan Modra <amodra@gmail.com>
Wed, 9 Oct 2019 00:17:13 +0000 (10:47 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 9 Oct 2019 02:58:20 +0000 (13:28 +1030)
Evil testcase with two debug info sections, with sizes of 2aaaabac4ec1
and ffffd5555453b140 result in a total size of 1.  Reading the first
section of course overflows the buffer and tramples on other memory.

PR 25070
* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Catch overflow of
total_size calculation.

bfd/ChangeLog
bfd/dwarf2.c

index cf5b372860359e1ef9f7ecd262c00b86db94c17d..87a6244bca537b5740f5b82a544f03825eaa1115 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-09  Alan Modra  <amodra@gmail.com>
+
+       PR 25070
+       * dwarf2.c (_bfd_dwarf2_slurp_debug_info): Catch overflow of
+       total_size calculation.
+
 2019-10-08  Alan Modra  <amodra@gmail.com>
 
        PR 25078
index d39f4fdfe4b8bc3d3e9bbbd691c59b6abb6a3255..88aaa2d23c22c65dd56cc94121a55216f23288cb 100644 (file)
@@ -4439,7 +4439,16 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
       for (total_size = 0;
           msec;
           msec = find_debug_info (debug_bfd, debug_sections, msec))
-       total_size += msec->size;
+       {
+         /* Catch PR25070 testcase overflowing size calculation here.  */
+         if (total_size + msec->size < total_size
+             || total_size + msec->size < msec->size)
+           {
+             bfd_set_error (bfd_error_no_memory);
+             return FALSE;
+           }
+         total_size += msec->size;
+       }
 
       stash->info_ptr_memory = (bfd_byte *) bfd_malloc (total_size);
       if (stash->info_ptr_memory == NULL)
This page took 0.027965 seconds and 4 git commands to generate.