diff --git a/CHANGES b/CHANGES index c13d44e162..3d8e5d4bc6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +4.2.0-dev.157 | 2021-09-08 12:04:45 -0700 + + * fix for looping over vectors with holes per https://github.com/zeek/zeek/issues/1763 (Vern Paxson, Corelight) + + * btest for https://github.com/zeek/zeek/issues/1763 (Vern Paxson, Corelight) + 4.2.0-dev.154 | 2021-09-08 12:03:51 -0700 * Fix mis-usage of string::append that leads to an overflow (Tim Wojtulewicz, Corelight) diff --git a/VERSION b/VERSION index f3480913be..6e49fb7671 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.0-dev.154 +4.2.0-dev.157 diff --git a/src/Stmt.cc b/src/Stmt.cc index a832aea2c4..a8618536eb 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1349,9 +1349,13 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) else if ( v->GetType()->Tag() == TYPE_VECTOR ) { VectorVal* vv = v->AsVectorVal(); + const auto& raw_vv = *vv->RawVec(); for ( auto i = 0u; i < vv->Size(); ++i ) { + if ( ! raw_vv[i] ) + continue; + // Set the loop variable to the current index, and make // another pass over the loop body. f->SetElement((*loop_vars)[0], val_mgr->Count(i)); diff --git a/testing/btest/Baseline/language.vector-hole-loop/out b/testing/btest/Baseline/language.vector-hole-loop/out new file mode 100644 index 0000000000..98cb76e32b --- /dev/null +++ b/testing/btest/Baseline/language.vector-hole-loop/out @@ -0,0 +1,8 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +[, foo, bar, , baz] +1 +2 +4 +foo +bar +baz diff --git a/testing/btest/language/vector-hole-loop.zeek b/testing/btest/language/vector-hole-loop.zeek new file mode 100644 index 0000000000..961ee3fbd6 --- /dev/null +++ b/testing/btest/language/vector-hole-loop.zeek @@ -0,0 +1,20 @@ +# @TEST-EXEC: zeek -b %INPUT >out +# @TEST-EXEC: btest-diff out + +event zeek_init() + { + local v: vector of string; + + v[1] = "foo"; + v[2] = "bar"; + v[4] = "baz"; + + print v; + + for ( idx in v ) + print idx; + + for ( idx in v ) + print v[idx]; + } +