Verify an immediate value fits into 32 bits before jumping to it/calling it with a 32-bit immediate operand. Without this fix, code along the lines of ((int (*)(const char *, ...))140244834372944LL)("hi\n"); will fail mysteriously, even if that decimal constant is the correct address for printf. See https://github.com/pipcet/tinycc/tree/bugfix-1
Unified · Split
| @@ -600,7 +600,8 @@ void store(int r, SValue *v) · 599 unmodified lines | ||
| 600 | 600 | static void gcall_or_jmp(int is_jmp) |
| 601 | 601 | { |
| 602 | 602 | int r; |
| 603 | − if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { | |
| 603 | + if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && | |
| 604 | + ((vtop->r & VT_SYM) || (vtop->c.ll-4) == (int)(vtop->c.ll-4))) { | |
| 604 | 605 | /* constant case */ |
| 605 | 606 | if (vtop->r & VT_SYM) { |
| 606 | 607 | /* relocation case */ |