Skip to content

reject trailing characters in SwitchNode numeric comparison#1178

Merged
facontidavide merged 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:switch-trailing-garbage-match
Jul 22, 2026
Merged

reject trailing characters in SwitchNode numeric comparison#1178
facontidavide merged 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:switch-trailing-garbage-match

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

SwitchNode picks a child by comparing its variable against each case_N with CheckStringEquality, which falls back from a string compare to an integer compare and then a real compare. The variable is a blackboard entry, so in practice it often carries a value that came from outside the tree. The integer and real fallbacks call std::from_chars (and std::stoi/std::stod on toolchains without the floating-point from_chars) but never check that the whole string was consumed, so 5abc, 42xxxx, and even 5 parse as their leading number and compare equal to case 5, 42, and 5. That routes a selector with trailing bytes to a case it does not actually equal, which is easy to slip past a check that only looked at the string form. I ran into it on a switch whose selector came from a message field. The fix requires full consumption (ptr == end, or pos == size on the stoi/stod path) at all four numeric parses; I also let the real comparison resolve scripting enums the way the integer one already does, so an enum name still matches the double a script stores for it. String equality and legitimate numeric matches like 5 versus 5.0 are unchanged.

@facontidavide
facontidavide merged commit a49a047 into BehaviorTree:master Jul 22, 2026
16 checks passed
@facontidavide

Copy link
Copy Markdown
Collaborator

thanks

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.

2 participants