From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 16/3EYFYsWoHey0AWB0awg (envelope-from ) for ; Mon, 21 Sep 2026 12:17:05 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=I9ouSAj4; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 31B5A1E01F; Mon, 21 Sep 2026 12:17:05 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3EC141E01F for ; Mon, 21 Sep 2026 12:17:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37A774BA9026 for ; Mon, 21 Sep 2026 16:17:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37A774BA9026 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=I9ouSAj4 Received: from mail-oi2-x10.google.com (mail-oi2-x10.google.com [IPv6:2607:f8b0:4864:32::10]) by sourceware.org (Postfix) with ESMTPS id 14C214BA799A for ; Mon, 21 Sep 2026 16:16:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14C214BA799A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14C214BA799A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:32::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790007399; cv=none; b=MXaI/KV4e+NAG95k7iaUK6ToqwGEcvRaTVPlDr19yllnZOxhPOQuUcn2Iw+BKkHARtlGqf4t4foJEddcFgVFqRgruCYZqR4sH34ebc1jj3665MWffOSeh9fit4qAS1LXCQUwKxqPPWxG7rHmIDG71pB/pUDBfb57wzuGODpbpvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790007399; c=relaxed/simple; bh=dULV58mNOCnJcJ7F0Bkx1slCXFnPOCdqFpowHka26FA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pH4eJGfz3caDmGJQF9koBxRjDBWldHp+PPV8v0bMqYfCwpsgtSroj5ZSCtLWQKq4+9C9mHtHQCDpWK8SKTk0ELUu08Ut5sGPDg8RI5WjzBU7neQND8Ius2jd5yJuDwAFy9EeV2WT6dCkTIPuY03YHXt0exITVtfWqeqh0YxqKVU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=I9ouSAj4 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14C214BA799A Received: by mail-oi2-x10.google.com with SMTP id 5614622812f47-4b37a2c0356so1756796b6e.2 for ; Mon, 21 Sep 2026 09:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1790007398; x=1790612198; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lPYj492/QNUMKxiU94ePq0lGVZfiji9LviChvRfKnZo=; b=I9ouSAj4jJvkRT2ii7DZ9aRYiYzZ3NLeYc6dMaSDqIjBciVDU80f013IJjb8zvQqR6 JJ4yNQIq02D4+AwCFqZmd5HrEVedYbB0pChVRV4gus+jnM5GYkWvXi/kAHXUzfOKn3Lq zZI7usEgh61Vm7B3Pgi2WyYphtGwxabjEjBLQK4bVAMsy8LKKG98HEDu9ZsgdaK/NOA6 u7JWQoqXis9SsX/+TbPrHc20o52SpVx1EaOmAuOQDMHDZC0FCKC++UoasDj0or/oPS8k 9QWQrqGd+Gh8zGnw9hUf3RBpFtyQCSRPr0opn+SA9dKXfWul7M4IgkVhk1bXqlXI11Uo 5Jrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790007398; x=1790612198; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lPYj492/QNUMKxiU94ePq0lGVZfiji9LviChvRfKnZo=; b=R7OUmhIDG1QvD0rGt6/yBcBfFwmnktvjF8RXljnYLrnZPoDO+9MuUXU7haka4AKUpJ a8K8dcdrS4q9turA089p/LNGx/wciV34CDTMtgNSlLKwVJv8+TJpE0nGzkhhS0Hd7xtL tfFyw7lA881q355h9Z/x8YUfY0XD+Y4tIf70Hqxy7Nh9TzrmyL70az536UeOSKFeqTz6 5QHMOK4eTD6Q4aAeqO3fhZsGiAwJT2PmIq4JLLPiAZ82nMnC5jymk67C+9eYDEu0HEGv FkyDXPmenpfJBg81RDb4EMtp1EdbsoXe2wquis/S6WseS3pmmEUgM49SlTQlvUf4Zkvb PiQg== X-Gm-Message-State: AFuF++lWh4+TZpExHV9Fu53Ll6Z2kXGIxoVhNBBrDfGlvJbbk+jZ9xnr tNeVGxZJb5+VhgiTuoAJ9j2eurhkIedwPn6soCfuLbU8dXeoO2/cx27b8oklafZ/lmg98LmmIUT XMFc0QA== X-Gm-Gg: AYBFou24biUN3XGZYdX7eDf2D9mc+Y/iQ2XMQOuSju1H2isbXAxAsCdctThMqnv2ywe vA4oVAw2Mn5h96nmB0OUkiLxQ2kbfwrwfFIu9JQ4TyPes4Mh+HxyixZNfdMs/2Y6txNo9JzjsMX v1vdAPNCKuUgNWUYbt8MTUKUZaGdA2Y4iOIWNVu2ouq3AusdZLF0u7qS9ZTlTPLHw2vTBOmcYio kJaVcr8OpXWPMLWUvUzIwlw6ozyhznq7xbBEZLCAuoajkeP+HLmvxjSfJe4UTfDyudDVrZugu8b t6AV5uDYrQcA0yD9xU9kJmpo6zsHdp4J6jOjiDSiF8vN+6mCEMlEQLL7tkGrItyGJLk+vahQ154 9yXnxT0ged2KK8EXXGVGTG4zlUeo6Kgg6zV5ep8EUFXtjA4jfe/IizZ9JLC+dxIu0PxwCP0jVpA WjfpHf6ngAJ7VUd/GBSanAscjR4BEDSmAiT/AZ6ZoNS909Qph7AgqJTQKezwiHyMfAYWh4RICFc bs2OarINguKpKSlfOo= X-Received: by 2002:a05:6808:16ab:b0:4ab:230c:5faa with SMTP id 5614622812f47-4ccf6647177mr10603795b6e.18.1790007398322; Mon, 21 Sep 2026 09:16:38 -0700 (PDT) Received: from bapiya (75-166-229-74.hlrn.qwest.net. [75.166.229.74]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4d4236077d2sm464854b6e.10.2026.09.21.09.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2026 09:16:36 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Return lazy value from allocate_repeat_value Date: Mon, 21 Sep 2026 10:16:32 -0600 Message-ID: <20260921161632.1602438-1-tromey@adacore.com> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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} + 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' ...}}] + gdb_test_no_output "set max-value-size 65536" + gdb_test_no_output "set print elements 200" } proc test_print_char_arrays {} { diff --git a/gdb/valops.c b/gdb/valops.c index a235a0ebe8d..f9d83ce81f8 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1387,10 +1387,6 @@ value_repeat (struct value *arg1, int count) val->set_lval (lval_memory); val->set_address (arg1->address ()); - read_value_memory (val, 0, val->stack (), val->address (), - val->contents_all_raw ().data (), - type_length_units (val->enclosing_type ())); - return val; } diff --git a/gdb/value.c b/gdb/value.c index d7c724757ce..6061d346dd5 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1025,7 +1025,7 @@ allocate_repeat_value (struct type *type, int count) struct type *array_type = lookup_array_range_type (type, low_bound, count + low_bound - 1); - return value::allocate (array_type); + return value::allocate_lazy (array_type); } struct value * base-commit: 3e5100fe3b15e2b3ece60f57b4c1ecc0c50cae53 -- 2.55.0