From df6ec4f94c90c59a30f5a3e3106ab4a402189c9b Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 22 Jan 2019 10:30:34 +0100 Subject: [PATCH] Property alias loop protection Patch by Henning Stahlke --- simgear/props/props.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index 1c21ecee..8b599632 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -963,6 +963,11 @@ SGPropertyNode::alias (SGPropertyNode * target) { if (target && (_type != props::ALIAS) && (!_tied)) { + /* loop protection: check alias chain; must not contain self */ + for (auto p = target; p; p = ((p->_type == props::ALIAS) ? p->_value.alias : nullptr)) { + if (p == this) return false; + } + clearValue(); get(target); _value.alias = target; @@ -973,7 +978,7 @@ SGPropertyNode::alias (SGPropertyNode * target) if (!target) { SG_LOG(SG_GENERAL, SG_ALERT, - "Failed to create alias for " << getPath() << ". " + "Failed to set alias " << getPath() << ". " "The target property does not exist."); } else @@ -981,15 +986,15 @@ SGPropertyNode::alias (SGPropertyNode * target) { if (_value.alias == target) return true; // ok, identical alias requested - SG_LOG(SG_GENERAL, SG_ALERT, - "Failed to create alias at " << target->getPath() << ". " - "Source "<< getPath() << " is already aliasing another property."); + SG_LOG(SG_GENERAL, SG_ALERT, "alias(): "<< getPath() << + " is already pointing to " << _value.alias->getPath() << + " so it cannot alias '" << target->getPath() << ". Use unalias() first."); } else if (_tied) { - SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create alias at " << target->getPath() << ". " - "Source " << getPath() << " is a tied property."); + SG_LOG(SG_GENERAL, SG_ALERT, "alias(): " << getPath() << + " is a tied property. It cannot alias " << target->getPath() << "."); } return false;