Fix possible invalid memory access in the MP sides config code (bug #21449)

(thunderstruck, you may want to review this.)

It appears that using a a function or method that returns a temporary as
the second argument of BOOST_FOREACH does something unexpected:

  BOOST_FOREACH(const config* faction, engine_->flg().choosable_factions()) {
      ...
  }

mp::flg_manager()::choosable_factions() returns a new object by value
rather than reference. Somehow this may result in invalid memory
accesses with some Boost and gcc versions (e.g. gcc 4.6.3 and Boost
1.46.1 from the bug report crashes, gcc 4.8.2 and Boost 1.54.0 here does
not), apparently.

I don't know the code well enough to determine whether
choosable_factions() returning an object by const value rather than
const reference is a typing mistake, so for now create a temporary const
reference before the BOOST_FOREACH loop.
This commit is contained in:
Ignacio R. Morelle 2014-01-06 23:25:48 -03:00
parent 715618b385
commit 3bf175313b
3 changed files with 10 additions and 1 deletions

View file

@ -7,6 +7,8 @@ Version 1.11.8+dev:
* Miscellaneous and bug fixes:
* Added -Wno-documentation-deprecated-sync to the CMake pedantic flags.
* Fixed several Doxygen issues found by Clang 3.4.
* Fixed possible invalid memory access issue in the MP sides configuration
code causing crashes for some users (bug #21449).
Version 1.11.8:
* Add-ons client:

View file

@ -10,6 +10,10 @@ Version 1.11.8+dev:
* Fixed subtle magenta TC for the Giant Mudcrawler sprites not being
enabled in-game.
* Miscellaneous and bug fixes:
* Fixed possible invalid memory access issue in the MP sides configuration
code causing crashes for some users (bug #21449).
Version 1.11.8:
* Add-ons client:

View file

@ -290,7 +290,10 @@ void connect::side::add_widgets_to_scrollpane(gui::scrollpane& pane, int pos)
void connect::side::update_faction_combo()
{
std::vector<std::string> factions;
BOOST_FOREACH(const config* faction, engine_->flg().choosable_factions()) {
const std::vector<const config*>& choosable =
engine_->flg().choosable_factions();
BOOST_FOREACH(const config* faction, choosable) {
const std::string& name = (*faction)["name"];
const std::string& icon = (*faction)["image"];
if (!icon.empty()) {