Crash:harden against malformed menu bar entries
If a menu-bar item is missing a <name>, we can end up building a string from nullptr, which is a SEGV. Reported as Sentry issue FLIGHTGEAR-1D Will back-port to LTS once verified.
This commit is contained in:
parent
830a890eff
commit
e26a2ecab0
1 changed files with 13 additions and 3 deletions
|
@ -20,14 +20,24 @@ FGMenuBar::~FGMenuBar ()
|
|||
std::string
|
||||
FGMenuBar::getLocalizedLabel(SGPropertyNode* node)
|
||||
{
|
||||
const char* name = node->getStringValue("name", 0);
|
||||
if (!node)
|
||||
return {};
|
||||
|
||||
std::string translated = globals->get_locale()->getLocalizedString(name, "menu");
|
||||
const char* name = node->getStringValue("name", 0);
|
||||
const auto translated = globals->get_locale()->getLocalizedString(name, "menu");
|
||||
if (!translated.empty())
|
||||
return translated;
|
||||
|
||||
// return default with fallback to name
|
||||
return node->getStringValue("label", name);
|
||||
const char* l = node->getStringValue("label", name);
|
||||
|
||||
// this can occur if the menu item is missing a <name>
|
||||
if (l == nullptr) {
|
||||
SG_LOG(SG_GUI, SG_ALERT, "FGMenuBar::getLocalizedLabel: No <name> defined for:" << node->getPath());
|
||||
return string{"<unnamed>"};
|
||||
}
|
||||
|
||||
return string{l};
|
||||
}
|
||||
|
||||
// end of menubar.cxx
|
||||
|
|
Loading…
Add table
Reference in a new issue