scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit ef4381d70e872c9a64381859e31808df19c7a331
parent 3af89ed93fc8971073678c0d480cb8ded8b560ff
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 21 Sep 2019 11:35:00 +0200

[as-powerpc] Check correct limits in i_form()

Diffstat:
Msrc/cmd/as/target/powerpc/ins.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/cmd/as/target/powerpc/ins.c b/src/cmd/as/target/powerpc/ins.c @@ -135,7 +135,9 @@ void i_form(Op *op, Node **args) { unsigned long ins, opcd, li, aa, lk; - unsigned long long dst; + long long dst; + long long max = 1l << 23; + long long min = -(1l << 23); opcd = op->bytes[0]; aa = op->bytes[1]; @@ -146,8 +148,11 @@ i_form(Op *op, Node **args) error("unaligned branch"); if (aa) dst -= cursec->curpc - 4; - li = dst >> 2; + if (dst < min || dst > max) + error("out of range branch"); + li = dst; + li >>= 2; ins = opcd<<26 | li<<2 | aa<<1 | lk; emit_packed(ins); }