mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/4323-traverse-all-stmt-nil-fix'
* origin/topic/awelzel/4323-traverse-all-stmt-nil-fix: Traverse: Do not short-circuit traverse_all() if stmts is nullptr
This commit is contained in:
commit
f0ccd5c7f8
3 changed files with 59 additions and 7 deletions
9
CHANGES
9
CHANGES
|
@ -1,3 +1,12 @@
|
|||
7.2.0-dev.473 | 2025-04-03 13:10:43 +0200
|
||||
|
||||
* GH-4323: Traverse: Do not short-circuit traverse_all() if stmts is nullptr (Arne Welzel, Corelight)
|
||||
|
||||
Since commit 0a813a53c7a5326d91fc5aa979429d04972d664b,
|
||||
zeek::detail::stmts is set to a nullptr when before it was usually
|
||||
an empty list of statements. This caused traverse_all() to be
|
||||
short-circuited unless global statements were available.
|
||||
|
||||
7.2.0-dev.471 | 2025-04-03 10:53:00 +0100
|
||||
|
||||
* Remove unnecessary check for bind library. (Johanna Amann, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
7.2.0-dev.471
|
||||
7.2.0-dev.473
|
||||
|
|
|
@ -2,27 +2,70 @@
|
|||
|
||||
#include "zeek/Traverse.h"
|
||||
|
||||
#include "zeek/Func.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/Stmt.h"
|
||||
#include "zeek/input.h"
|
||||
|
||||
#include "zeek/3rdparty/doctest.h"
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
TraversalCode traverse_all(TraversalCallback* cb) {
|
||||
if ( ! global_scope() )
|
||||
return TC_CONTINUE;
|
||||
|
||||
if ( ! stmts )
|
||||
// May be null when parsing fails.
|
||||
return TC_CONTINUE;
|
||||
|
||||
cb->current_scope = global_scope();
|
||||
|
||||
TraversalCode tc = global_scope()->Traverse(cb);
|
||||
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
tc = stmts->Traverse(cb);
|
||||
|
||||
if ( stmts )
|
||||
// May be null when parsing fails.
|
||||
tc = stmts->Traverse(cb);
|
||||
|
||||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
} // namespace zeek::detail
|
||||
|
||||
|
||||
TEST_SUITE_BEGIN("traverser");
|
||||
|
||||
namespace {
|
||||
// Helper classes for tests below.
|
||||
using namespace zeek::detail;
|
||||
|
||||
class SaveRestoreStmts {
|
||||
public:
|
||||
SaveRestoreStmts() : orig(zeek::detail::stmts) {}
|
||||
~SaveRestoreStmts() { zeek::detail::stmts = orig; }
|
||||
|
||||
Stmt* orig;
|
||||
};
|
||||
|
||||
class ZeekInitFinder : public TraversalCallback {
|
||||
public:
|
||||
TraversalCode PreFunction(const zeek::Func* f) override {
|
||||
if ( f->GetName() == "zeek_init" )
|
||||
zeek_init_found = true;
|
||||
|
||||
return TC_CONTINUE;
|
||||
}
|
||||
|
||||
bool zeek_init_found = false;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("traverse_all") {
|
||||
SUBCASE("ensure zeek_init() is found if stmts == nullptr") {
|
||||
SaveRestoreStmts save_restore_stmts;
|
||||
zeek::detail::stmts = nullptr; // force stmts to be a nullptr
|
||||
ZeekInitFinder cb;
|
||||
traverse_all(&cb);
|
||||
CHECK(cb.zeek_init_found);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue