[xoreos-git] [xoreos/xoreos] ab0587: AURORA: Fix potential segfault when loading 2DA/GD...

Sven Hesse noreply at github.com
Tue Aug 25 02:59:30 CEST 2020


  Branch: refs/heads/master
  Home:   https://github.com/xoreos/xoreos
  Commit: ab0587d685217a06ad57f53eed0a947f405a189b
      https://github.com/xoreos/xoreos/commit/ab0587d685217a06ad57f53eed0a947f405a189b
  Author: Sven Hesse <drmccoy at drmccoy.de>
  Date:   2020-08-25 (Tue, 25 Aug 2020)

  Changed paths:
    M src/aurora/2dareg.cpp

  Log Message:
  -----------
  AURORA: Fix potential segfault when loading 2DA/GDA into the registry

The order of evaluation in an assignment is unspecified, at least
before C++17.

So in our cases here, when loading the 2DA/GDA throws, the
std::map::operator[] might have been called already, allocating a
space in the map with a default std::unique_ptr<TwoDAFile> containing
a nullptr. Subsequent calls will return this nullptr, promptly
dereference it... which then blow up in our faces.

Since we're still C++14, this is still unspecified behaviour for us,
so entirely legal for an implementation to do. As does, apparently,
the arm64 gcc on Travis CI. Good to know.

Adding a temporary std::unique_ptr that is moved out of into the map
fixes this issue.





More information about the xoreos-git mailing list