Skip to content
Snippets Groups Projects
Commit 46c603ce authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix NULL pointer deref in random_menu()

When no files with extensions are found, though they matched the glob()
pattern, a NULL pointer deref would result (segfault).

This could happen if the only files matching the pattern had no extenions or
were directories (not files).

Fix for issue #779
parent e93b6dfa
No related branches found
No related tags found
1 merge request!455Update branch with changes from master
Pipeline #6576 passed
......@@ -373,9 +373,12 @@ bool sbbs_t::random_menu(const char *name, int mode, JSObject* obj)
globfree(&g);
strListDedupe(&names, /* case_sensitive: */true);
bool result = false;
size_t i = sbbs_random(strListCount(names));
if(menu_exists(names[i], NULL, path)) {
result = menu(names[i], mode, obj);
size_t count = strListCount(names);
if(count > 0) {
size_t i = sbbs_random(count);
if(menu_exists(names[i], NULL, path)) {
result = menu(names[i], mode, obj);
}
}
strListFree(&names);
return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment