diff --git a/CHANGES b/CHANGES index 13128c9cec..5c2ef7415c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +7.1.0-dev.692 | 2024-12-06 10:22:07 +0100 + + * fix for ZAM "assert" statements potentially evaluating invalid expressions (Vern Paxson, Corelight) + 7.1.0-dev.689 | 2024-12-05 13:48:46 -0700 * init-bare: Deprecate tcp_reassembler_ports (Arne Welzel, Corelight) diff --git a/VERSION b/VERSION index 5702ab9253..a50ea1bcac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -7.1.0-dev.689 +7.1.0-dev.692 diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 75075dfa86..5877bc4f32 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -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) { diff --git a/testing/btest/Baseline.zam/language.assert-6/out b/testing/btest/Baseline.zam/language.assert-6/out index e400085e57..4bcf7b428e 100644 --- a/testing/btest/Baseline.zam/language.assert-6/out +++ b/testing/btest/Baseline.zam/language.assert-6/out @@ -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=]) fatal error: errors occurred while initializing diff --git a/testing/btest/Baseline.zam/language.assert-7/out b/testing/btest/Baseline.zam/language.assert-7/out index e400085e57..abbfbbf9f7 100644 --- a/testing/btest/Baseline.zam/language.assert-7/out +++ b/testing/btest/Baseline.zam/language.assert-7/out @@ -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