From: Jielun Wu <firmiana402@gmail.com>
To: Tom Tromey <tom@tromey.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: Mon, 26 Oct 2026 17:14:04 +0800 [thread overview]
Message-ID: <b2ca6b0c-85cb-4164-a174-63cba2341ae5@gmail.com> (raw)
In-Reply-To: <87ld7oqnt0.fsf@tromey.com>
Thank you for the review.
> It's conventional in C for the end pointer to be one-past-the-end.
> [...]
> So using "<" seems more correct than "<=" here?
For reference, the helper is:
> static const gdb_byte *
> safe_skip_bytes (const gdb_byte *buf, const gdb_byte *buf_end,
> ULONGEST bytes)
> {
> gdb_assert (buf <= buf_end);
> if (bytes > (ULONGEST) (buf_end - buf))
> error (_("DWARF expression error: ran off end of buffer reading bytes"));
> return buf + bytes;
> }
BUF_END is indeed one-past-the-end, but BUF can equal it when an
operand is entirely missing.
For example, the existing truncated_const1u case contains only
DW_OP_const1u. After reading the opcode, op_ptr == op_end, and
safe_skip_bytes is called with bytes == 1. The <= assertion lets
the subsequent length check report the expected DWARF error;
a < assertion would instead trigger an internal error first.
Equality also allows a zero-byte skip at the end, so I think we
should keep <= here.
Jielun
prev parent reply other threads:[~2026-10-26 9:14 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
2026-10-26 9:14 ` Jielun Wu [this message]
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=b2ca6b0c-85cb-4164-a174-63cba2341ae5@gmail.com \
--to=firmiana402@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=guinevere@redhat.com \
--cc=simark@simark.ca \
--cc=tom@tromey.com \
/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