yrp604 / rappel

A linux-based assembly REPL for x86, amd64, armv7, and armv8
Other
1.16k stars 55 forks source link

Invalid instruction is executed #12

Closed disconnect3d closed 6 years ago

disconnect3d commented 6 years ago

After:

> mov qword [rsp-0x1234], 0x1122334455667788
> mov qword rbx, [rsp-0x1234]

The result in rbx is:

rbx: 0x0000000055667788

The fact is that the first instruction is not really valid as the operand size is too big. Actually it prints out a warning about it, but it is super easy to miss it:

> mov qword [rsp-0x1234], 0x1122334455667788
/dev/fd/3:3: warning: signed dword immediate exceeds bounds [-w+number-overflow]
/dev/fd/3:3: warning: dword data exceeds bounds [-w+number-overflow]

Can we make this warning an error and not continue on that?

yrp604 commented 6 years ago

Hey, thanks for the bug report.

I've changed the behavior here a bit: after piping user input to nasm we now capture both stdout (the bytecode) and stderr (warnings). If anything is written to stderr, we dump it and truncate the bytecode length to 0 so the state will be unchanged. In pipe mode this is an error and we exit(1). UI mode treats it as an assembly failure basically -- previously we would have warned and executed nasms best effort at assembling the instruction, now we warn and don't execute anything. I'd rather not make it an error, because the ui quitting due to the user entering an invalid instruction like this could be very annoying.

Does this work for you?

PS: I also found an fd leak when changing this :)