From nobody Mon Feb 9 11:31:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488557187380930.9812945771752; Fri, 3 Mar 2017 08:06:27 -0800 (PST) Received: from localhost ([::1]:58806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjpip-0006wT-Nc for importer@patchew.org; Fri, 03 Mar 2017 11:06:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjpgc-0005m2-S1 for qemu-devel@nongnu.org; Fri, 03 Mar 2017 11:04:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjpgc-0000KM-3l for qemu-devel@nongnu.org; Fri, 03 Mar 2017 11:04:06 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48759) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjpgb-0000Jj-TQ for qemu-devel@nongnu.org; Fri, 03 Mar 2017 11:04:06 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cjpTY-0006Dl-E9; Fri, 03 Mar 2017 15:50:36 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 15:50:31 +0000 Message-Id: <1488556233-31246-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488556233-31246-1-git-send-email-peter.maydell@linaro.org> References: <1488556233-31246-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.9 4/6] disas/microblaze: Avoid unintended sign extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , patches@linaro.org, Laurent Vivier , Paolo Bonzini , "Edgar E. Iglesias" , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In read_insn_microblaze() we assemble 4 bytes into an 'unsigned long'. If 'unsigned long' is 64 bits and the high byte has its top bit set, then C's implicit conversion from 'unsigned char' to 'int' for the shift will result in an unintended sign extension which sets the top 32 bits in 'inst'. Add casts to prevent this. (Spotted by Coverity, CID 1005401.) Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias --- disas/microblaze.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index 91b30ac..407c0a3 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -748,9 +748,11 @@ read_insn_microblaze (bfd_vma memaddr, } =20 if (info->endian =3D=3D BFD_ENDIAN_BIG) - inst =3D (ibytes[0] << 24) | (ibytes[1] << 16) | (ibytes[2] << 8) | ib= ytes[3]; + inst =3D ((unsigned)ibytes[0] << 24) | (ibytes[1] << 16) + | (ibytes[2] << 8) | ibytes[3]; else if (info->endian =3D=3D BFD_ENDIAN_LITTLE) - inst =3D (ibytes[3] << 24) | (ibytes[2] << 16) | (ibytes[1] << 8) | ib= ytes[0]; + inst =3D ((unsigned)ibytes[3] << 24) | (ibytes[2] << 16) + | (ibytes[1] << 8) | ibytes[0]; else abort (); =20 --=20 2.7.4