Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix memory issues with Exhumed sound loading #642

Closed
wants to merge 2 commits into from

Conversation

Talon1024
Copy link
Contributor

Properly get the length of the sound file name to prevent a buffer overflow.
Also, use proper UTF-8 character for the degree symbol.

Properly get the length of the sound file name to prevent a buffer overflow.
Also, use proper UTF-8 character for the degree symbol.
@Talon1024 Talon1024 changed the title Attempt to fix Exhumed sound loading Attempt to fix memory issues with Exhumed sound loading Jan 29, 2022
@mjr4077au
Copy link
Member

Should we just use strlen unconditionally?

@coelckers
Copy link
Member

You cannot use strlen on a buffer that may not have a 0 terminator. If you are unlucky it'd crash with an access violation.
What's the problem this tries to fix anyway? It seems to work, after all.

@Talon1024
Copy link
Contributor Author

This is the issue I tried to fix:

=================================================================
==5164==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5606a00730e7 at pc 0x7efef0741480 bp 0x7ffe61fb2b80 sp 0x7ffe61fb2328
READ of size 8 at 0x5606a00730e7 thread T0
    #0 0x7efef074147f  (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x9b47f)
    #1 0x56069f7f2e30 in FString::StrCopy(char*, char const*, unsigned long) ../source/common/utility/zstring.cpp:1204
    #2 0x56069f7ec929 in FString::FString(char const*, unsigned long) ../source/common/utility/zstring.cpp:86
    #3 0x56069f32d18a in Exhumed::LoadSound(char const*) ../source/games/exhumed/src/sound.cpp:184
    #4 0x56069f32d6d2 in Exhumed::InitFX() ../source/games/exhumed/src/sound.cpp:225
    #5 0x56069f294bb4 in Exhumed::GameInterface::app_init() ../source/games/exhumed/src/exhumed.cpp:522
    #6 0x56069e89e537 in RunGame() ../source/core/gamecontrol.cpp:1069
    #7 0x56069e89a560 in GameMain() ../source/core/gamecontrol.cpp:574
    #8 0x56069e3bbf03 in main ../source/common/platform/posix/sdl/i_main.cpp:194
    #9 0x7efeefbc40b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #10 0x56069e3ad89d in _start (/home/kevinc/Games/code/Raze/build_asan/raze+0x82b89d)

0x5606a00730e7 is located 0 bytes to the right of global variable '*.LC971' defined in '../source/games/exhumed/all.cpp' (0x5606a00730e0) of size 7
  '*.LC971' is ascii string 'tele_1'
0x5606a00730e7 is located 57 bytes to the left of global variable '*.LC972' defined in '../source/games/exhumed/all.cpp' (0x5606a0073120) of size 9
  '*.LC972' is ascii string 'wasp_stg'
SUMMARY: AddressSanitizer: global-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x9b47f) 
Shadow bytes around the buggy address:
  0x0ac1540065c0: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 00 01 f9 f9
  0x0ac1540065d0: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0ac1540065e0: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 00 01 f9 f9
  0x0ac1540065f0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 01 f9 f9
  0x0ac154006600: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 00 01 f9 f9
=>0x0ac154006610: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9[07]f9 f9 f9
  0x0ac154006620: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x0ac154006630: f9 f9 f9 f9 06 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0ac154006640: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 07 f9 f9 f9
  0x0ac154006650: f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9 00 01 f9 f9
  0x0ac154006660: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==5164==ABORTING

A for loop has a maximum whereas strlen does not
@Gaerzi
Copy link
Contributor

Gaerzi commented Jan 29, 2022

How about namelen = strnlen(name, 8)? That should solve the issue of missing null terminators.

@coelckers
Copy link
Member

In that case this is the wrong place to do the fix. Just looking at the calling code gives me headaches. The term wrong doesn't even begin to describe the shit going on there.

@coelckers coelckers closed this Jan 29, 2022
@Talon1024 Talon1024 deleted the fix/ex_sound_loading branch January 29, 2022 11:13
@coelckers
Copy link
Member

Cam you please retry with the latest build? I changed the loading code so that it doesn't pass uninitialized data to other functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants