Skip to content

validate substituted node type in instantiateTreeNode - #1193

Open
aysha-afrah26 wants to merge 2 commits into
BehaviorTree:masterfrom
aysha-afrah26:substitution-node-type-check
Open

aysha-afrah26 wants to merge 2 commits 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.

@aysha-afrah26

Copy link
Copy Markdown
Contributor Author

Pushed a small follow-up: the new test was tripping MSVC C4834 (discarded nodiscard result), so it now uses the same (void) cast as the other factory tests.

The two red jobs on the first run were timing flakes in RepeatTestAsync.RepeatTestAsync and CoroTest.sequence_child. Neither goes through the factory, and both pass on the re-run. The windows Debug job has been sitting in the Build step for a while on this run (Release built the same sources fine), so that one looks like a runner stall and may need a re-run.

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