m68k: fix undefined abs() of INT32_MIN displacement in printer#2990
m68k: fix undefined abs() of INT32_MIN displacement in printer#2990Samin061 wants to merge 1 commit into
Conversation
|
There is literally an util function for it. |
|
Took another look at this. printInt32HexOffset/printInt16HexOffset do handle the same UB, but they emit the offset as +0x.../-0x..., which changes the M68K $ syntax and the existing m68k.yaml detail case (e.g. To keep the disassembly output byte-for-byte identical I dropped the local helper and used the same well-defined unsigned negation those utils rely on internally, inline at the three 32-bit sites. I also added a cstest case in tests/details/m68k.yaml asserting the INT32_MIN outer displacement prints as I pushed the update to the branch, but GitHub won't let me reopen since it was force-pushed. If you'd rather standardize on the 0x offset form I'm happy to switch to the util and update the affected M68K tests instead. Let me know how you'd like to proceed (reopen on your side, or a fresh PR). |
Your checklist for this pull request
Detailed description
printBaseDispandprintMemIndirectprint a 32-bit displacement by callingabs()onop->mem.in_disp/op->mem.out_disp, but those fields are filled fromread_imm_32in the disassembler, so a crafted M68K memory-indirect operand can set them toINT32_MIN, whereabs()negates a value with no representable positive counterpart and the behavior is undefined. The magnitude now goes through a small unsigned-negation helper so it stays well-defined at the three 32-bit sites; the sign is already printed separately, so the output is unchanged. Theint16_t dispsites cannot reachINT32_MINand are left alone.Test plan
Building with
-fsanitize=undefinedand runningtest_pocaborts atM68KInstPrinter.concs_disasmof the newtest_ub_abs_m68k_dispinput before the change and exits cleanly after. That case disassembles a full-format memory-indirectmove.wwhose outer displacement is0x80000000.Closing issues