Skip to content

validate substituted node type in instantiateTreeNode - #1193

Open
aysha-afrah26 wants to merge 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:substitution-node-type-check
Open

validate substituted node type in instantiateTreeNode#1193
aysha-afrah26 wants to merge 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:substitution-node-type-check

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

Substitution rules replace a node by ID, but instantiateTreeNode never 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:

<AlwaysSuccess name="action_A"/>  +  addSubstitutionRule("action_A", "SubTree")
=> Segmentation fault (exit 139)

The crash is std::string(element->Attribute("ID")) at xml_parsing.cpp:1095. A compact <AlwaysSuccess/> carries no ID, so Attribute("ID") is null and the string constructor calls strlen(nullptr). The same setup with "Inverter" leaves the decorator child_node_ null and segfaults on the first tick instead. Both are reachable from an untrusted SubstitutionRules JSON 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 SubTree to TestNode mocking path from #934, and turns both crashes into a clear RuntimeError. Added a regression test that segfaults before the change and passes after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant