From patchwork Tue Mar 12 17:03:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160168 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13394056jad; Tue, 12 Mar 2019 10:58:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJV3bCPkTj98ml88m+/Rhts65ZaDrsaEETS6bzR1+Al6EzSc1BkfLZAEZFy0gPT17S9qrP X-Received: by 2002:a81:6f87:: with SMTP id k129mr1415932ywc.322.1552413535335; Tue, 12 Mar 2019 10:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552413535; cv=none; d=google.com; s=arc-20160816; b=1GAQJ0gMGmpurjEAVpL+ybWQ9isrwZPojTTHDRFHfHe2YOYpfZEoTsNX+oJtiQELZc slirCP9i9J71bPo6N74OTwwsIfAIn/H6D+zHv/iej9VPPT/vhTqKZs0wgMP6gVw569Cb RvlUUO2VOiPv5cb9lC+cwI9NFCybYjloGRQ9GVnIuWkiXWfxgxG/FQ/fZJna3YaHSt3w FQakJNAnc/nPxDB4rzFJ3+cGwMqTt70sXbg8RGyym2eDk86dOPZwtzNwZFFR4hc9lLn3 Y6EAWxsje46pd0jffC9ZQzlwPhv0glKGJHrT1a8YEWcU/5K/kAda9YPqctnwmA0tWqdg lKvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=U8jWfxjTB06zNjuAV7mfMguhymjQ42j8YO1WeS5mESc=; b=nZhnxroSlIR+HxH/pnttpa20orOkdb2U2IkdMhNLlNSihg0g5sxOVj4tgJ53GUGPUt bwdRYyKLLGA36DA+3FK2OUcHJ+dL2ttsDeUk3a96NjEBg8wDheJj0d7NwUpQpslBOAfC ZZZeFBBUN+Uo2xjAHjlrX5HCBOPXHvgtG6MSYUGB2QR2UikwEwTF3zhu4Hxi5eiaGC8u bn73ex3HNCTCNygHDmhlUkLBR7ymhNEVnwcomHGtn0KH4HrvbvuHIb2U8OeBd53BteQ3 tes+GmpKk4ib4tzmbOadc6XWOcDs3MCksHfmFeQIFzOt4gEjfJ3fiuLVCbPf4rlHNvv0 jUDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xsH7aTH1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x1si5339530ybj.360.2019.03.12.10.58.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 10:58:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xsH7aTH1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3lfy-0006eR-Qx for patch@linaro.org; Tue, 12 Mar 2019 13:58:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3l3N-00061D-4t for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:19:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3kow-0001QP-IK for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:04:08 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:38143) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3kou-0001Hy-Dc for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:04:06 -0400 Received: by mail-pf1-x436.google.com with SMTP id n125so2268756pfn.5 for ; Tue, 12 Mar 2019 10:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U8jWfxjTB06zNjuAV7mfMguhymjQ42j8YO1WeS5mESc=; b=xsH7aTH1ypem/GskMg+ekwHrPBadXraRVOJIwXzTC7EFMqjRd5z8+kqZeNnyd4zi2m wpUblVuSEh5+eSHUwqbyUqJNXpBhmbwQnJ1ZFZ7GRSHfUTMivMnKXB71VvxkKjuCHP4X kPv6WpdOhvj8Ca+1G5C7+TPuiarcaLsg1ewzN4GAJzUFRHZQOQAeSBjs1dWhf70C7Yf/ w1Z/ZXc4OS6pBP7FiRfAjZXYh3V3saQQLtCL64ql+fUJBtyTcSzoXXUBxp21txm9oTYq AGFQ40vEU5+jGn9t3Snwo+/7imA/eFHeCUQoSyALughRULvBH/QqwVkmzoUZUKFVL3AG yeNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U8jWfxjTB06zNjuAV7mfMguhymjQ42j8YO1WeS5mESc=; b=czq9/jwCIZM28I6HqcXoFlMBYgIlPAUWaPm5Tymj/zkL+CD9T4Fzc2/MVs+IL805RR +yS7n+vAqB4p7tdLerMXcN0L/cDwZoDW9Nv2RNu8jkQsyDF/YtJXhfevtix/5Na1a7Yj Bnm0wnsiKTlS4d42PaEP/XqR30ovcd9eT6UV89J68Mfha7MYEiIcxEJ5AJWDx2cetMzZ EC5FenroBZV74k2dCP9HY+Y757rxEt9AJH2fHC2CqqMYgVqQTJNnm2QSrumtKg7p7Wr/ fltAnwqSUEN0u1wfDTK18U+Aqk3eU2XpwlGNIFoLdioRmBuovJjPsz13mfVdJXbGQDFw nzUw== X-Gm-Message-State: APjAAAXrVTKuz+2q7TbMbW4z+XgDEflzdGUiLVyYrH82roVQ0IBwL5pu gageCAZlB6AKOQqcAovLaQ7RS/KXfRA= X-Received: by 2002:aa7:8a59:: with SMTP id n25mr4908227pfa.251.1552410232995; Tue, 12 Mar 2019 10:03:52 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id v22sm17514265pfa.49.2019.03.12.10.03.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2019 10:03:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 10:03:34 -0700 Message-Id: <20190312170334.14005-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190312170334.14005-1-richard.henderson@linaro.org> References: <20190312170334.14005-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::436 Subject: [Qemu-devel] [PULL 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: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 -- 2.17.2 diff --git a/scripts/decodetree.py b/scripts/decodetree.py index ac158b42d0..aa790b596a 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