Rewrite conditional branch delay logic #8147
Open
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.
Problem
Delays are handled improperly by conditional sections. Specifically, the delay state is not reset properly before parsing branches. When a branch is parsed, it should use the delay state from BEFORE the start of the conditional change.
Solution
I have rewritten all of the delay logic in SecConditional. Now, before
loadCode
is called, the delay state is updated to use the delay state from right before the start of the conditional chain. Additionally, the logic for setting the delay state after the conditional chain has been reset. The "after" delay state is now tracked and set at each conditional (meaning it accounts for whether you stop at an "else" or an "else if").If the delay state was true before the conditional, it will continue to be true after. Otherwise, if all of the conditional branches are false, the delay state is false. If all are true, the delay state is true. If it is mixed, the delay state is unknown.
For testing purposes, I added a simple new condition,
CondHasDelayBefore
, for testing the delay state. Additionally, since the test script code is delayed, it is not possible to make assertions. To circumvent this, I added an "assert unsafe" option which disables this check. The code is not actually executed at runtime and therefore there will not be a delay (maybe something to fix actually with SecParse?). Recommendations for alternative approaches would be appreciated.Testing Completed
I have expanded
SecConditional.sk
with a new test case for delays. Additionally, I have added a regression test for explicitly tested the linked issue.Supporting Information
n/a
Completes: #8139
Related: none