radareorg / radare2

UNIX-like reverse engineering framework and command-line toolset
https://www.radare.org/
GNU Lesser General Public License v3.0
20.58k stars 3k forks source link

seg fault from r_getopt in r_main_radiff2() #16306

Closed aar0nge closed 4 years ago

aar0nge commented 4 years ago

Work environment

Questions Answers
OS/arch/bits (mandatory) Ubuntu x86 64
File format of the file you reverse (mandatory) ELF
Architecture/bits of the file (mandatory) x86/64
r2 -v full output, not truncated (mandatory) rradare2 4.3.1 23909 @ linux-x86-64 git.4.3.1-1-ge55661b commit: e55661bd4c229b9095982675709bdd52e1b4c068 build: 2020-03-22__22:18:20

Expected behavior

Handle input error

Actual behavior

seg fault

Steps to reproduce the behavior

$ r2 - [0x00000000]> radiff2 Usage: radiff2 [-abBcCdjrspOxuUvV] [-A[A]] [-g sym] [-m graph_mode][-t %] [file] [file] [0x00000000]> radiff2 Segmentation fault (core dumped)

Additional Logs, screenshots, source-code, configuration dump, ...

image

not sure about the root cause, seems like the situation here: http://www.cplusplus.com/forum/unices/104742/ about getopt's usage

suggestion fix:

add extern int optind; optind = 1; before the getopt while loop in radiff2.c: r_main_radiff2()

    evals = r_list_newf (NULL);
    extern int optind ;
    optind = 1;
    while ((o = r_getopt (argc, argv, "Aa:b:BCDe:npg:m:G:OijrhcdsS:uUvVxXt:zqZ")) != -1) {
radare commented 4 years ago

send a PR with the suggested fix please

On 25 Mar 2020, at 07:56, aar0nge notifications@github.com wrote:

Work environment

Questions Answers OS/arch/bits (mandatory) Ubuntu x86 64 File format of the file you reverse (mandatory) ELF Architecture/bits of the file (mandatory) x86/64 r2 -v full output, not truncated (mandatory) rradare2 4.3.1 23909 @ linux-x86-64 git.4.3.1-1-ge55661b commit: e55661b https://github.com/radareorg/radare2/commit/e55661bd4c229b9095982675709bdd52e1b4c068 build: 2020-03-22__22:18:20 Expected behavior

Handle input error

Actual behavior

seg fault

Steps to reproduce the behavior

$ r2 - [0x00000000]> radiff2 Usage: radiff2 [-abBcCdjrspOxuUvV] [-A[A]] [-g sym] [-m graph_mode][-t %] [file] [file] [0x00000000]> radiff2 Segmentation fault (core dumped)

Additional Logs, screenshots, source-code, configuration dump, ...

https://user-images.githubusercontent.com/20163299/77509693-299df400-6ea8-11ea-945c-b3bd8febfabd.png not sure about the root cause, seems like the situation here: http://www.cplusplus.com/forum/unices/104742/ http://www.cplusplus.com/forum/unices/104742/ about getopt's usage

suggestion fix:

add extern int optind; optind = 1; before the getopt while loop in radiff2.c: r_main_radiff2()

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/radareorg/radare2/issues/16306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG75FR2KVPRLDTQLWZRBBLRJGTKBANCNFSM4LTHI62A.

XVilka commented 4 years ago

Was fixed in https://github.com/radareorg/radare2/commit/5e4cdaaa0473ce1bcf152fe51531d3aa30754b9f