peda icon indicating copy to clipboard operation
peda copied to clipboard

[bug] "start" command evaluates math expression

Open mdumitru opened this issue 7 years ago • 0 comments

Consider the following program:

#include <stdio.h>
int main(int argc, char *argv[]) { puts(argv[1]); }

Compile it as "prog".

Now let's run it under gdb, without peda, with "-10" as the argument: gdb -n -batch -ex "file ./prog" -ex "start -10" -ex "continue" We get the expected string: "-10"

Running it under gdb, with peda, same argument: gdb -batch -ex "file ./prog" -ex "start -10" -ex "continue" We get the string "-0xa", which means the "start" command converted our number before passing it to the program.

This conversion only seems to happen for negative numbers (passing "10", we get the expected "10") and doesn't happen under the "run" command.

Edit: After looking around the source code, it seems the issue is more profound. Any "math expression" passed to start will be evaluated and converted to a hexadecimal representation, because invoke always calls string_to_argv, which among other things calls python's eval if is_math_exp returns True (which maybe it shouldn't for negative numbers). I think invoke should look at the command name and have a blacklist of commands (or just start) whose arguments shouldn't be evaluated.

mdumitru avatar Jan 08 '19 12:01 mdumitru