middle-end/101292 - invalid memory access with warning control
authorRichard Biener <rguenther@suse.de>
Mon, 17 Jan 2022 14:22:11 +0000 (15:22 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 17 Jan 2022 15:16:49 +0000 (16:16 +0100)
The warning control falls into the C++ trap of using a reference
to old hashtable contents for a put operation which can end up
re-allocating that before reading from the old freed referenced to
source.  Fixed by introducing a temporary.

2022-01-17  Richard Biener  <rguenther@suse.de>

PR middle-end/101292
* diagnostic-spec.c (copy_warning): Make sure to not
reference old hashtable content on possible resize.
* warning-control.cc (copy_warning): Likewise.

gcc/diagnostic-spec.c
gcc/warning-control.cc

index a8af229..4341ccf 100644 (file)
@@ -195,7 +195,10 @@ copy_warning (location_t to, location_t from)
   else
     {
       if (from_spec)
-       nowarn_map->put (to, *from_spec);
+       {
+         nowarn_spec_t tem = *from_spec;
+         nowarn_map->put (to, tem);
+       }
       else
        nowarn_map->remove (to);
     }
index f9808bf..fa39eca 100644 (file)
@@ -206,7 +206,8 @@ void copy_warning (ToType to, FromType from)
          gcc_assert (supp);
 
          gcc_checking_assert (nowarn_map);
-         nowarn_map->put (to_loc, *from_spec);
+         nowarn_spec_t tem = *from_spec;
+         nowarn_map->put (to_loc, tem);
        }
       else
        {