ref: 413609195feb8bd92c45204536c925a1006cba9e
parent: 15d3cccf394c8c68e3d6e8311c3b50910ad23f91
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Sep 21 07:35:00 EDT 2019
[as-powerpc] Check correct limits in i_form()
--- a/src/cmd/as/target/powerpc/ins.c
+++ b/src/cmd/as/target/powerpc/ins.c
@@ -135,7 +135,9 @@
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 @@
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);
}