Codechange: Make sort list function lists safer. (#12574)
GUIList has a pointer only to the start of each sort/filter func list, which has the potential for UB as it is unable to validate that the selected sort or filter type is in range. Use a std::span instead and check if the selected type is in range before using it.
This commit is contained in:
@@ -181,8 +181,8 @@ protected:
|
||||
static Listing last_sorting;
|
||||
|
||||
/* Constants for sorting servers */
|
||||
static GUIGameServerList::SortFunction * const sorter_funcs[];
|
||||
static GUIGameServerList::FilterFunction * const filter_funcs[];
|
||||
static const std::initializer_list<GUIGameServerList::SortFunction * const> sorter_funcs;
|
||||
static const std::initializer_list<GUIGameServerList::FilterFunction * const> filter_funcs;
|
||||
|
||||
NetworkGameList *server; ///< Selected server.
|
||||
NetworkGameList *last_joined; ///< The last joined server.
|
||||
@@ -459,8 +459,8 @@ public:
|
||||
this->server = this->last_joined;
|
||||
|
||||
this->servers.SetListing(this->last_sorting);
|
||||
this->servers.SetSortFuncs(this->sorter_funcs);
|
||||
this->servers.SetFilterFuncs(this->filter_funcs);
|
||||
this->servers.SetSortFuncs(NetworkGameWindow::sorter_funcs);
|
||||
this->servers.SetFilterFuncs(NetworkGameWindow::filter_funcs);
|
||||
this->servers.ForceRebuild();
|
||||
}
|
||||
|
||||
@@ -860,7 +860,7 @@ public:
|
||||
};
|
||||
|
||||
Listing NetworkGameWindow::last_sorting = {false, 5};
|
||||
GUIGameServerList::SortFunction * const NetworkGameWindow::sorter_funcs[] = {
|
||||
const std::initializer_list<GUIGameServerList::SortFunction * const> NetworkGameWindow::sorter_funcs = {
|
||||
&NGameNameSorter,
|
||||
&NGameClientSorter,
|
||||
&NGameMapSizeSorter,
|
||||
@@ -869,7 +869,7 @@ GUIGameServerList::SortFunction * const NetworkGameWindow::sorter_funcs[] = {
|
||||
&NGameAllowedSorter
|
||||
};
|
||||
|
||||
GUIGameServerList::FilterFunction * const NetworkGameWindow::filter_funcs[] = {
|
||||
const std::initializer_list<GUIGameServerList::FilterFunction * const> NetworkGameWindow::filter_funcs = {
|
||||
&NGameSearchFilter
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user