devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Ziureaev <andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 1/6] dtc: Avoid UB when shifting
Date: Tue, 14 Jul 2020 16:45:37 +0100	[thread overview]
Message-ID: <20200714154542.18064-2-andrei.ziureaev@arm.com> (raw)
In-Reply-To: <20200714154542.18064-1-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>

Prevent undefined behavior when shifting by a number that's bigger than
or equal to the width of the first operand.

Signed-off-by: Andrei Ziureaev <andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
---
 dtc-parser.y | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index 40dcf4f..a0316a3 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -476,8 +476,8 @@ integer_rela:
 	;
 
 integer_shift:
-	  integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; }
-	| integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; }
+	  integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; }
+	| integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; }
 	| integer_add
 	;
 
-- 
2.17.1


  parent reply	other threads:[~2020-07-14 15:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 15:45 [PATCH v2 0/6] dtc: Add support for signed operations Andrei Ziureaev
     [not found] ` <20200714154542.18064-1-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-07-14 15:45   ` Andrei Ziureaev [this message]
     [not found]     ` <20200714154542.18064-2-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-07-15 10:41       ` [PATCH v2 1/6] dtc: Avoid UB when shifting David Gibson
2020-07-14 15:45   ` [PATCH v2 2/6] dtc: Add bytestring type Andrei Ziureaev
2020-07-14 15:45   ` [PATCH v2 3/6] dtc: Turn 'uint64_t integer' into a struct Andrei Ziureaev
2020-07-14 15:45   ` [PATCH v2 4/6] dtc: Add support for signed operations Andrei Ziureaev
     [not found]     ` <20200714154542.18064-5-andrei.ziureaev-5wv7dgnIgG8@public.gmane.org>
2020-08-03 10:21       ` David Gibson
2020-07-14 15:45   ` [PATCH v2 5/6] dtc: Preserve negative integers in yaml and dts Andrei Ziureaev
2020-07-14 15:45   ` [PATCH v2 6/6] dtc: Add sign preservation and operation tests Andrei Ziureaev

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=20200714154542.18064-2-andrei.ziureaev@arm.com \
    --to=andrei.ziureaev-5wv7dgnigg8@public.gmane.org \
    --cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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).