]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.10] cmd/compile: prevent overflow in walkinrange
authorAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 22 Aug 2018 12:01:22 +0000 (14:01 +0200)
committerDmitri Shuralyov <dmitshur@golang.org>
Thu, 1 Nov 2018 20:08:12 +0000 (20:08 +0000)
commit30ccc6284ad283bae86dfdd8c0e77d65f3d6a4f9
treeebce1deb2ecfcd5b98d575fd61e4973a8317d72a
parent15c6cc7c67ff299d8259f7c7950ee8b49555bbfe
[release-branch.go1.10] cmd/compile: prevent overflow in walkinrange

In the compiler frontend, walkinrange indiscriminately calls Int64()
on const CTINT nodes, even though Int64's return value is undefined
for anything over 2⁶³ (in practise, it'll return a negative number).

This causes the introduction of bad constants during rewrites of
unsigned expressions, which make the compiler reject valid Go
programs.

This change introduces a preliminary check that Int64() is safe to
call on the consts on hand. If it isn't, walkinrange exits without
doing any rewrite.

Fixes #27247

Change-Id: I2017073cae65468a521ff3262d4ea8ab0d7098d9
Reviewed-on: https://go-review.googlesource.com/130735
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
(cherry picked from commit 42cc4ca30a7729a4c6d1bb0bbbc3e4a736ef91c8)
Reviewed-on: https://go-review.googlesource.com/c/131595
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/walk.go
test/fixedbugs/issue27143.go [new file with mode: 0644]