Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Jielun Wu <firmiana402@gmail.com>
Cc: gdb-patches@sourceware.org,  Simon Marchi <simark@simark.ca>,
	 Guinevere Larsen <guinevere@redhat.com>
Subject: Re: [PATCH v2] gdb: Check bounds before reading DWARF expression operands
Date: Fri, 23 Oct 2026 12:22:51 -0600	[thread overview]
Message-ID: <87ld7oqnt0.fsf@tromey.com> (raw)
In-Reply-To: <20260805040640.2095812-1-firmiana402@gmail.com> (Jielun Wu's message of "Wed, 5 Aug 2026 12:06:40 +0800")

>>>>> Jielun Wu <firmiana402@gmail.com> writes:

> Some DWARF expression opcodes read fixed-width operands or block payloads
> before checking that the bytes are available in the current expression.
> Malformed expressions can consequently consume opcode or unrelated bytes
> and fail later with misleading results.

Thanks for the patch.

> +/* Return BUF advanced by BYTES bytes.  Throw an error if fewer than BYTES
> +   bytes remain before BUF_END.  */
> +
> +static const gdb_byte *
> +safe_skip_bytes (const gdb_byte *buf, const gdb_byte *buf_end,
> +		 ULONGEST bytes)
> +{
> +  gdb_assert (buf <= buf_end);

It's conventional in C for the end pointer to be one-past-the-end.
And I think that's true in this code too:

      const gdb_byte *op_ptr = expr.data ();
      const gdb_byte *op_end = expr.data () + expr.size ();

    +	    op_ptr = safe_skip_bytes (op_ptr, op_end, len);

So using "<" seems more correct than "<=" here?

OTOH maybe it doesn't matter due to the subsequent check:

> +  if (bytes > (ULONGEST) (buf_end - buf))
> +    error (_("DWARF expression error: ran off end of buffer reading bytes"));

Curious what you think.  Anyway that's my only nit on this patch.

Tom

  reply	other threads:[~2026-10-23 18:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  4:06 Jielun Wu
2026-10-23 18:22 ` Tom Tromey [this message]
2026-10-26  9:14   ` Jielun Wu

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=87ld7oqnt0.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=firmiana402@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guinevere@redhat.com \
    --cc=simark@simark.ca \
    /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