[PATCH] Avoid pascal crashes for structures having fields without names

Pierre Muller pierre.muller@ics-cnrs.unistra.fr
Thu Oct 14 15:21:00 GMT 2010


  I committed the following patch
to GDB cvs HEAD.
  Some Free Pascal classes seem now to have
hidden fields that get no names.
  This could lead to crashes by
calling strcmp with a NULL parameter.


Pierre Muller
Pascal language support maintainer for GDB


ChangeLog entry:

2010-10-14  Pierre Muller  <muller@ics.u-strasbg.fr>

       * p-lang.c (is_pascal_string_type): Avoid crashes on structures
       having fields without names.


Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.55
diff -u -p -r1.55 p-lang.c
--- p-lang.c    12 Jul 2010 17:07:11 -0000      1.55
+++ p-lang.c    14 Oct 2010 15:17:54 -0000
@@ -105,8 +105,10 @@ is_pascal_string_type (struct type *type
     {
       /* Old Borland type pascal strings from Free Pascal Compiler.  */
       /* Two fields: length and st.  */
-      if (TYPE_NFIELDS (type) == 2
+      if (TYPE_NFIELDS (type) == 2
+         && TYPE_FIELDS (type) [0].name
           && strcmp (TYPE_FIELDS (type)[0].name, "length") == 0
+         && TYPE_FIELDS (type) [1].name
           && strcmp (TYPE_FIELDS (type)[1].name, "st") == 0)
         {
           if (length_pos)
@@ -124,7 +126,9 @@ is_pascal_string_type (struct type *type
       /* GNU pascal strings.  */
       /* Three fields: Capacity, length and schema$ or _p_schema.  */
       if (TYPE_NFIELDS (type) == 3
+         && TYPE_FIELDS (type) [0].name
           && strcmp (TYPE_FIELDS (type)[0].name, "Capacity") == 0
+         && TYPE_FIELDS (type) [1].name
           && strcmp (TYPE_FIELDS (type)[1].name, "length") == 0)
         {
          if (length_pos)



More information about the Gdb-patches mailing list