Skip to content

Commit e80a56d

Browse files
committed
Fixes issue 5532: null pointer dereference in EmitBooleanExpression
Github issue: #5532 Given a nested for loop that qualifies for loop inversion, the lack of a conditional in the outer loop causes a read access violation when the conditional’s ParseNode’s nop is read. The conditional is analyzed to perform a zero trip test which can skip the execution of the loop entirely. In the case where the outer loop lacks a conditional, the zero trip test will not pass. Therefore when the outer loop lacks a conditional skipping the inclusion of a zero trip test is valid and avoids the read access violation.
1 parent 3dae2d3 commit e80a56d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9259,12 +9259,16 @@ void ByteCodeGenerator::EmitInvertedLoop(ParseNodeLoop* outerLoop, ParseNodeFor*
92599259
this->m_writer.Br(afterInvertedLoop);
92609260
this->m_writer.MarkLabel(invertedLoopLabel);
92619261

9262-
// Emit a zero trip test for the original outer-loop
9263-
Js::ByteCodeLabel zeroTrip = this->m_writer.DefineLabel();
9264-
ParseNode* testNode = this->GetParser()->CopyPnode(outerLoop->AsParseNodeFor()->pnodeCond);
9265-
EmitBooleanExpression(testNode, zeroTrip, afterInvertedLoop, this, funcInfo, true, false);
9266-
this->m_writer.MarkLabel(zeroTrip);
9267-
funcInfo->ReleaseLoc(testNode);
9262+
// Emit a zero trip test for the original outer-loop if the outer-loop
9263+
// has a condition
9264+
if (outerLoop->AsParseNodeFor()->pnodeCond)
9265+
{
9266+
Js::ByteCodeLabel zeroTrip = this->m_writer.DefineLabel();
9267+
ParseNode* testNode = this->GetParser()->CopyPnode(outerLoop->AsParseNodeFor()->pnodeCond);
9268+
EmitBooleanExpression(testNode, zeroTrip, afterInvertedLoop, this, funcInfo, true, false);
9269+
this->m_writer.MarkLabel(zeroTrip);
9270+
funcInfo->ReleaseLoc(testNode);
9271+
}
92689272

92699273
// emit inverted
92709274
Emit(invertedLoop->pnodeInit, this, funcInfo, false);

0 commit comments

Comments
 (0)