From nobody Sun Nov 9 22:32:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551986858537722.9751316758835; Thu, 7 Mar 2019 11:27:38 -0800 (PST) Received: from localhost ([127.0.0.1]:58129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1yg2-000311-G6 for importer@patchew.org; Thu, 07 Mar 2019 14:27:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1yC9-0001Qv-Ow for qemu-devel@nongnu.org; Thu, 07 Mar 2019 13:56:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1yC8-0002ZP-N5 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 13:56:41 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:33904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1yC8-0002Xz-EA for qemu-devel@nongnu.org; Thu, 07 Mar 2019 13:56:40 -0500 Received: by mail-pf1-x432.google.com with SMTP id u9so12138361pfn.1 for ; Thu, 07 Mar 2019 10:56:40 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id g12sm8801973pgr.76.2019.03.07.10.56.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Mar 2019 10:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=nW8JphH6Qh+JwrnKEHPQE427juS/l8m1uTk3laZENPE=; b=rS/BGypu/qEfjzfSehSc224dhT/p4UOaZRercF5tbrLIsz6PzMA4LwA+WLCyNh++8V +jkJeC8kvdEewwuX82aYoEXS2NCO2Ol1BbWc+TRvijXqXs3WfkVvZ6Xhyp7zHB1AAVW/ 3yr+pI3zi6Iq1s1K1DqOSR11+B7VsFeIWJ1zXbbIDMBxntUatdvnGehTLW7KdBWeYYup obTxWz65rwZUwt4JWlA4j5bdlHaBmh8SuzZlvZaNdRzd2jnSIAW/XIKmoRNBmv3xtj4m WzjDBVvrqY2axl5bagc9lUshTUSvfe1uMsMflqJB+Eg768T4In08QCwcIcshWRNmpbTU TrCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nW8JphH6Qh+JwrnKEHPQE427juS/l8m1uTk3laZENPE=; b=S5gMvMi4y3gOHutFu8fEZHPFsxRfi7fXnCacTf9xQRfg7pLgKc2Yi8uhuAPfSWJY5f AL7jPnVGzSrAddD4zaVauS/yX14Kiiyuw5jSYYE/3bMzRr/oZ9mw8+kuTT0nw6wcK1os XEONxoPpyVRYsolLWtNygvQ0C7uLK3oPfiDUK8f2V57xCbiuHMgLLSTNNeHW+rjhnMeW OMJR7qcM273jcJU/2V7YgTKBsgSxB0ieDOm1UiH+ZayWQXwATvdMcLO/51q55xjxLmCR cMy099uK/JCdrnOBUxIW2PrlnI2mABOxVW9VLt592aXC7wqcUQL/bBCSDKl8+dP59vsz jLKg== X-Gm-Message-State: APjAAAX8zX9L4kmmuXikFpACmQii5q2JGQJX1lZif4cvfyyMXhVBQIOz rtPpYhCD62kK5fIb+0142rBYSEYBWNM= X-Google-Smtp-Source: APXvYqzFxZ6T9NV5JxXfRlTiH3JRMdT0fGhpx40SxmGHCkxbhucUw4Cb7xpCl1sYnltCvSRA7MUG+g== X-Received: by 2002:a63:d542:: with SMTP id v2mr12828091pgi.52.1551984998961; Thu, 07 Mar 2019 10:56:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:56:22 -0800 Message-Id: <20190307185622.29026-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190307185622.29026-1-richard.henderson@linaro.org> References: <20190307185622.29026-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::432 Subject: [Qemu-devel] [PATCH v3 12/12] decodetree: Properly diagnose fields overflowing an insn 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Previously this would result in an exception for shifting the field mask by a negative number. Signed-off-by: Richard Henderson --- scripts/decodetree.py | 2 ++ tests/decode/err_width1.decode | 5 +++++ tests/decode/err_width2.decode | 5 +++++ tests/decode/err_width3.decode | 5 +++++ tests/decode/err_width4.decode | 5 +++++ 5 files changed, 22 insertions(+) create mode 100644 tests/decode/err_width1.decode create mode 100644 tests/decode/err_width2.decode create mode 100644 tests/decode/err_width3.decode create mode 100644 tests/decode/err_width4.decode diff --git a/scripts/decodetree.py b/scripts/decodetree.py index f8df89e072..7e890ecf1a 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -622,6 +622,8 @@ def parse_generic(lineno, is_format, name, toks): sign =3D True flen =3D flen[1:] shift =3D int(flen, 10) + if shift + width > insnwidth: + error(lineno, 'field {0} exceeds insnwidth'.format(fname)) f =3D Field(sign, insnwidth - width - shift, shift) flds =3D add_field(lineno, flds, fname, f) fixedbits <<=3D shift diff --git a/tests/decode/err_width1.decode b/tests/decode/err_width1.decode new file mode 100644 index 0000000000..0c14f6d73b --- /dev/null +++ b/tests/decode/err_width1.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too many bits (33 of 32) +one 000000000000000000000000000000000 diff --git a/tests/decode/err_width2.decode b/tests/decode/err_width2.decode new file mode 100644 index 0000000000..47f0acf322 --- /dev/null +++ b/tests/decode/err_width2.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too few bits (31 of 32) +one 0000000000000000000000000000000 diff --git a/tests/decode/err_width3.decode b/tests/decode/err_width3.decode new file mode 100644 index 0000000000..c5fb6b3699 --- /dev/null +++ b/tests/decode/err_width3.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too many bits (33 of 32) +one 0 s:32 diff --git a/tests/decode/err_width4.decode b/tests/decode/err_width4.decode new file mode 100644 index 0000000000..1588a63698 --- /dev/null +++ b/tests/decode/err_width4.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too few bits (31 of 32) +one 0 s:30 --=20 2.17.2