From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Return lazy value from allocate_repeat_value
Date: Mon, 21 Sep 2026 13:46:44 -0400 [thread overview]
Message-ID: <0a491ae3-f893-4543-afd8-658f650bd042@simark.ca> (raw)
In-Reply-To: <20260921161632.1602438-1-tromey@adacore.com>
On 9/21/26 12:16 PM, Tom Tromey wrote:
> A user noticed that the "@" operator could cause a crash in gdb. The
> bug here was that value::allocate_contents might limit the amount of
> memory allocated for the contents, but value_repeat did not respect
> this.
>
> This patch fixes the problem by having allocate_repeat_value return a
> lazy value. This defers to the memory reading to the "usual" code
> that does respect these limits.
>
> Regression tested on x86-64 Fedora 43.
>
> Note that the new test only reliably fails in an ASAN build.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34132
> ---
> gdb/testsuite/gdb.base/printcmds.exp | 9 +++++++++
> gdb/valops.c | 4 ----
> gdb/value.c | 2 +-
> 3 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
> index 12933d898ed..0600eaf2ab6 100644
> --- a/gdb/testsuite/gdb.base/printcmds.exp
> +++ b/gdb/testsuite/gdb.base/printcmds.exp
> @@ -717,6 +717,15 @@ proc test_artificial_arrays {} {
> {p int1dim[0]@TWO@three}
> gdb_test_escape_braces {p/x (short [])0x12345678} \
> " = ({0x1234, 0x5678}|{0x5678, 0x1234})"
> +
> + # A regression test for a buffer overflow. PR gdb/34132.
> + gdb_test_no_output {set $ctable = (char *) ctable2}
Just wondering, is the use of the convenience var necessary?
> + gdb_test_no_output "set max-value-size 16"
> + gdb_test_no_output "set print elements 10"
> + gdb_test {print $ctable[0] @ 20} \
> + [quotemeta {$@DECIMAL = {97 'a', 88 'X' <repeats 15 times>...}}]
> + gdb_test_no_output "set max-value-size 65536"
> + gdb_test_no_output "set print elements 200"
Can you do
with max-value-size 16 -- with print elements 10 -- ...
to avoid having to set and reset the settings?
Other than that, LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
next prev parent reply other threads:[~2026-09-21 17:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 16:16 Tom Tromey
2026-09-21 17:46 ` Simon Marchi [this message]
2026-09-21 19:30 ` Tom Tromey
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=0a491ae3-f893-4543-afd8-658f650bd042@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.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