Fixed a crash when using certain invalid color= values
The specific case that brought this to our attention was color=100. In case such values
are used, the color reverts back to the default color for that side, as before.
The new codepath (team::get_side_color_id_from_config) is essentially the same as the old
one but more robust (range checking, for example, the lack of which was causing the crash
before).
(cherry-picked from commit 4c937c10c7
)
This commit is contained in:
parent
ce9e0d2cac
commit
3b5a9d2994
2 changed files with 16 additions and 17 deletions
|
@ -151,6 +151,7 @@
|
|||
* Implemented a workaround for an unhandled std::bad_cast from string comparison
|
||||
functions that caused a crash-to-desktop when opening Preferences among others
|
||||
(issue #3050).
|
||||
* Fixed a crash when using certain invalid color= values.
|
||||
|
||||
## Version 1.13.12
|
||||
### Security fixes
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "map/map.hpp"
|
||||
#include "mt_rng.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "team.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -961,24 +962,21 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine, const
|
|||
team_ = team_name_index;
|
||||
}
|
||||
|
||||
if(!cfg["color"].empty()) {
|
||||
if(cfg["color"].to_int()) {
|
||||
color_ = cfg["color"].to_int() - 1;
|
||||
color_id_ = color_options_[color_];
|
||||
// Check the value of the config's color= key.
|
||||
const std::string given_color = team::get_side_color_id_from_config(cfg_);
|
||||
|
||||
if(!given_color.empty()) {
|
||||
// If it's valid, save the color...
|
||||
color_id_ = given_color;
|
||||
|
||||
// ... and find the appropriate index for it.
|
||||
const auto iter = std::find(color_options_.begin(), color_options_.end(), color_id_);
|
||||
|
||||
if(iter != color_options_.end()) {
|
||||
color_ = std::distance(color_options_.begin(), iter);
|
||||
} else {
|
||||
const std::string custom_color = cfg["color"].str();
|
||||
|
||||
const auto iter = std::find(color_options_.begin(), color_options_.end(), custom_color);
|
||||
|
||||
if(iter != color_options_.end()) {
|
||||
color_id_ = *iter;
|
||||
color_ = std::distance(color_options_.begin(), iter);
|
||||
} else {
|
||||
color_options_.push_back(custom_color);
|
||||
|
||||
color_id_ = custom_color;
|
||||
color_ = color_options_.size() - 1;
|
||||
}
|
||||
color_options_.push_back(color_id_);
|
||||
color_ = color_options_.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue