fix for ZAM "assert" statements potentially evaluating invalid expressions

This commit is contained in:
Vern Paxson 2024-12-05 14:29:06 -08:00
parent 682789a8e9
commit e6e31bc25a
3 changed files with 10 additions and 3 deletions

View file

@ -1062,6 +1062,9 @@ const ZAMStmt ZAMCompiler::CompileAssert(const AssertStmt* as) {
(void)AddInst(ZInstI(OP_SHOULD_REPORT_ASSERT_VV, decision_slot, cond_slot));
auto cond_stmt = AddInst(ZInstI(OP_IF_Vb, decision_slot, 0));
AddCFT(insts1.back(), CFT_IF);
ZInstI z;
// We don't have a convenient way of directly introducing a std::string
@ -1085,7 +1088,11 @@ const ZAMStmt ZAMCompiler::CompileAssert(const AssertStmt* as) {
else
z = ZInstI(OP_REPORT_ASSERT_VVC, decision_slot, cond_slot, cond_desc_e.get());
return AddInst(z);
auto end_inst = AddInst(z);
AddCFT(insts1.back(), CFT_BLOCK_END);
SetV(cond_stmt, GoToTargetBeyond(end_inst), 2);
return end_inst;
}
const ZAMStmt ZAMCompiler::InitRecord(IDPtr id, RecordType* rt) {

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
runtime error in <...>/assert.zeek, line 9: field value missing: $b
error in <...>/assert.zeek, line 10: assertion failure: r?$b (r$b is not set in [a=1234, b=<uninitialized>])
fatal error: errors occurred while initializing

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
runtime error in <...>/assert.zeek, line 9: field value missing: $b
runtime error in <...>/assert.zeek, line 12: field value missing: $b
fatal error: errors occurred while initializing