PR fortran/95090 - ICE: identifier overflow
authorHarald Anlauf <anlauf@gmx.de>
Sat, 30 May 2020 18:50:59 +0000 (20:50 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 30 May 2020 18:50:59 +0000 (20:50 +0200)
Implement buffer overrun check for temporary that holds mangled names.

2020-05-30  Harald Anlauf  <anlauf@gmx.de>

gcc/fortran/
PR fortran/95090
* class.c (get_unique_type_string): Use buffer overrun check.

gcc/fortran/class.c

index db395624a16da697faa59d06e5aa86d31a494270..afd8885a1eaea5097e4c7d9d3d021e42098e9911 100644 (file)
@@ -484,7 +484,14 @@ get_unique_type_string (char *string, gfc_symbol *derived)
   if (derived->attr.unlimited_polymorphic)
     strcpy (dt_name, "STAR");
   else
-    strncpy (dt_name, gfc_dt_upper_string (derived->name), sizeof (dt_name));
+    {
+      const char *upper = gfc_dt_upper_string (derived->name);
+      size_t len = strnlen (upper, sizeof (dt_name));
+      if (len >= sizeof (dt_name))
+       gfc_internal_error ("get_unique_type_string: identifier overflow");
+      memcpy (dt_name, upper, len);
+      dt_name[len] = '\0';
+    }
   if (derived->attr.unlimited_polymorphic)
     sprintf (string, "_%s", dt_name);
   else if (derived->module)