validate substituted node type in instantiateTreeNode - #1193
Open
aysha-afrah26 wants to merge 1 commit into
Open
validate substituted node type in instantiateTreeNode#1193aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Substitution rules replace a node by ID, but
instantiateTreeNodenever checks that the replacement has a compatible node type. The XML around the node was validated for its ORIGINAL type (mandatory ID, child count), so a compact leaf swapped for a structural node is mishandled at build time:The crash is
std::string(element->Attribute("ID"))at xml_parsing.cpp:1095. A compact<AlwaysSuccess/>carries no ID, soAttribute("ID")is null and the string constructor callsstrlen(nullptr). The same setup with"Inverter"leaves the decoratorchild_node_null and segfaults on the first tick instead. Both are reachable from an untrustedSubstitutionRulesJSON plus ordinary XML, before any node runs.The fix rejects a substitution whose resulting type differs from the original unless the replacement is a leaf (Action or Condition). That keeps the supported cases working, same-type swaps and the
SubTreetoTestNodemocking path from #934, and turns both crashes into a clearRuntimeError. Added a regression test that segfaults before the change and passes after.