Add some extra guards against null dereference and empty std::stack pops
Fixes segfault cases of #572
This commit is contained in:
22
ASTree.cpp
22
ASTree.cpp
@@ -1231,8 +1231,12 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
stack = stack_hist.top();
|
if (!stack_hist.empty()) {
|
||||||
stack_hist.pop();
|
stack = stack_hist.top();
|
||||||
|
stack_hist.pop();
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Warning: Stack history is empty, something wrong might have happened\n");
|
||||||
|
}
|
||||||
|
|
||||||
PycRef<ASTBlock> prev = curblock;
|
PycRef<ASTBlock> prev = curblock;
|
||||||
PycRef<ASTBlock> nil;
|
PycRef<ASTBlock> nil;
|
||||||
@@ -1389,10 +1393,10 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
|||||||
|
|
||||||
} while (prev != nil);
|
} while (prev != nil);
|
||||||
|
|
||||||
curblock = blocks.top();
|
if (!blocks.empty()) {
|
||||||
|
curblock = blocks.top();
|
||||||
if (curblock->blktype() == ASTBlock::BLK_EXCEPT) {
|
if (curblock->blktype() == ASTBlock::BLK_EXCEPT)
|
||||||
curblock->setEnd(pos+offs);
|
curblock->setEnd(pos+offs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1769,7 +1773,8 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
|||||||
else
|
else
|
||||||
curblock->append(new ASTPrint(stack.top(), stream));
|
curblock->append(new ASTPrint(stack.top(), stream));
|
||||||
stack.pop();
|
stack.pop();
|
||||||
stream->setProcessed();
|
if (stream)
|
||||||
|
stream->setProcessed();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Pyc::PRINT_NEWLINE:
|
case Pyc::PRINT_NEWLINE:
|
||||||
@@ -1797,7 +1802,8 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
|||||||
else
|
else
|
||||||
curblock->append(new ASTPrint(nullptr, stream));
|
curblock->append(new ASTPrint(nullptr, stream));
|
||||||
stack.pop();
|
stack.pop();
|
||||||
stream->setProcessed();
|
if (stream)
|
||||||
|
stream->setProcessed();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Pyc::RAISE_VARARGS_A:
|
case Pyc::RAISE_VARARGS_A:
|
||||||
|
Reference in New Issue
Block a user