mickelson / attract

A graphical front-end for command line emulators that hides the underlying operating system and is intended to be controlled with a joystick or gamepad.
http://attractmode.org
GNU General Public License v3.0
393 stars 115 forks source link

Fix string out of bounds access issue #702

Closed davide125 closed 2 years ago

davide125 commented 2 years ago

last_char can become negative here, which can result in attempting to index the string at an invalid position, which leads to

/usr/include/c++/12/bits/basic_string.h:1201: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) const [with _CharT = unsigned int; _Traits = std::char_traits<unsigned int>; _Alloc = std::allocator<unsigned int>; const_reference = const unsigned int&; size_type = long unsigned int]: Assertion '__pos <= size()' failed.
Aborted (core dumped)