RetroArch crashes with invalid arguments.

Created on 13 Jan 2019  路  8Comments  路  Source: libretro/RetroArch

Description

RetroArch will crash when ran with invalid arguments that do not that with a dash (-).

Expected behavior

RetroArch should fail safely.

Actual behavior

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5e22445 in __strrchr_sse2 () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff5e22445 in __strrchr_sse2 () from /lib64/libc.so.6
#1  0x0000000000443930 in find_last_slash (str=0x0)
    at libretro-common/file/file_path.c:532
#2  0x0000000000443e5d in path_basename (path=0x0)
    at libretro-common/file/file_path.c:803
#3  0x0000000000443a1a in fill_pathname_dir (
    in_dir=0xa52460 <g_extern> "/media/data/home/games/roms/.saves/retroarch/",
    in_basename=0x0, replace=0x7447fc ".srm", size=8192)
    at libretro-common/file/file_path.c:593
#4  0x00000000004196c8 in path_set_redirect () at paths.c:174
#5  0x000000000041a28c in path_set_names (path=0x7fffffffe540 "foo")
    at paths.c:573
#6  0x000000000041a2ed in path_set (type=RARCH_PATH_NAMES,
    path=0x7fffffffe540 "foo") at paths.c:588
#7  0x0000000000414854 in retroarch_parse_input_and_config (argc=2,
    argv=0x7fffffffe208) at retroarch.c:1171
#8  0x0000000000414c74 in retroarch_main_init (argc=2, argv=0x7fffffffe208)
    at retroarch.c:1342
#9  0x000000000042ec20 in content_load (info=0x7fffffffe0d0)
    at tasks/task_content.c:282
#10 0x000000000042fe81 in task_load_content (content_info=0x7fffffffe0d0,
    content_ctx=0x7fffffffdfe0, launched_from_menu=true, launched_from_cli=true,
    error_string=0x7fffffffdfd8) at tasks/task_content.c:884
#11 0x00000000004312e4 in task_load_content_callback (
    content_info=0x7fffffffe0d0, loading_from_menu=true, loading_from_cli=true)
    at tasks/task_content.c:1560
#12 0x00000000004314dd in task_push_load_content_from_cli (core_path=0x0,
    fullpath=0x0, content_info=0x7fffffffe0d0, type=CORE_TYPE_PLAIN, cb=0x0,
    user_data=0x0) at tasks/task_content.c:1641
#13 0x0000000000411341 in rarch_main (argc=2, argv=0x7fffffffe208, data=0x0)
    at frontend/frontend.c:138
#14 0x00000000004113c4 in main (argc=2, argv=0x7fffffffe208)
    at frontend/frontend.c:182

Full GDB log - https://pastebin.com/LEH4TUXn

AddressSanitizer:DEADLYSIGNAL
=================================================================
==12235==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fa31d4d1736 bp 0x7ffff24003f0 sp 0x7ffff23ffb78 T0)
==12235==The signal is caused by a READ memory access.
==12235==Hint: address points to the zero page.
    #0 0x7fa31d4d1735 in __GI___strlen_sse2 (/lib64/libc.so.6+0xb1735)
    #1 0x7fa31f78d563  (/usr/lib64/libasan.so.5+0x9d563)
    #2 0x47cb8f in find_last_slash libretro-common/file/file_path.c:532
    #3 0x47d50e in path_basename libretro-common/file/file_path.c:803
    #4 0x47cd9e in fill_pathname_dir libretro-common/file/file_path.c:593
    #5 0x42847f in path_set_redirect /home/orbea/gittings/forks/RetroArch/paths.c:174
    #6 0x4296d6 in path_set_names /home/orbea/gittings/forks/RetroArch/paths.c:573
    #7 0x429737 in path_set /home/orbea/gittings/forks/RetroArch/paths.c:588
    #8 0x41f421 in retroarch_parse_input_and_config /home/orbea/gittings/forks/RetroArch/retroarch.c:1171
    #9 0x41fa9e in retroarch_main_init /home/orbea/gittings/forks/RetroArch/retroarch.c:1342
    #10 0x447c13 in content_load tasks/task_content.c:282
    #11 0x44ab8f in task_load_content tasks/task_content.c:884
    #12 0x44ee8e in task_load_content_callback tasks/task_content.c:1560
    #13 0x44f297 in task_push_load_content_from_cli tasks/task_content.c:1641
    #14 0x4191df in rarch_main frontend/frontend.c:138
    #15 0x4193a3 in main frontend/frontend.c:182
    #16 0x7fa31d442c66 in __libc_start_main (/lib64/libc.so.6+0x22c66)
    #17 0x40e9c9 in _start (/media/gittings/forks/RetroArch/retroarch+0x40e9c9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libc.so.6+0xb1735) in __GI___strlen_sse2
==12235==ABORTING

Steps to reproduce the bug

  1. ./retroarch foo
  2. Crash

Bisect Results

b33d29aecfb671ed3701b7025440a362da657e8d is the first bad commit
commit b33d29aecfb671ed3701b7025440a362da657e8d
Author: Gregor Richards <[email protected]>
Date:   Fri Mar 9 17:23:34 2018 -0500

    Make command-line overrides (somewhat) clearer

    This commit:

    (1) Changes the order of command-line loading so that config loading
    happens before command line overrides. This way, config loading does not
    itself have to be concerned with being pre-overridden.

    (2) Adds overrides to the data structures that configuration saving uses
    to save configuration blocks of the same type, so that they can easily
    be added in the future.

b33d29aecfb671ed3701b7025440a362da657e8d

Version/Commit

You can find this information under Information/System Information

Environment information

  • OS: Slackware64-current
  • Compiler: gcc-8.2.0
bisected major commandline

Most helpful comment

Should be fixed in af73798

All 8 comments

@GregorR Mind looking at this?

I'll take a look tomorrow.

Would it benefit to use something other than straight up getopt? A command-line argument library wrapper like parg could help...

FWIW, here's the output I get when I run retroarch foo...

./retroarch foo
[INFO] [recording] twitch streaming key empty
[INFO] RetroArch 1.7.5 (Git cb596aec3a)
[INFO] === Build =======================================
Capabilities: MMX MMXEXT SSE1 SSE2 SSE3 SSSE3 SSE4 SSE4.2 AVX AES 
Built: Jan 13 2019
[INFO] Version: 1.7.5
[INFO] Git: cb596aec3a
[INFO] =================================================
[ERROR] RetroArch is built for dynamic libretro cores, but libretro_path is not set. Cannot continue.
[ERROR] Fatal error received in: "init_libretro_sym()"

Here is my verbose log.

$ retroarch --verbose foo
[INFO] RetroArch 1.7.5 (Git 1b22acd)
Segmentation fault

This doesn't happen with a default config, after comparing my existing config with a default one I found this setting is the difference.

--- retroarch.cfg.default   2019-01-12 22:48:12.487030731 -0800
+++ retroarch.cfg   2019-01-12 22:48:01.374914414 -0800
@@ -2832,7 +2832,7 @@
 run_ahead_frames = "1"
 run_ahead_hide_warnings = "false"
 run_ahead_secondary_instance = "false"
-savefile_directory = "default"
+savefile_directory = "/tmp"
 savefiles_in_content_dir = "false"
 savestate_auto_index = "false"
 savestate_auto_load = "false"

It doesn't seem to matter what directory its set to, only that its set.

Also this one.

--- retroarch.cfg.default   2019-01-12 23:05:18.189740427 -0800
+++ retroarch.cfg   2019-01-12 23:05:11.088666672 -0800
@@ -2837,7 +2837,7 @@
 savestate_auto_index = "false"
 savestate_auto_load = "false"
 savestate_auto_save = "false"
-savestate_directory = "default"
+savestate_directory = "/tmp"
 savestate_thumbnail_enable = "false"
 savestates_in_content_dir = "false"
 screenshot_directory = "~/.config/retroarch/screenshots"

Should be fixed in af73798

Yes, I can confirm that its at least fixed with my config, thanks for the fix!

$ retroarch --verbose foo
[INFO] RetroArch 1.7.5 (Git af73798)
[INFO] Redirecting save file to "/media/data/home/games/roms/.saves/retroarch/.srm".
[INFO] Redirecting savestate to "/media/data/home/games/roms/.saves/retroarch/.sstates/.state".
[INFO] === Build =======================================
Capabilities: MMX MMXEXT SSE1 SSE2 SSE3 SSSE3 SSE4 SSE4.2 AVX AES 
Built: Jan 13 2019
[INFO] Version: 1.7.5
[INFO] Git: af73798
[INFO] =================================================
[ERROR] RetroArch is built for dynamic libretro cores, but libretro_path is not set. Cannot continue.
[ERROR] Fatal error received in: "init_libretro_sym()"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

charlydelta picture charlydelta  路  3Comments

Chocobubba picture Chocobubba  路  3Comments

RobLoach picture RobLoach  路  3Comments

orbea picture orbea  路  3Comments

ghost picture ghost  路  3Comments