Clang format again but now with v13.0.1

This commit is contained in:
Tomer Lev 2022-11-02 10:13:58 +02:00
parent a105ea9d80
commit 73e749a162
12 changed files with 215 additions and 209 deletions

View file

@ -296,8 +296,8 @@ TEST_CASE("dns_mapping init addr")
TEST_CASE("dns_mapping save reload") TEST_CASE("dns_mapping save reload")
{ {
// TODO: this test uses fmemopen and mkdtemp, both of which aren't available on // TODO: this test uses fmemopen and mkdtemp, both of which aren't available on
// Windows. We'll have to figure out another way to do this test there. // Windows. We'll have to figure out another way to do this test there.
#ifndef _MSC_VER #ifndef _MSC_VER
IPAddr addr("1.2.3.4"); IPAddr addr("1.2.3.4");
in4_addr in4; in4_addr in4;

View file

@ -1613,7 +1613,7 @@ void TestDNS_Mgr::Process()
TEST_CASE("dns_mgr priming" * doctest::skip(true)) TEST_CASE("dns_mgr priming" * doctest::skip(true))
{ {
// TODO: This test uses mkdtemp, which isn't available on Windows. // TODO: This test uses mkdtemp, which isn't available on Windows.
#ifndef _MSC_VER #ifndef _MSC_VER
char prefix[] = "/tmp/zeek-unit-test-XXXXXX"; char prefix[] = "/tmp/zeek-unit-test-XXXXXX";
auto tmpdir = mkdtemp(prefix); auto tmpdir = mkdtemp(prefix);

View file

@ -32,7 +32,9 @@ namespace zeek::detail
Flare::Flare() Flare::Flare()
#ifndef _MSC_VER #ifndef _MSC_VER
: pipe(FD_CLOEXEC, FD_CLOEXEC, O_NONBLOCK, O_NONBLOCK){} : pipe(FD_CLOEXEC, FD_CLOEXEC, O_NONBLOCK, O_NONBLOCK)
{
}
#else #else
{ {
WSADATA wsaData; WSADATA wsaData;
@ -62,7 +64,7 @@ Flare::Flare()
} }
#endif #endif
[[noreturn]] static void bad_pipe_op(const char* which, bool signal_safe) [[noreturn]] static void bad_pipe_op(const char* which, bool signal_safe)
{ {
if ( signal_safe ) if ( signal_safe )
abort(); abort();

View file

@ -372,7 +372,7 @@ protected:
void Set(double d); void Set(double d);
void Set(const void* p); void Set(const void* p);
union { union {
bool b; bool b;
int i; int i;
zeek_int_t bi; zeek_int_t bi;

View file

@ -546,7 +546,7 @@ void IPv6_Hdr_Chain::Init(const struct ip6_hdr* ip6, int total_len, bool set_nex
total_len -= cur_len; total_len -= cur_len;
} while ( current_type != IPPROTO_FRAGMENT && current_type != IPPROTO_ESP && } while ( current_type != IPPROTO_FRAGMENT && current_type != IPPROTO_ESP &&
current_type != IPPROTO_MOBILITY && isIPv6ExtHeader(next_type) ); current_type != IPPROTO_MOBILITY && isIPv6ExtHeader(next_type) );
} }
bool IPv6_Hdr_Chain::IsFragment() const bool IPv6_Hdr_Chain::IsFragment() const

View file

@ -4,8 +4,11 @@
#include "zeek/zeek-config.h" #include "zeek/zeek-config.h"
// clang-format off
// Include order is required here for a working build on Windows.
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
// clang-format on
#include <cstring> #include <cstring>
#include "zeek/util.h" #include "zeek/util.h"

View file

@ -111,7 +111,7 @@ static std::string prefix_basename_with(const std::string& path, const std::stri
TEST_CASE("writers.ascii prefix_basename_with") TEST_CASE("writers.ascii prefix_basename_with")
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
// TODO: adapt this test to Windows paths // TODO: adapt this test to Windows paths
#else #else
CHECK(prefix_basename_with("a/conn.log", ".shadow.") == "a/.shadow.conn.log"); CHECK(prefix_basename_with("a/conn.log", ".shadow.") == "a/.shadow.conn.log");
CHECK(prefix_basename_with("/a/conn.log", ".shadow.") == "/a/.shadow.conn.log"); CHECK(prefix_basename_with("/a/conn.log", ".shadow.") == "/a/.shadow.conn.log");

View file

@ -63,7 +63,7 @@ string SQLite::GetTableType(int arg_type, int arg_subtype)
case TYPE_INT: case TYPE_INT:
case TYPE_COUNT: case TYPE_COUNT:
case TYPE_PORT: // note that we do not save the protocol at the moment. Just like in the case TYPE_PORT: // note that we do not save the protocol at the moment. Just like in the
// case of the ascii-writer // case of the ascii-writer
type = "integer"; type = "integer";
break; break;

View file

@ -64,7 +64,7 @@ struct ip6_ext
struct ip6_hdr struct ip6_hdr
{ {
union { union {
struct ip6_hdrctl struct ip6_hdrctl
{ {
uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC, 20 bits uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC, 20 bits
@ -335,7 +335,7 @@ inline float htonf(float f)
inline uint64_t ntohll(uint64_t i) inline uint64_t ntohll(uint64_t i)
{ {
u_char c; u_char c;
union { union {
uint64_t i; uint64_t i;
u_char c[8]; u_char c[8];
} x; } x;

View file

@ -661,7 +661,7 @@ public:
private: private:
Type type; Type type;
union { union {
bool bool_; bool bool_;
double double_; double double_;
const Event* event; const Event* event;

View file

@ -631,7 +631,7 @@ string flatten_script_name(const string& name, const string& prefix)
TEST_CASE("util normalize_path") TEST_CASE("util normalize_path")
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
// TODO: adapt these tests to Windows // TODO: adapt these tests to Windows
#else #else
CHECK(normalize_path("/1/2/3") == "/1/2/3"); CHECK(normalize_path("/1/2/3") == "/1/2/3");
CHECK(normalize_path("/1/./2/3") == "/1/2/3"); CHECK(normalize_path("/1/./2/3") == "/1/2/3");
@ -2737,7 +2737,7 @@ string json_escape_utf8(const char* val, size_t val_size, bool escape_printable_
TEST_CASE("util filesystem") TEST_CASE("util filesystem")
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
// TODO: adapt these tests to Windows paths // TODO: adapt these tests to Windows paths
#else #else
zeek::filesystem::path path1("/a/b"); zeek::filesystem::path path1("/a/b");
CHECK(path1.is_absolute()); CHECK(path1.is_absolute());

View file

@ -887,228 +887,229 @@ SetupResult setup(int argc, char** argv, Options* zopts)
#ifdef USE_PERFTOOLS_DEBUG #ifdef USE_PERFTOOLS_DEBUG
} }
#endif #endif
set_signal_mask(false); set_signal_mask(false);
if ( reporter->Errors() > 0 ) if ( reporter->Errors() > 0 )
{
early_shutdown();
exit(1);
}
reporter->InitOptions();
KeyedHash::InitOptions();
zeekygen_mgr->GenerateDocs();
if ( options.pcap_filter )
{
const auto& id = global_scope()->Find("cmd_line_bpf_filter");
if ( ! id )
reporter->InternalError("global cmd_line_bpf_filter not defined");
id->SetVal(make_intrusive<StringVal>(*options.pcap_filter));
}
std::vector<SignatureFile> all_signature_files;
// Append signature files given on the command line
for ( const auto& sf : options.signature_files )
all_signature_files.emplace_back(sf);
// Append signature files defined in "signature_files" script option
for ( auto&& sf : get_script_signature_files() )
all_signature_files.emplace_back(std::move(sf));
// Append signature files defined in @load-sigs
for ( const auto& sf : zeek::detail::sig_files )
all_signature_files.emplace_back(sf);
if ( ! all_signature_files.empty() )
{
rule_matcher = new RuleMatcher(options.signature_re_level);
if ( ! rule_matcher->ReadFiles(all_signature_files) )
{ {
early_shutdown(); early_shutdown();
exit(1); exit(1);
} }
if ( options.print_signature_debug_info ) reporter->InitOptions();
rule_matcher->PrintDebug(); KeyedHash::InitOptions();
zeekygen_mgr->GenerateDocs();
file_mgr->InitMagic(); if ( options.pcap_filter )
}
if ( g_policy_debug )
// ### Add support for debug command file.
dbg_init_debugger(nullptr);
if ( ! options.pcap_file && ! options.interface )
{
const auto& interfaces_val = id::find_val("interfaces");
if ( interfaces_val )
{ {
char* interfaces_str = interfaces_val->AsString()->Render(); const auto& id = global_scope()->Find("cmd_line_bpf_filter");
if ( interfaces_str[0] != '\0' ) if ( ! id )
options.interface = interfaces_str; reporter->InternalError("global cmd_line_bpf_filter not defined");
delete[] interfaces_str; id->SetVal(make_intrusive<StringVal>(*options.pcap_filter));
} }
}
if ( options.parse_only ) std::vector<SignatureFile> all_signature_files;
{
if ( analysis_options.usage_issues > 0 )
analyze_scripts(options.no_unused_warnings);
early_shutdown(); // Append signature files given on the command line
exit(reporter->Errors() != 0); for ( const auto& sf : options.signature_files )
} all_signature_files.emplace_back(sf);
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr; // Append signature files defined in "signature_files" script option
for ( auto&& sf : get_script_signature_files() )
all_signature_files.emplace_back(std::move(sf));
analyze_scripts(options.no_unused_warnings); // Append signature files defined in @load-sigs
for ( const auto& sf : zeek::detail::sig_files )
all_signature_files.emplace_back(sf);
if ( analysis_options.report_recursive ) if ( ! all_signature_files.empty() )
{ {
// This option is report-and-exit. rule_matcher = new RuleMatcher(options.signature_re_level);
early_shutdown(); if ( ! rule_matcher->ReadFiles(all_signature_files) )
exit(0); {
} early_shutdown();
exit(1);
}
if ( dns_type != DNS_PRIME ) if ( options.print_signature_debug_info )
run_state::detail::init_run(options.interface, options.pcap_file, options.pcap_output_file, rule_matcher->PrintDebug();
options.use_watchdog);
if ( ! g_policy_debug ) file_mgr->InitMagic();
{ }
(void)setsignal(SIGTERM, sig_handler);
(void)setsignal(SIGINT, sig_handler);
(void)setsignal(SIGPIPE, SIG_IGN);
}
// Cooperate with nohup(1). if ( g_policy_debug )
if ( (oldhandler = setsignal(SIGHUP, sig_handler)) != SIG_DFL ) // ### Add support for debug command file.
(void)setsignal(SIGHUP, oldhandler); dbg_init_debugger(nullptr);
// If we were priming the DNS cache (i.e. -P was passed as an argument), flush anything if ( ! options.pcap_file && ! options.interface )
// remaining to be resolved and save the cache to disk. We can just exit now because {
// we've done everything we need to do. The run loop isn't started in this case, so const auto& interfaces_val = id::find_val("interfaces");
// nothing else should be happening. if ( interfaces_val )
if ( dns_type == DNS_PRIME ) {
{ char* interfaces_str = interfaces_val->AsString()->Render();
dns_mgr->Resolve();
if ( ! dns_mgr->Save() ) if ( interfaces_str[0] != '\0' )
reporter->FatalError("can't update DNS cache"); options.interface = interfaces_str;
delete[] interfaces_str;
}
}
if ( options.parse_only )
{
if ( analysis_options.usage_issues > 0 )
analyze_scripts(options.no_unused_warnings);
early_shutdown();
exit(reporter->Errors() != 0);
}
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr;
analyze_scripts(options.no_unused_warnings);
if ( analysis_options.report_recursive )
{
// This option is report-and-exit.
early_shutdown();
exit(0);
}
if ( dns_type != DNS_PRIME )
run_state::detail::init_run(options.interface, options.pcap_file,
options.pcap_output_file, options.use_watchdog);
if ( ! g_policy_debug )
{
(void)setsignal(SIGTERM, sig_handler);
(void)setsignal(SIGINT, sig_handler);
(void)setsignal(SIGPIPE, SIG_IGN);
}
// Cooperate with nohup(1).
if ( (oldhandler = setsignal(SIGHUP, sig_handler)) != SIG_DFL )
(void)setsignal(SIGHUP, oldhandler);
// If we were priming the DNS cache (i.e. -P was passed as an argument), flush anything
// remaining to be resolved and save the cache to disk. We can just exit now because
// we've done everything we need to do. The run loop isn't started in this case, so
// nothing else should be happening.
if ( dns_type == DNS_PRIME )
{
dns_mgr->Resolve();
if ( ! dns_mgr->Save() )
reporter->FatalError("can't update DNS cache");
event_mgr.Drain();
early_shutdown();
exit(0);
}
// Print the ID.
if ( options.identifier_to_print )
{
const auto& id = global_scope()->Find(*options.identifier_to_print);
if ( ! id )
reporter->FatalError("No such ID: %s\n", options.identifier_to_print->data());
ODesc desc;
desc.SetQuotes(true);
desc.SetIncludeStats(true);
id->DescribeExtended(&desc);
fprintf(stdout, "%s\n", desc.Description());
early_shutdown();
exit(0);
}
if ( profiling_interval > 0 )
{
const auto& profiling_file = id::find_val("profiling_file");
profiling_logger = std::make_shared<ProfileLogger>(profiling_file->AsFile(),
profiling_interval);
if ( segment_profiling )
segment_logger = profiling_logger;
}
if ( ! run_state::reading_live && ! run_state::reading_traces )
// Set up network_time to track real-time, since
// we don't have any other source for it.
run_state::detail::update_network_time(util::current_time());
if ( CPP_activation_hook )
(*CPP_activation_hook)();
if ( zeek_init )
event_mgr.Enqueue(zeek_init, Args{});
EventRegistry::string_list dead_handlers = event_registry->UnusedHandlers();
if ( ! dead_handlers.empty() && check_for_unused_event_handlers )
{
for ( const string& handler : dead_handlers )
reporter->Warning("event handler never invoked: %s", handler.c_str());
}
// Enable LeakSanitizer before zeek_init() and even before executing
// top-level statements. Even though it's not bad if a leak happens only
// once at initialization, we have to assume that script-layer code causing
// such a leak can be placed in any arbitrary event handler and potentially
// cause more severe problems.
ZEEK_LSAN_ENABLE();
if ( init_stmts )
{
StmtFlowType flow;
Frame f(init_stmts->Scope()->Length(), nullptr, nullptr);
g_frame_stack.push_back(&f);
try
{
init_stmts->Body()->Exec(&f, flow);
}
catch ( InterpreterException& )
{
reporter->FatalError("failed to execute script statements at top-level scope");
}
g_frame_stack.pop_back();
}
if ( options.ignore_checksums )
ignore_checksums = 1;
if ( zeek_script_loaded )
{
// Queue events reporting loaded scripts.
for ( const auto& file : zeek::detail::files_scanned )
{
if ( file.skipped )
continue;
event_mgr.Enqueue(zeek_script_loaded, make_intrusive<StringVal>(file.name.c_str()),
val_mgr->Count(file.include_level));
}
}
reporter->ReportViaEvents(true);
// Drain the event queue here to support the protocols framework configuring DPM
event_mgr.Drain(); event_mgr.Drain();
early_shutdown();
exit(0);
}
// Print the ID. if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") )
if ( options.identifier_to_print ) reporter->FatalError("errors occurred while initializing");
{
const auto& id = global_scope()->Find(*options.identifier_to_print);
if ( ! id )
reporter->FatalError("No such ID: %s\n", options.identifier_to_print->data());
ODesc desc; run_state::detail::zeek_init_done = true;
desc.SetQuotes(true); packet_mgr->DumpDebug();
desc.SetIncludeStats(true); analyzer_mgr->DumpDebug();
id->DescribeExtended(&desc);
fprintf(stdout, "%s\n", desc.Description()); run_state::detail::have_pending_timers = ! run_state::reading_traces &&
early_shutdown(); timer_mgr->Size() > 0;
exit(0);
}
if ( profiling_interval > 0 ) return {0, std::move(options)};
{
const auto& profiling_file = id::find_val("profiling_file");
profiling_logger = std::make_shared<ProfileLogger>(profiling_file->AsFile(),
profiling_interval);
if ( segment_profiling )
segment_logger = profiling_logger;
}
if ( ! run_state::reading_live && ! run_state::reading_traces )
// Set up network_time to track real-time, since
// we don't have any other source for it.
run_state::detail::update_network_time(util::current_time());
if ( CPP_activation_hook )
(*CPP_activation_hook)();
if ( zeek_init )
event_mgr.Enqueue(zeek_init, Args{});
EventRegistry::string_list dead_handlers = event_registry->UnusedHandlers();
if ( ! dead_handlers.empty() && check_for_unused_event_handlers )
{
for ( const string& handler : dead_handlers )
reporter->Warning("event handler never invoked: %s", handler.c_str());
}
// Enable LeakSanitizer before zeek_init() and even before executing
// top-level statements. Even though it's not bad if a leak happens only
// once at initialization, we have to assume that script-layer code causing
// such a leak can be placed in any arbitrary event handler and potentially
// cause more severe problems.
ZEEK_LSAN_ENABLE();
if ( init_stmts )
{
StmtFlowType flow;
Frame f(init_stmts->Scope()->Length(), nullptr, nullptr);
g_frame_stack.push_back(&f);
try
{
init_stmts->Body()->Exec(&f, flow);
}
catch ( InterpreterException& )
{
reporter->FatalError("failed to execute script statements at top-level scope");
}
g_frame_stack.pop_back();
}
if ( options.ignore_checksums )
ignore_checksums = 1;
if ( zeek_script_loaded )
{
// Queue events reporting loaded scripts.
for ( const auto& file : zeek::detail::files_scanned )
{
if ( file.skipped )
continue;
event_mgr.Enqueue(zeek_script_loaded, make_intrusive<StringVal>(file.name.c_str()),
val_mgr->Count(file.include_level));
}
}
reporter->ReportViaEvents(true);
// Drain the event queue here to support the protocols framework configuring DPM
event_mgr.Drain();
if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") )
reporter->FatalError("errors occurred while initializing");
run_state::detail::zeek_init_done = true;
packet_mgr->DumpDebug();
analyzer_mgr->DumpDebug();
run_state::detail::have_pending_timers = ! run_state::reading_traces && timer_mgr->Size() > 0;
return {0, std::move(options)};
} }
int cleanup(bool did_run_loop) int cleanup(bool did_run_loop)