From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v3 12/12] decodetree: Properly diagnose fields overflowing an insn
Date: Thu, 7 Mar 2019 10:56:22 -0800 [thread overview]
Message-ID: <20190307185622.29026-13-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190307185622.29026-1-richard.henderson@linaro.org>
Previously this would result in an exception for shifting
the field mask by a negative number.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
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 = True
flen = flen[1:]
shift = int(flen, 10)
+ if shift + width > insnwidth:
+ error(lineno, 'field {0} exceeds insnwidth'.format(fname))
f = Field(sign, insnwidth - width - shift, shift)
flds = add_field(lineno, flds, fname, f)
fixedbits <<= 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 later.
+# 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 later.
+# 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 later.
+# 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 later.
+# See the COPYING.LIB file in the top-level directory.
+
+# Diagnose too few bits (31 of 32)
+one 0 s:30
--
2.17.2
prev parent reply other threads:[~2019-03-07 18:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-07 18:56 [Qemu-devel] [PATCH v3 00/12] decodetree enhacements Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 01/12] MAINTAINERS: Add scripts/decodetree.py to the TCG section Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 02/12] decodetree: Move documentation to docs/devel/decodetree.rst Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 03/12] decodetree: Document the usefulness of argument sets Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 04/12] decodetree: Ensure build_tree does not include values outside insnmask Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 05/12] decodetree: Do not unconditionaly return from Pattern.output_code Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 06/12] decodetree: Allow grouping of overlapping patterns Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 07/12] test/decode: Add tests for PatternGroups Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 08/12] decodetree: Add --static-decode option Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 09/12] decodetree: Produce clean output for an empty input file Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 10/12] decodetree: Allow +- to begin a number initializing a field Richard Henderson
2019-03-07 18:56 ` [Qemu-devel] [PATCH v3 11/12] decodetree: Prefix extract function names with decode_function Richard Henderson
2019-03-07 18:56 ` Richard Henderson [this message]
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=20190307185622.29026-13-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).