Bugfix/out of bounds in reduce expression sequence #386
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.
Bugfix
An issue is fixed which occurs while reducing sequences of expressions in beta nodes involving binary logical operators.
This fixes #381.
Description
The issue is caused by a missing update of
currentExpressioninreduceExpressionSequence()after indexi, which refers to the current expression, andcurrentExpressionbecame inconsistent:currentExpression(e1) represents a binary logical operator (OP_AND,OP_OR), it will incrementito the next expression (e2) and callreduceExpressionSequence()recursively.reduceExpression()and will incrementiagain to the next expression (e3). This invalidatescurrentExpressionwhich still refers to e2.OP_ENDis found.currentExpression, which still refers to e2 instead of e3. Then it incrementsito next expression (e4) and checks its operator to be different fromOP_END. It continues with e5, e6 and so on. In case e3 - which has never been checked - wasOP_END, the loop did not terminate. Incrementingifurther can lead to out-of-bounds access in arrayexprs->expressions[].Please note: The issue will also occur, if two subsequent expressions with binary logical operators exist (maybe from nesting?). This case is even worse, since recursive call of
reduceExpressionSequence()may incrementieven further (andiis a pointer in the argument of this function).Solution
After
iincrements,currentExpressionmust be updated consistently. In cases without binary logical operators, this is done right at the beginning of the loop. An additional update in the next statement after the increment would cause only additional runtime without benefit. Hence, the fix updatescurrentExpressiononly in the special case of the binary logical operators, just before it is accessed. This does not cost any additional runtime for all other cases.