public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/31258] [gdb] ThreadSanitizer: heap-use-after-free in memmove
Date: Thu, 18 Jan 2024 16:44:47 +0000	[thread overview]
Message-ID: <bug-31258-4717-K7bBfR1CWi@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-31258-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=31258

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
The problem is a discrepancy between type size and fields.

The variable y2:
...
   Y2 : Variable_Record := (A => False, C => 1.0, D => 2);
...
is of type:
...
   type Variable_Record (A : Boolean := True) is record
      case A is
         when True =>
            B : Integer;
         when False =>
            C : Float;
            D : Integer;
      end case;
   end record;
...

For the valid values of a, 0 and 1, we get correct values for the size of the
type:
...
(gdb) set var y2.a=0
(gdb) ptype y2
type = struct parse__variable_record {
    boolean a;
    float c;
    integer d;
}
(gdb) p sizeof (y2)
$9 = 12
(gdb) set var y2.a=1
(gdb) ptype y2
type = struct parse__variable_record {
    boolean a;
    integer b;
}
(gdb) p sizeof (y2)
$10 = 8
....
and correct corresponding types.

When y2.a is unitialized, say to 0x70:
...
(gdb) set var y2.a=0x70
(gdb) ptype y2
type = struct parse__variable_record {
    boolean a;
    float c;
    integer d;
}
(gdb) p sizeof (y2)
$14 = 8
...
we get the type with three fields, which doesn't fit in the computed type size
of 8.

This demonstrator patch fixes it for ada:
...
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index ac85440b139..79769bae3bd 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -601,6 +601,10 @@ print_field_values (struct value *value, struct value
*outer_value,
          continue;
        }

+      long field_offset = type->field (i).loc_bitpos ();
+      if (field_offset / 8 >= type->length ())
+       continue;
+      
       if (comma_needed)
        gdb_printf (stream, ", ");
       comma_needed = 1;
...

However, same issue triggers again when setting language to c.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2024-01-18 16:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18  9:07 [Bug gdb/31258] New: " vries at gcc dot gnu.org
2024-01-18 14:27 ` [Bug gdb/31258] " vries at gcc dot gnu.org
2024-01-18 16:44 ` vries at gcc dot gnu.org [this message]
2024-01-19 15:39 ` vries at gcc dot gnu.org
2024-01-20 23:20 ` vries at gcc dot gnu.org
2024-01-21  9:08 ` [Bug exp/31258] " vries at gcc dot gnu.org
2024-01-22 13:27 ` vries at gcc dot gnu.org
2024-02-19  8:59 ` cvs-commit at gcc dot gnu.org
2024-02-19  9:01 ` vries at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31258-4717-K7bBfR1CWi@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).