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

Prevent crash from -1 array idx when searching zones #75739

Conversation

inogenous
Copy link
Contributor

Summary

Bugfixes "Prevent crash from -1 array idx when searching zones"

Purpose of change

Prevents a crash when searching for zones to add, but the search yields no results. Fixes #75738 .

Describe the solution

Previous crash being fixed:

Thread 1 "cataclysm-tiles" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44

(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x00007ffff787840f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  0x00007ffff78294f2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff78124ed in __GI_abort () at ./stdlib/abort.c:79
#4  0x00007ffff7ad501e in std::__glibcxx_assert_fail(char const*, int, char const*, char const*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x0000555555de2639 in std::vector<uilist_entry, std::allocator<uilist_entry> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14/bits/stl_vector.h:1130
#6  std::vector<uilist_entry, std::allocator<uilist_entry> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14/bits/stl_vector.h:1128
#7  0x000055555699deac in uilist_impl::draw_controls (this=0x555599a181d0) at src/ui.cpp:138
#8  0x0000555555b7c312 in cataimgui::window::draw (this=0x555599a181d0) at src/cata_imgui.cpp:631
#9  cataimgui::window::draw (this=0x555599a181d0) at src/cata_imgui.cpp:600
#10 0x00005555569a2b1c in ui_adaptor::redraw_invalidated () at src/ui_manager.cpp:440
#11 0x00005555569a2bd9 in ui_adaptor::redraw () at src/ui_manager.cpp:345
#12 0x00005555569a2c00 in ui_manager::redraw () at src/ui_manager.cpp:508
#13 0x000055555699bfa4 in uilist::inputfilter (this=this@entry=0x7fffffffb9c8) at src/ui.cpp:531
#14 0x000055555699ead4 in uilist::query (this=this@entry=0x7fffffffb9c8, loop=loop@entry=true, timeout=timeout@entry=-1, allow_unfiltered_hotkeys=allow_unfiltered_hotkeys@entry=false) at src/ui.cpp:865
#15 0x0000555555c610d4 in zone_manager::query_type (this=this@entry=0x555557274060 <zone_manager::get_manager()::manager>, personal=personal@entry=false) at src/clzones.cpp:621
#16 0x0000555555ef3894 in game::zones_manager (this=this@entry=0x555558291db0) at src/game.cpp:6944
#17 0x0000555555f5d279 in game::do_regular_action (this=this@entry=0x555558291db0, act=@0x7fffffffcfec: ACTION_ZONES, player_character=..., mouse_target=std::optional [no contained value]) at src/handle_action.cpp:2438
#18 0x0000555555f60769 in game::handle_action (this=0x555558291db0) at src/handle_action.cpp:3172
#19 0x0000555555dcf14d in do_turn () at src/do_turn.cpp:579
#20 0x00005555557a1217 in main (argc=<optimized out>, argv=<optimized out>) at src/main.cpp:873

gdb shows that parent.selected was negative:

(gdb) frame 7
138                                           parent.entries[parent.selected].desc.c_str()
(gdb) print parent.selected
$1 = -1
(gdb) print parent.entries.size()
$2 = 63

Describe alternatives you've considered

  • Could also check for whether selected < entries.size(), but other code handling the entries does not seem to do that anyway.

Testing

Additional context

@github-actions github-actions bot added Info / User Interface Game - player communication, menus, etc. [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions labels Aug 16, 2024
Prevents the crash listed below that previously happened when searching
for zones to add, but the search yielded no results:

```
Thread 1 "cataclysm-tiles" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44

(gdb) bt
 #0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
 CleverRaven#1  0x00007ffff787840f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
 CleverRaven#2  0x00007ffff78294f2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
 CleverRaven#3  0x00007ffff78124ed in __GI_abort () at ./stdlib/abort.c:79
 CleverRaven#4  0x00007ffff7ad501e in std::__glibcxx_assert_fail(char const*, int, char const*, char const*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
 CleverRaven#5  0x0000555555de2639 in std::vector<uilist_entry, std::allocator<uilist_entry> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14/bits/stl_vector.h:1130
 CleverRaven#6  std::vector<uilist_entry, std::allocator<uilist_entry> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/14/bits/stl_vector.h:1128
 CleverRaven#7  0x000055555699deac in uilist_impl::draw_controls (this=0x555599a181d0) at src/ui.cpp:138
 CleverRaven#8  0x0000555555b7c312 in cataimgui::window::draw (this=0x555599a181d0) at src/cata_imgui.cpp:631
 CleverRaven#9  cataimgui::window::draw (this=0x555599a181d0) at src/cata_imgui.cpp:600
 CleverRaven#10 0x00005555569a2b1c in ui_adaptor::redraw_invalidated () at src/ui_manager.cpp:440
 CleverRaven#11 0x00005555569a2bd9 in ui_adaptor::redraw () at src/ui_manager.cpp:345
 CleverRaven#12 0x00005555569a2c00 in ui_manager::redraw () at src/ui_manager.cpp:508
 CleverRaven#13 0x000055555699bfa4 in uilist::inputfilter (this=this@entry=0x7fffffffb9c8) at src/ui.cpp:531
 CleverRaven#14 0x000055555699ead4 in uilist::query (this=this@entry=0x7fffffffb9c8, loop=loop@entry=true, timeout=timeout@entry=-1, allow_unfiltered_hotkeys=allow_unfiltered_hotkeys@entry=false) at src/ui.cpp:865
 CleverRaven#15 0x0000555555c610d4 in zone_manager::query_type (this=this@entry=0x555557274060 <zone_manager::get_manager()::manager>, personal=personal@entry=false) at src/clzones.cpp:621
 CleverRaven#16 0x0000555555ef3894 in game::zones_manager (this=this@entry=0x555558291db0) at src/game.cpp:6944
 CleverRaven#17 0x0000555555f5d279 in game::do_regular_action (this=this@entry=0x555558291db0, act=@0x7fffffffcfec: ACTION_ZONES, player_character=..., mouse_target=std::optional [no contained value]) at src/handle_action.cpp:2438
 CleverRaven#18 0x0000555555f60769 in game::handle_action (this=0x555558291db0) at src/handle_action.cpp:3172
 CleverRaven#19 0x0000555555dcf14d in do_turn () at src/do_turn.cpp:579
 CleverRaven#20 0x00005555557a1217 in main (argc=<optimized out>, argv=<optimized out>) at src/main.cpp:873
```

gdb shows that `parent.selected` was negative:
```
(gdb) frame 7
138                                           parent.entries[parent.selected].desc.c_str()
(gdb) print parent.selected
$1 = -1
(gdb) print parent.entries.size()
$2 = 63
```
@inogenous inogenous force-pushed the crash-negative-array-idx-searching-zones branch from 3141135 to e3b30b6 Compare August 16, 2024 11:05
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Aug 16, 2024
@Maleclypse Maleclypse merged commit 74006ee into CleverRaven:master Aug 18, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Searching for the Zone type crashes the game
2 participants