Avoid use-after-free in DWARF debug names code
authorTom Tromey <tromey@adacore.com>
Mon, 1 Jul 2019 15:33:19 +0000 (09:33 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 1 Jul 2019 15:36:30 +0000 (09:36 -0600)
A static analyzer pointed out that find_vec_in_debug_names will use
the contents of a unique_ptr after it has been destroyed.  This patch
fixes the bug by hoisting the declaration into the appropriate
enclosing block.

I'm checking this in as obvious.

gdb/ChangeLog
2019-07-01  Tom Tromey  <tromey@adacore.com>

* dwarf2read.c
(dw2_debug_names_iterator::find_vec_in_debug_names): Hoist
declaration of without_params.  Fix formatting.

gdb/ChangeLog
gdb/dwarf2read.c

index b1fa6112866745e2fd939a35ba3e288064daa737..4cb3f6f1bc2067fcdf9510d39e7d8985d2e05946 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-01  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2read.c
+       (dw2_debug_names_iterator::find_vec_in_debug_names): Hoist
+       declaration of without_params.  Fix formatting.
+
 2019-07-01  Tom Tromey  <tromey@adacore.com>
 
        * ada-exp.y (find_primitive_type): Update.
index d0048632926d1ba2dd4ca592b194cc777fc17fe2..f1fbba43fade3db9b68ca2d66e07193b357ee615 100644 (file)
@@ -5726,6 +5726,7 @@ dw2_debug_names_iterator::find_vec_in_debug_names
 {
   int (*cmp) (const char *, const char *);
 
+  gdb::unique_xmalloc_ptr<char> without_params;
   if (current_language->la_language == language_cplus
       || current_language->la_language == language_fortran
       || current_language->la_language == language_d)
@@ -5735,13 +5736,9 @@ dw2_debug_names_iterator::find_vec_in_debug_names
 
       if (strchr (name, '(') != NULL)
        {
-         gdb::unique_xmalloc_ptr<char> without_params
-           = cp_remove_params (name);
-
+         without_params = cp_remove_params (name);
          if (without_params != NULL)
-           {
-             name = without_params.get();
-           }
+           name = without_params.get ();
        }
     }