From nobody Fri Apr  4 13:51:03 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=linaro.org
ARC-Seal: i=1; a=rsa-sha256; t=1742942872; cv=none;
	d=zohomail.com; s=zohoarc;
	b=SaBI1M4UmDpCXLpa8b+HDUEfeSs/MgDfQmaRoheNH9XyLnBUxE8TqpMB1UpAVINYClpoA1D7TtbjbHZj8es8mOHXb3emjzTIZOYwbzEN4zT90CTo+6dHTwV9N+53kHMY+H0E+BkW/oG/PC/fzrSJl0JVevpJa08fzDyOXkm30rY=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1742942872;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=QHX5k2lUgvMa0RL4ytQ9eAaxeLEElDmk4Ql4Y4+DSI8=;
	b=Z5j1fT4UUIteQoL7nkOj9ofZQUE4mXPAgKSUjES0U7QwgnJqYH+krZyjRz7SyWw9QLMJkPQ2LBc8hkBjZcn3woWH5KKRF9SymPHhCbQES0WaikqkGn1g8ug6N86rdP92sPOPo7mk4jQQkCTXvnBiieD2wj8Flo467pRWRAR5BTE=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<richard.henderson@linaro.org> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1742942872445926.7475633482903;
 Tue, 25 Mar 2025 15:47:52 -0700 (PDT)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1txD0K-0001lx-Vn; Tue, 25 Mar 2025 18:44:17 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)
 id 1txD0D-0001LT-SF
 for qemu-devel@nongnu.org; Tue, 25 Mar 2025 18:44:10 -0400
Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)
 id 1txD0B-00071y-6s
 for qemu-devel@nongnu.org; Tue, 25 Mar 2025 18:44:09 -0400
Received: by mail-pl1-x633.google.com with SMTP id
 d9443c01a7336-2240b4de12bso59342585ad.2
 for <qemu-devel@nongnu.org>; Tue, 25 Mar 2025 15:44:06 -0700 (PDT)
Received: from stoup.. (174-21-74-48.tukw.qwest.net. [174.21.74.48])
 by smtp.gmail.com with ESMTPSA id
 d2e1a72fcca58-7390611d3d6sm11111321b3a.94.2025.03.25.15.44.04
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 25 Mar 2025 15:44:05 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=linaro.org; s=google; t=1742942645; x=1743547445; darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=QHX5k2lUgvMa0RL4ytQ9eAaxeLEElDmk4Ql4Y4+DSI8=;
 b=JuHSFqQgR/e307E96SkDtTDBCXlVEu4aAX7qBh3YOqwo563O3dnJJSTr+ZEuX71HuX
 n1eqdV/lGxAArpguyNhvcocCykVGo9g2YZQZLrA8MW//EkhM8+rkTWqIk40nJcKeY+0H
 IdC5bK/PXhnB48WOq9fjxv0YGO/pkLkv0oVAFhZ5B3EKQaEHA+ENW56kKG6DsPXn6XYK
 zxOglN9k4821iUrqtZ/KLCdYV2cJ93N4keis9ceincNRnWW3ofAQJF2Cwl2AeVFftxu+
 50I6Y4r6QXOOnJRBmyozCZquWK2rzbUj7edkHdBu4JvUu5nuFXBrsZmKgqGn7Cxx3WlJ
 4muw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1742942645; x=1743547445;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=QHX5k2lUgvMa0RL4ytQ9eAaxeLEElDmk4Ql4Y4+DSI8=;
 b=Zy6G3Ug8+8fEdYlZDcQgu5qz9prGyP5By5ouIYDHrh0K9Z/enp4eTCH4drgiySyNFt
 tJGNJdgoKEzP14VuA+LHuBYioNnFM7NA8GyRgEyvBA+rX5aXsCfMmVA/ong4PCzqLLMl
 tPn/0uidWy/E3l+OaAokcw1ey6qBUntZePBDgxD/GzqcTCqPN7SBWmMFxTzwAR2y3z55
 WydYvOZQk1jq0f/2P96ZIy6nQmCQaWu1dnT6XxTYmD4RN6O05z1xCqPYfRCxbqzO4f66
 XU8DsvKnac7Ngh53v/ixfkp8EOOie0KpupdukLE1DNknnBqzPP9liOWoTSQDupbp9jnQ
 7Gww==
X-Gm-Message-State: AOJu0YxoWKfwnG9IEgMKOD8iQErJ2DB2nVre9r3NXzeBOC+s5PumREHE
 F0w1eDTeeADupIlT1/3LpR8ZDKK5jobW+bfS7FBCrMeMGdoZdpHJA1Gj/teFvEW5X88DduZQzvJ
 X
X-Gm-Gg: ASbGnctHMMhLz4/OAuEydHjak+AgVBVmoKqj8yEZJ6HTWrwtoSJxJd6t2mibCmNhmid
 sx1S6tJ6vQDRpJUpx0W4qYGGLaOzv9XxfPx0oFcYhOs7IW6fTcRfnWfbUtHCPOAuT3IJM4ye0BV
 4TMrPocJYJJJu5qVIfxEJc2MZNyxy0UhQ0hfn2ON2A87E7giFLFmfrzrxc+B7ix+Xs6ZGVaWyJK
 S8a48tOo2jxH7YBKXeJzAiWNTl1gzQsf3ahLMZdxuBe0mCs3EVyiZdikczTXSLNSiOe+Z0l1Qh+
 kxqWYf3P5Pn0wY+rSQeD5glYUwGOf7uiLMDqyR+HsC0lPT9SFZM0lMJbTLoiToCrGpkheQYakyA
 d
X-Google-Smtp-Source: 
 AGHT+IF1BdqqhDB1O6iCoCoQnLWgNuFN+hT2nfQObV+5Idf262uhi43wCOk4OldnVlQVKvLkB7lxog==
X-Received: by 2002:a05:6a00:1995:b0:736:34a2:8a18 with SMTP id
 d2e1a72fcca58-73905a27860mr31732395b3a.24.1742942645338;
 Tue, 25 Mar 2025 15:44:05 -0700 (PDT)
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: mrolnik@gmail.com, philmd@linaro.org, pierrick.bouvier@linaro.org,
 qemu-stable@nongnu.org
Subject: [PATCH v2 01/11] target/avr: Fix buffer read in avr_print_insn
Date: Tue, 25 Mar 2025 15:43:53 -0700
Message-ID: <20250325224403.4011975-2-richard.henderson@linaro.org>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20250325224403.4011975-1-richard.henderson@linaro.org>
References: <20250325224403.4011975-1-richard.henderson@linaro.org>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=2607:f8b0:4864:20::633;
 envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @linaro.org)
X-ZM-MESSAGEID: 1742942874890019100
Content-Type: text/plain; charset="utf-8"

Do not unconditionally attempt to read 4 bytes, as there
may only be 2 bytes remaining in the translator cache.

Cc: qemu-stable@nongnu.org
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daud=C3=A9 <philmd@linaro.org>
---
 target/avr/disas.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/target/avr/disas.c b/target/avr/disas.c
index b7689e8d7c..d341030174 100644
--- a/target/avr/disas.c
+++ b/target/avr/disas.c
@@ -68,28 +68,35 @@ static bool decode_insn(DisasContext *ctx, uint16_t ins=
n);
=20
 int avr_print_insn(bfd_vma addr, disassemble_info *info)
 {
-    DisasContext ctx;
+    DisasContext ctx =3D { info };
     DisasContext *pctx =3D &ctx;
     bfd_byte buffer[4];
     uint16_t insn;
     int status;
=20
-    ctx.info =3D info;
-
-    status =3D info->read_memory_func(addr, buffer, 4, info);
+    status =3D info->read_memory_func(addr, buffer, 2, info);
     if (status !=3D 0) {
         info->memory_error_func(status, addr, info);
         return -1;
     }
     insn =3D bfd_getl16(buffer);
-    ctx.next_word =3D bfd_getl16(buffer + 2);
-    ctx.next_word_used =3D false;
+
+    status =3D info->read_memory_func(addr + 2, buffer + 2, 2, info);
+    if (status =3D=3D 0) {
+        ctx.next_word =3D bfd_getl16(buffer + 2);
+    }
=20
     if (!decode_insn(&ctx, insn)) {
         output(".db", "0x%02x, 0x%02x", buffer[0], buffer[1]);
     }
=20
-    return ctx.next_word_used ? 4 : 2;
+    if (!ctx.next_word_used) {
+        return 2;
+    } else if (status =3D=3D 0) {
+        return 4;
+    }
+    info->memory_error_func(status, addr + 2, info);
+    return -1;
 }
=20
=20
--=20
2.43.0