]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
binutils/dwarf.c debug_information leak
authorAlan Modra <amodra@gmail.com>
Wed, 19 Feb 2025 12:15:29 +0000 (22:45 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 19 Feb 2025 12:33:11 +0000 (23:03 +1030)
It is possible with fuzzed files to have num_debug_info_entries zero
after allocating space for debug_information, leading to multiple
allocations.

* dwarf.c (process_debug_info): Don't test num_debug_info_entries
to determine whether debug_information has been allocated,
test alloc_num_debug_info_entries.

binutils/dwarf.c

index 8e004cea8396a39508a05aaf4c8c0d3fbdc453f7..bfbf83ec9f416cf3c2ce95668489b245d916ddad 100644 (file)
@@ -3807,13 +3807,11 @@ process_debug_info (struct dwarf_section * section,
     }
 
   if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
-      && num_debug_info_entries == 0
-      && ! do_types)
+      && alloc_num_debug_info_entries == 0
+      && !do_types)
     {
-
       /* Then allocate an array to hold the information.  */
-      debug_information = (debug_info *) cmalloc (num_units,
-                                                 sizeof (* debug_information));
+      debug_information = cmalloc (num_units, sizeof (*debug_information));
       if (debug_information == NULL)
        {
          error (_("Not enough memory for a debug info array of %u entries\n"),