From 4735165d31aaf1b9c1b4d8d0facbf9f9d2ad3a76 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 19 Dec 2019 18:36:15 -0800 Subject: [PATCH 01/28] Improve --sanitizers configure option * Rename SANITIZERS CMake variable to ZEEK_SANITIZERS for clarity * Use -O1 by default to improve speed (set NO_OPTIMIZATIONS env. var. to override and use -O0). Uses -fno-optimize-sibling-calls with -O1 to still get "perfect stack traces". * Updates various sub-projects with sanitizer improvements: binpac and bifcl, by default, now ignore leaks reported by LeakSanitizer so that it doesn't interfere with the Zeek build --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++---- aux/bifcl | 2 +- aux/binpac | 2 +- aux/broker | 2 +- configure | 6 +++--- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa5f6e7621..a18f82a19d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,10 +121,30 @@ if ( NOT BINARY_PACKAGING_MODE ) _make_install_dir_symlink("${CMAKE_INSTALL_PREFIX}/lib/bro" "${CMAKE_INSTALL_PREFIX}/lib/zeek") endif () -if ( SANITIZERS ) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SANITIZERS} -fno-omit-frame-pointer") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZERS} -fno-omit-frame-pointer") - set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -fsanitize=${SANITIZERS} -fno-omit-frame-pointer") +if ( ZEEK_SANITIZERS ) + # Check the thread library info early as setting compiler flags seems to + # interfere with the detection and cause CMAKE_THREAD_LIBS_INIT to not + # include -lpthread when it should. + find_package(Threads) + set(_sanitizer_flags "-fsanitize=${ZEEK_SANITIZERS}") + set(_sanitizer_flags "${_sanitizer_flags} -fno-omit-frame-pointer") + set(_sanitizer_flags "${_sanitizer_flags} -fno-optimize-sibling-calls") + + if ( NOT DEFINED ENV{NO_OPTIMIZATIONS} ) + # Using -O1 is generally the suggestion to get more reasonable + # performance. The one downside is it that the compiler may optimize out + # code that otherwise generates an error/leak in a -O0 build, but that + # should be rare and users mostly will not be running unoptimized builds + # in production anyway. + set(_sanitizer_flags "${_sanitizer_flags} -O1") + endif () + + # Technically, the we also need to use the compiler to drive linking and + # give the sanitizer flags there, too. However, CMake, by default, uses + # the compiler for linking and so the automatically flags get used. See + # https://cmake.org/pipermail/cmake/2014-August/058268.html + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_sanitizer_flags}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_sanitizer_flags}") endif() ######################################################################## @@ -205,6 +225,10 @@ if ( BROKER_ROOT_DIR ) set(zeekdeps ${zeekdeps} ${BROKER_LIBRARY}) set(broker_includes ${BROKER_INCLUDE_DIR}) else () + if ( ZEEK_SANITIZERS ) + set(BROKER_SANITIZERS ${ZEEK_SANITIZERS}) + endif () + set(ENABLE_STATIC_ONLY_SAVED ${ENABLE_STATIC_ONLY}) if ( BUILD_STATIC_BROKER ) diff --git a/aux/bifcl b/aux/bifcl index e5b1940850..9cc1f0dfcd 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit e5b1940850d486e3989f6a55615140a16bd1b9d2 +Subproject commit 9cc1f0dfcd7c9d7c7a4031d45732268e0d68206f diff --git a/aux/binpac b/aux/binpac index c02d6ff7be..71f815a220 160000 --- a/aux/binpac +++ b/aux/binpac @@ -1 +1 @@ -Subproject commit c02d6ff7be6bcee097d668f4f667f83c82a28cc6 +Subproject commit 71f815a22027bef47fa46459a1010013bd4f59e3 diff --git a/aux/broker b/aux/broker index 237c3cd2d8..5156ba056e 160000 --- a/aux/broker +++ b/aux/broker @@ -1 +1 @@ -Subproject commit 237c3cd2d87d467a5b9ac0517c6461ac00c7b85c +Subproject commit 5156ba056e1747b31466a29898564065d20d30a1 diff --git a/configure b/configure index 8b4b421753..cd6fd4b025 100755 --- a/configure +++ b/configure @@ -27,6 +27,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]... ccache installation and CMake 3.10+) --toolchain=PATH path to a CMAKE_TOOLCHAIN_FILE (useful for cross-compiling) + --sanitizers=LIST comma-separated list of sanitizer names to enable Installation Directories: --prefix=PREFIX installation directory [/usr/local/zeek] @@ -57,7 +58,6 @@ Usage: $0 [OPTION]... [VAR=VALUE]... --disable-auxtools don't build or install auxiliary tools --disable-python don't try to build python bindings for Broker --disable-broker-tests don't try to build Broker unit tests - --sanitizers=SANITIZERS comma-separated list of Clang sanitizers to enable Required Packages in Non-Standard Locations: --with-openssl=PATH path to OpenSSL install root @@ -154,7 +154,7 @@ append_cache_entry INSTALL_AUX_TOOLS BOOL true append_cache_entry INSTALL_ZEEKCTL BOOL true append_cache_entry CPACK_SOURCE_IGNORE_FILES STRING append_cache_entry ENABLE_MOBILE_IPV6 BOOL false -append_cache_entry SANITIZERS STRING "" +append_cache_entry ZEEK_SANITIZERS STRING "" # parse arguments while [ $# -ne 0 ]; do @@ -240,7 +240,7 @@ while [ $# -ne 0 ]; do append_cache_entry ENABLE_PERFTOOLS_DEBUG BOOL true ;; --sanitizers=*) - append_cache_entry SANITIZERS STRING $optarg + append_cache_entry ZEEK_SANITIZERS STRING $optarg ;; --enable-jemalloc) append_cache_entry ENABLE_JEMALLOC BOOL true From 447c3712cff49bb593f3cf8c468451a652b73b47 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 19 Dec 2019 18:42:49 -0800 Subject: [PATCH 02/28] Add general LeakSanitizer macros/instrumentation --- src/main.cc | 10 ++++++++++ zeek-config.h.in | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main.cc b/src/main.cc index d4bbf960b7..8a698f29e1 100644 --- a/src/main.cc +++ b/src/main.cc @@ -308,6 +308,8 @@ void done_with_network() abort(); } #endif + + ZEEK_LSAN_DISABLE(); } void terminate_bro() @@ -406,6 +408,7 @@ static void bro_new_handler() int main(int argc, char** argv) { + ZEEK_LSAN_DISABLE(); std::set_new_handler(bro_new_handler); // When running unit tests, the first argument on the command line must be @@ -1052,6 +1055,13 @@ int main(int argc, char** argv) 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 ( stmts ) { stmt_flow_type flow; diff --git a/zeek-config.h.in b/zeek-config.h.in index 343ab49363..eb208312ac 100644 --- a/zeek-config.h.in +++ b/zeek-config.h.in @@ -243,3 +243,29 @@ extern const char* BRO_VERSION_FUNCTION(); #ifdef __cplusplus } #endif + +// GCC uses __SANITIZE_ADDRESS__, Clang uses __has_feature +#if defined(__SANITIZE_ADDRESS__) + #define ZEEK_ASAN +#endif + +#if defined(__has_feature) + #if __has_feature(address_sanitizer) + #define ZEEK_ASAN + #endif +#endif + +#if defined(ZEEK_ASAN) + #include + #define ZEEK_LSAN_CHECK(x) __lsan_do_leak_check(x) + #define ZEEK_LSAN_ENABLE(x) __lsan_enable(x) + #define ZEEK_LSAN_IGNORE(x) __lsan_ignore_object(x) + #define ZEEK_LSAN_DISABLE(x) __lsan_disable(x) + #define ZEEK_LSAN_DISABLE_SCOPE(x) __lsan::ScopedDisabler x +#else + #define ZEEK_LSAN_CHECK(x) + #define ZEEK_LSAN_ENABLE(x) + #define ZEEK_LSAN_IGNORE(x) + #define ZEEK_LSAN_DISABLE(x) + #define ZEEK_LSAN_DISABLE_SCOPE(x) +#endif From bf90587cb8f9847c3e490c88b1d4f85aa93af8c9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 19 Dec 2019 18:46:30 -0800 Subject: [PATCH 03/28] Free the global X509 certificate root store on shutdown Otherwise LeakSanitizer reports its contents as leaked. --- src/file_analysis/analyzer/x509/Plugin.cc | 6 +++ src/file_analysis/analyzer/x509/X509.cc | 45 +++++++++++++++++++ src/file_analysis/analyzer/x509/X509.h | 25 +++++++++++ src/file_analysis/analyzer/x509/functions.bif | 42 +---------------- 4 files changed, 78 insertions(+), 40 deletions(-) diff --git a/src/file_analysis/analyzer/x509/Plugin.cc b/src/file_analysis/analyzer/x509/Plugin.cc index 9de6648893..f5cd95f2f6 100644 --- a/src/file_analysis/analyzer/x509/Plugin.cc +++ b/src/file_analysis/analyzer/x509/Plugin.cc @@ -22,6 +22,12 @@ public: config.description = "X509 and OCSP analyzer"; return config; } + + void Done() override + { + plugin::Plugin::Done(); + ::file_analysis::X509::FreeRootStore(); + } } plugin; } diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 9e89dc6dd9..bf9539c9aa 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -18,6 +18,10 @@ #include #include +namespace file_analysis { +std::map X509::x509_stores; +} + using namespace file_analysis; file_analysis::X509::X509(RecordVal* args, file_analysis::File* file) @@ -213,6 +217,47 @@ RecordVal* file_analysis::X509::ParseCertificate(X509Val* cert_val, File* f) return pX509Cert; } +X509_STORE* file_analysis::X509::GetRootStore(TableVal* root_certs) + { + // If this certificate store was built previously, just reuse the old one. + if ( x509_stores.count(root_certs) > 0 ) + return x509_stores[root_certs]; + + X509_STORE* ctx = X509_STORE_new(); + ListVal* idxs = root_certs->ConvertToPureList(); + + // Build the validation store + for ( int i = 0; i < idxs->Length(); ++i ) + { + Val* key = idxs->Index(i); + StringVal *sv = root_certs->Lookup(key)->AsStringVal(); + assert(sv); + const uint8_t* data = sv->Bytes(); + ::X509* x = d2i_X509(NULL, &data, sv->Len()); + if ( ! x ) + { + builtin_error(fmt("Root CA error: %s", ERR_error_string(ERR_get_error(),NULL))); + return 0; + } + + X509_STORE_add_cert(ctx, x); + X509_free(x); + } + + delete idxs; + + // Save the newly constructed certificate store into the cacheing map. + x509_stores[root_certs] = ctx; + + return ctx; + } + +void file_analysis::X509::FreeRootStore() + { + for ( const auto& e : x509_stores ) + X509_STORE_free(e.second); + } + void file_analysis::X509::ParseBasicConstraints(X509_EXTENSION* ex) { assert(OBJ_obj2nid(X509_EXTENSION_get_object(ex)) == NID_basic_constraints); diff --git a/src/file_analysis/analyzer/x509/X509.h b/src/file_analysis/analyzer/x509/X509.h index ca5fa60c57..59137f7fd3 100644 --- a/src/file_analysis/analyzer/x509/X509.h +++ b/src/file_analysis/analyzer/x509/X509.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include "OpaqueVal.h" #include "X509Common.h" @@ -89,6 +90,28 @@ public: static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) { return new X509(args, file); } + /** + * Retrieves OpenSSL's representation of an X509 certificate store + * associated with a script-layer certificate root table variable/value. + * The underlying X509 store will be created if it has not been already, + * else the previously allocated one for the same table will be returned. + * + * @param root_certs The script-layer certificate root table value. + * + * @return OpenSSL's X509 store associated with the table value. + */ + static X509_STORE* GetRootStore(TableVal* root_certs); + + /** + * Frees memory obtained from OpenSSL that is associated with the global + * X509 certificate store used by the Zeek scripting-layer. This primarily + * exists so leak checkers like LeakSanitizer don't count the + * globally-allocated mapping as a leak. Would be easy to suppress/ignore + * it, but that could accidentally silence cases where some new code + * mistakenly overwrites a table element without freeing it. + */ + static void FreeRootStore(); + protected: X509(RecordVal* args, File* file); @@ -102,6 +125,8 @@ private: // Helpers for ParseCertificate. static StringVal* KeyCurve(EVP_PKEY *key); static unsigned int KeyLength(EVP_PKEY *key); + /** X509 stores associated with global script-layer values */ + static std::map x509_stores; }; /** diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index eaf1ae918c..7c53e27bf3 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -10,9 +10,6 @@ #include #include -// This is the indexed map of X509 certificate stores. -static map x509_stores; - // construct an error record RecordVal* x509_result_record(uint64_t num, const char* reason, Val* chainVector = 0) { @@ -26,41 +23,6 @@ RecordVal* x509_result_record(uint64_t num, const char* reason, Val* chainVector return rrecord; } -X509_STORE* x509_get_root_store(TableVal* root_certs) - { - // If this certificate store was built previously, just reuse the old one. - if ( x509_stores.count(root_certs) > 0 ) - return x509_stores[root_certs]; - - X509_STORE* ctx = X509_STORE_new(); - ListVal* idxs = root_certs->ConvertToPureList(); - - // Build the validation store - for ( int i = 0; i < idxs->Length(); ++i ) - { - Val* key = idxs->Index(i); - StringVal *sv = root_certs->Lookup(key)->AsStringVal(); - assert(sv); - const uint8_t* data = sv->Bytes(); - X509* x = d2i_X509(NULL, &data, sv->Len()); - if ( ! x ) - { - builtin_error(fmt("Root CA error: %s", ERR_error_string(ERR_get_error(),NULL))); - return 0; - } - - X509_STORE_add_cert(ctx, x); - X509_free(x); - } - - delete idxs; - - // Save the newly constructed certificate store into the cacheing map. - x509_stores[root_certs] = ctx; - - return ctx; - } - // get all cretificates starting at the second one (assuming the first one is the host certificate) STACK_OF(X509)* x509_get_untrusted_stack(VectorVal* certs_vec) { @@ -254,7 +216,7 @@ function x509_get_certificate_string%(cert: opaque of x509, pem: bool &default=F function x509_ocsp_verify%(certs: x509_opaque_vector, ocsp_reply: string, root_certs: table_string_of_string, verify_time: time &default=network_time()%): X509::Result %{ RecordVal* rval = 0; - X509_STORE* ctx = x509_get_root_store(root_certs->AsTableVal()); + X509_STORE* ctx = ::file_analysis::X509::GetRootStore(root_certs->AsTableVal()); if ( ! ctx ) return x509_result_record(-1, "Problem initializing root store"); @@ -540,7 +502,7 @@ x509_ocsp_cleanup: ## x509_get_certificate_string x509_ocsp_verify sct_verify function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_string, verify_time: time &default=network_time()%): X509::Result %{ - X509_STORE* ctx = x509_get_root_store(root_certs->AsTableVal()); + X509_STORE* ctx = ::file_analysis::X509::GetRootStore(root_certs->AsTableVal()); if ( ! ctx ) return x509_result_record(-1, "Problem initializing root store"); From 2fbcf23f767797d321d7239f5260d16a25b16eb1 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 20 Dec 2019 13:51:35 -0800 Subject: [PATCH 04/28] Fix memory leak in OCSP parsing functions Various OCSP parsing functions used in presence of OpenSSL 1.1 used "d2i_ASN1_SEQUENCE_ANY" which returns a "STACK_OF(ASN1_TYPE)", but used "sk_ASN1_TYPE_free" instead of "sk_ASN1_TYPE_pop_free" to free it. The former only frees the stack structure while the later frees both the structure and the elements. --- src/file_analysis/analyzer/x509/OCSP.cc | 51 +++++++++++-------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 26e58fecae..8f5ed3419c 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -183,6 +183,23 @@ bool file_analysis::OCSP::EndOfFile() } #if ( OPENSSL_VERSION_NUMBER >= 0x10100000L ) + +struct ASN1Seq { + ASN1Seq(const unsigned char** der_in, long length) + { decoded = d2i_ASN1_SEQUENCE_ANY(nullptr, der_in, length); } + + ~ASN1Seq() + { sk_ASN1_TYPE_pop_free(decoded, ASN1_TYPE_free); } + + explicit operator bool() const + { return decoded; } + + operator ASN1_SEQUENCE_ANY*() const + { return decoded; } + + ASN1_SEQUENCE_ANY* decoded; +}; + // Re-encode and then parse out ASN1 structures to get at what we need... /*- BasicOCSPResponse ::= SEQUENCE { * tbsResponseData ResponseData, @@ -209,8 +226,7 @@ static StringVal* parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, const unsigned char* const_der_basic_resp_dat = der_basic_resp_dat; - auto bseq = d2i_ASN1_SEQUENCE_ANY(nullptr, &const_der_basic_resp_dat, - der_basic_resp_len); + ASN1Seq bseq{&const_der_basic_resp_dat, der_basic_resp_len}; if ( ! bseq ) { @@ -220,7 +236,6 @@ static StringVal* parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, if ( sk_ASN1_TYPE_num(bseq) < 3 ) { - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } @@ -230,7 +245,6 @@ static StringVal* parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, if ( ASN1_TYPE_get(aseq_type) != V_ASN1_SEQUENCE ) { - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } @@ -239,19 +253,16 @@ static StringVal* parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, auto aseq_len = ASN1_STRING_length(aseq_str); auto aseq_dat = ASN1_STRING_get0_data(aseq_str); - auto aseq = d2i_ASN1_SEQUENCE_ANY(nullptr, &aseq_dat, aseq_len); + ASN1Seq aseq{&aseq_dat, aseq_len}; if ( ! aseq ) { - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } if ( sk_ASN1_TYPE_num(aseq) < 1 ) { - sk_ASN1_TYPE_free(aseq); - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } @@ -261,8 +272,6 @@ static StringVal* parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, if ( ASN1_TYPE_get(alg_obj_type) != V_ASN1_OBJECT ) { - sk_ASN1_TYPE_free(aseq); - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } @@ -273,8 +282,6 @@ static StringVal* parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, auto rval = new StringVal(alg_len, buf); BIO_reset(bio); - sk_ASN1_TYPE_free(aseq); - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return rval; } @@ -291,8 +298,7 @@ static Val* parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) const unsigned char* const_der_basic_resp_dat = der_basic_resp_dat; - auto bseq = d2i_ASN1_SEQUENCE_ANY(nullptr, &const_der_basic_resp_dat, - der_basic_resp_len); + ASN1Seq bseq{&const_der_basic_resp_dat, der_basic_resp_len}; if ( ! bseq ) { @@ -302,7 +308,6 @@ static Val* parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) if ( sk_ASN1_TYPE_num(bseq) < 3 ) { - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetCount(-1); } @@ -312,7 +317,6 @@ static Val* parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) if ( ASN1_TYPE_get(dseq_type) != V_ASN1_SEQUENCE ) { - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetCount(-1); } @@ -321,19 +325,16 @@ static Val* parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) auto dseq_len = ASN1_STRING_length(dseq_str); auto dseq_dat = ASN1_STRING_get0_data(dseq_str); - auto dseq = d2i_ASN1_SEQUENCE_ANY(nullptr, &dseq_dat, dseq_len); + ASN1Seq dseq{&dseq_dat, dseq_len}; if ( ! dseq ) { - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } if ( sk_ASN1_TYPE_num(dseq) < 1 ) { - sk_ASN1_TYPE_free(dseq); - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetEmptyString(); } @@ -351,16 +352,12 @@ static Val* parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) if ( ASN1_TYPE_get(version_type) != V_ASN1_INTEGER ) { - sk_ASN1_TYPE_free(dseq); - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); // Not present, use default value. return val_mgr->GetCount(0); } uint64_t asn1_int = ASN1_INTEGER_get(version_type->value.integer); - sk_ASN1_TYPE_free(dseq); - sk_ASN1_TYPE_free(bseq); OPENSSL_free(der_basic_resp_dat); return val_mgr->GetCount(asn1_int); } @@ -375,8 +372,7 @@ static uint64_t parse_request_version(OCSP_REQUEST* req) if ( ! der_req_dat ) return -1; - auto rseq = d2i_ASN1_SEQUENCE_ANY(nullptr, &const_der_req_dat, - der_req_len); + ASN1Seq rseq{&const_der_req_dat, der_req_len}; if ( ! rseq ) { @@ -386,7 +382,6 @@ static uint64_t parse_request_version(OCSP_REQUEST* req) if ( sk_ASN1_TYPE_num(rseq) < 1 ) { - sk_ASN1_TYPE_free(rseq); OPENSSL_free(der_req_dat); return -1; } @@ -396,14 +391,12 @@ static uint64_t parse_request_version(OCSP_REQUEST* req) if ( ASN1_TYPE_get(version_type) != V_ASN1_INTEGER ) { - sk_ASN1_TYPE_free(rseq); OPENSSL_free(der_req_dat); // Not present, use default value. return 0; } uint64_t asn1_int = ASN1_INTEGER_get(version_type->value.integer); - sk_ASN1_TYPE_free(rseq); OPENSSL_free(der_req_dat); return asn1_int; } From 8cdcfad6d25f0c46ad00e0a29ea9539e1d67414f Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 23 Dec 2019 10:10:49 -0800 Subject: [PATCH 05/28] Delete/timeout pending DNS requests during shutdown Primarily, this change prevents the pending requests showing up as memory leaks. --- src/DNS_Mgr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 122588e18b..0b50700bd1 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -1404,7 +1404,7 @@ void DNS_Mgr::DoProcess() { AsyncRequest* req = asyncs_timeouts.top(); - if ( req->time + DNS_TIMEOUT > current_time() ) + if ( req->time + DNS_TIMEOUT > current_time() && ! terminating ) break; if ( ! req->processed ) From c0d6eb9efbc133c320a963729e99251d4b6952e3 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 23 Dec 2019 10:54:22 -0800 Subject: [PATCH 06/28] Fix malloc/delete mismatch in JSON formatting ODesc allocated with malloc() and BroString deallocated with delete[], but really the intermediate BroString wasn't even needed when copying into std::string. --- src/Val.cc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 907a29d062..53aecb0bbb 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -479,11 +479,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=nul ODesc d; d.SetStyle(RAW_STYLE); val->Describe(&d); - - auto* bs = new BroString(1, d.TakeBytes(), d.Len()); - j = string((char*)bs->Bytes(), bs->Len()); - - delete bs; + j = string(reinterpret_cast(d.Bytes()), d.Len()); break; } @@ -495,11 +491,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=nul ODesc d; d.SetStyle(RAW_STYLE); val->Describe(&d); - - auto* bs = new BroString(1, d.TakeBytes(), d.Len()); - j = json_escape_utf8(string((char*)bs->Bytes(), bs->Len())); - - delete bs; + j = json_escape_utf8(string(reinterpret_cast(d.Bytes()), d.Len())); break; } From aa0b5215975d620c36586f241df1abb14318e28e Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 23 Dec 2019 13:19:20 -0800 Subject: [PATCH 07/28] Update paraglob submodule --- aux/paraglob | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aux/paraglob b/aux/paraglob index 6c2b36193e..d65dd0aa04 160000 --- a/aux/paraglob +++ b/aux/paraglob @@ -1 +1 @@ -Subproject commit 6c2b36193e47490e61f22ce6de233af7ed3101b1 +Subproject commit d65dd0aa04e73cca884d3630b57532bb3fe3974d From 10473d58a9472242002895d12aead38ea7a1e95f Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 26 Dec 2019 08:14:09 -0800 Subject: [PATCH 08/28] Fix scripting error in an ftp btest --- testing/btest/scripts/base/protocols/ftp/cwd-navigation.zeek | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/btest/scripts/base/protocols/ftp/cwd-navigation.zeek b/testing/btest/scripts/base/protocols/ftp/cwd-navigation.zeek index 79b41fa28d..b07033ca7c 100644 --- a/testing/btest/scripts/base/protocols/ftp/cwd-navigation.zeek +++ b/testing/btest/scripts/base/protocols/ftp/cwd-navigation.zeek @@ -6,6 +6,9 @@ # Make sure we're tracking the CWD correctly. event ftp_reply(c: connection, code: count, msg: string, cont_resp: bool) &priority=10 { + if ( ! c?$ftp ) + return; + print "CWD", c$ftp$cwd; } From 53fadb2bb0e9a165dac3899290282236f770be68 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 26 Dec 2019 09:41:21 -0800 Subject: [PATCH 09/28] Fix memory leaks in Kerberos ticket decryption Memory allocated to the decrypted ticket data as well as the server principal were not freed. Also fixed potential leaks in error cases that called krb5_get_error_message() without freeing the returned value. --- src/analyzer/protocol/krb/KRB.cc | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/analyzer/protocol/krb/KRB.cc b/src/analyzer/protocol/krb/KRB.cc index 26c00693da..65e764eca1 100644 --- a/src/analyzer/protocol/krb/KRB.cc +++ b/src/analyzer/protocol/krb/KRB.cc @@ -25,6 +25,13 @@ KRB_Analyzer::KRB_Analyzer(Connection* conn) } #ifdef USE_KRB5 +static void warn_krb(const char* msg, krb5_context ctx, krb5_error_code code) + { + auto err = krb5_get_error_message(ctx, code); + reporter->Warning("%s (%s)", msg, err); + krb5_free_error_message(ctx, err); + } + void KRB_Analyzer::Initialize_Krb() { if ( BifConst::KRB::keytab->Len() == 0 ) @@ -40,14 +47,14 @@ void KRB_Analyzer::Initialize_Krb() krb5_error_code retval = krb5_init_context(&krb_context); if ( retval ) { - reporter->Warning("KRB: Couldn't initialize the context (%s)", krb5_get_error_message(krb_context, retval)); + warn_krb("KRB: Couldn't initialize the context", krb_context, retval); return; } retval = krb5_kt_resolve(krb_context, keytab_filename, &krb_keytab); if ( retval ) { - reporter->Warning("KRB: Couldn't resolve keytab (%s)", krb5_get_error_message(krb_context, retval)); + warn_krb("KRB: Couldn't resolve keytab", krb_context, retval); return; } krb_available = true; @@ -103,33 +110,44 @@ StringVal* KRB_Analyzer::GetAuthenticationInfo(const BroString* principal, const krb5_error_code retval = krb5_sname_to_principal(krb_context, hostname->CheckString(), service->CheckString(), KRB5_NT_SRV_HST, &sprinc); if ( retval ) { - reporter->Warning("KRB: Couldn't generate principal name (%s)", krb5_get_error_message(krb_context, retval)); + warn_krb("KRB: Couldn't generate principal name", krb_context, retval); return nullptr; } - krb5_ticket tkt; - tkt.server = sprinc; - tkt.enc_part.enctype = enctype; - tkt.enc_part.ciphertext.data = reinterpret_cast(ciphertext->Bytes()); - tkt.enc_part.ciphertext.length = ciphertext->Len(); + auto tkt = static_cast(safe_malloc(sizeof(krb5_ticket))); + memset(tkt, 0, sizeof(krb5_ticket)); + + tkt->server = sprinc; + tkt->enc_part.enctype = enctype; + + auto ctd = static_cast(safe_malloc(ciphertext->Len())); + memcpy(ctd, ciphertext->Bytes(), ciphertext->Len()); + tkt->enc_part.ciphertext.data = ctd; + tkt->enc_part.ciphertext.length = ciphertext->Len(); + + retval = krb5_server_decrypt_ticket_keytab(krb_context, krb_keytab, tkt); - retval = krb5_server_decrypt_ticket_keytab(krb_context, krb_keytab, &tkt); if ( retval ) { - reporter->Warning("KRB: Couldn't decrypt ticket (%s)", krb5_get_error_message(krb_context, retval)); + krb5_free_ticket(krb_context, tkt); + warn_krb("KRB: Couldn't decrypt ticket", krb_context, retval); return nullptr; } char* cp; - retval = krb5_unparse_name(krb_context, tkt.enc_part2->client, &cp); + retval = krb5_unparse_name(krb_context, tkt->enc_part2->client, &cp); + if ( retval ) { - reporter->Warning("KRB: Couldn't unparse name (%s)", krb5_get_error_message(krb_context, retval)); + krb5_free_ticket(krb_context, tkt); + warn_krb("KRB: Couldn't unparse name", krb_context, retval); return nullptr; } + StringVal* ret = new StringVal(cp); krb5_free_unparsed_name(krb_context, cp); + krb5_free_ticket(krb_context, tkt); return ret; #else From d936607cc99065cc2bdacb4c3f58cdb1c2aea296 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 26 Dec 2019 09:50:33 -0800 Subject: [PATCH 10/28] Fix scripting error in a DHCP btest --- .../protocols/dhcp/dhcp-time-nameserver-events.zeek | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/testing/btest/scripts/base/protocols/dhcp/dhcp-time-nameserver-events.zeek b/testing/btest/scripts/base/protocols/dhcp/dhcp-time-nameserver-events.zeek index bba8a0412f..4ac896c465 100644 --- a/testing/btest/scripts/base/protocols/dhcp/dhcp-time-nameserver-events.zeek +++ b/testing/btest/scripts/base/protocols/dhcp/dhcp-time-nameserver-events.zeek @@ -5,8 +5,12 @@ event DHCP::aggregate_msgs(ts: time, id: conn_id, uid: string, is_orig: bool, msg: DHCP::Msg, options: DHCP::Options) &priority=5 { - print "time_offset", options$time_offset; - print "timeserver_list", options$time_servers; - print "nameserver_list", options$name_servers; - print "ntpserver_list", options$ntp_servers; + if ( options?$time_offset ) + print "time_offset", options$time_offset; + if ( options?$time_servers ) + print "timeserver_list", options$time_servers; + if ( options?$name_servers ) + print "nameserver_list", options$name_servers; + if ( options?$ntp_servers ) + print "ntpserver_list", options$ntp_servers; } From 3742e5601c7390aacd1f8ce59b054e0090d7524a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 27 Dec 2019 07:11:02 -0800 Subject: [PATCH 11/28] Fix memory leak when table-based input stream overwrites old entries --- src/input/Manager.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 68964dd121..44b819f04d 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1289,7 +1289,8 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) if ( predidx != 0 ) Unref(predidx); - stream->currDict->Insert(idxhash, ih); + auto prev = stream->currDict->Insert(idxhash, ih); + delete prev; delete idxhash; if ( stream->event ) From 9e07b8a9f1adff2c97c848dfd454029c47c6e0fa Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 27 Dec 2019 07:35:59 -0800 Subject: [PATCH 12/28] Prevent duplicate "finish" threading messages As they don't get processed and may show up as a memory leak. --- src/threading/MsgThread.cc | 4 +++- src/threading/MsgThread.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/threading/MsgThread.cc b/src/threading/MsgThread.cc index dc399020da..7d7ab73a50 100644 --- a/src/threading/MsgThread.cc +++ b/src/threading/MsgThread.cc @@ -176,6 +176,7 @@ MsgThread::MsgThread() : BasicThread(), queue_in(this, 0), queue_out(0, this) cnt_sent_in = cnt_sent_out = 0; main_finished = false; child_finished = false; + child_sent_finish = false; failed = false; thread_mgr->AddMsgThread(this); } @@ -185,9 +186,10 @@ extern int signal_val; void MsgThread::OnSignalStop() { - if ( main_finished || Killed() ) + if ( main_finished || Killed() || child_sent_finish ) return; + child_sent_finish = true; // Signal thread to terminate. SendIn(new FinishMessage(this, network_time), true); } diff --git a/src/threading/MsgThread.h b/src/threading/MsgThread.h index 70d6fafc6e..1f5ec0e017 100644 --- a/src/threading/MsgThread.h +++ b/src/threading/MsgThread.h @@ -306,6 +306,7 @@ private: bool main_finished; // Main thread is finished, meaning child_finished propagated back through message queue. bool child_finished; // Child thread is finished. + bool child_sent_finish; // Child thread asked to be finished. bool failed; // Set to true when a command failed. }; From 13831ca21b773ec2f2822276e27a90654ebc54f9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 27 Dec 2019 08:08:46 -0800 Subject: [PATCH 13/28] Fix memory leak of sqlite input reader prepared statement --- src/input/readers/sqlite/SQLite.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index 8dcaed61c0..f08167ed25 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -49,6 +49,9 @@ SQLite::~SQLite() void SQLite::DoClose() { + sqlite3_finalize(st); + st = nullptr; + if ( db != 0 ) { sqlite3_close(db); From 7db84dfcb6bb54155291eaeec948fdbaf8b9da36 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 27 Dec 2019 09:10:01 -0800 Subject: [PATCH 14/28] Skip sending thread heartbeat if it alread asked to be finished Otherwise the heartbeat message may fail to be processed and show up as leaked memory. --- src/threading/MsgThread.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/threading/MsgThread.cc b/src/threading/MsgThread.cc index 7d7ab73a50..01f90921e8 100644 --- a/src/threading/MsgThread.cc +++ b/src/threading/MsgThread.cc @@ -260,6 +260,9 @@ void MsgThread::OnKill() void MsgThread::Heartbeat() { + if ( child_sent_finish ) + return; + SendIn(new HeartbeatMessage(this, network_time, current_time())); } From a961f0b4c4ad5a365d2078acbacaf6a380997013 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 30 Dec 2019 10:52:50 -0800 Subject: [PATCH 15/28] Fix packet filter memory leaks --- src/PacketFilter.cc | 41 +++++++++++++++++++++++++++++++++-------- src/PacketFilter.h | 4 +++- src/PrefixTable.h | 10 +++++++--- src/patricia.c | 6 +++--- src/patricia.h | 11 ++++++----- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/PacketFilter.cc b/src/PacketFilter.cc index c89c59a39a..f506d1778e 100644 --- a/src/PacketFilter.cc +++ b/src/PacketFilter.cc @@ -1,11 +1,25 @@ #include "PacketFilter.h" +void PacketFilter::DeleteFilter(void* data) + { + auto f = static_cast(data); + delete f; + } + +PacketFilter::PacketFilter(bool arg_default) + { + default_match = arg_default; + src_filter.SetDeleteFunction(PacketFilter::DeleteFilter); + dst_filter.SetDeleteFunction(PacketFilter::DeleteFilter); + } + void PacketFilter::AddSrc(const IPAddr& src, uint32_t tcp_flags, double probability) { Filter* f = new Filter; f->tcp_flags = tcp_flags; f->probability = uint32_t(probability * RAND_MAX); - src_filter.Insert(src, 128, f); + auto prev = static_cast(src_filter.Insert(src, 128, f)); + delete prev; } void PacketFilter::AddSrc(Val* src, uint32_t tcp_flags, double probability) @@ -13,7 +27,8 @@ void PacketFilter::AddSrc(Val* src, uint32_t tcp_flags, double probability) Filter* f = new Filter; f->tcp_flags = tcp_flags; f->probability = uint32_t(probability * RAND_MAX); - src_filter.Insert(src, f); + auto prev = static_cast(src_filter.Insert(src, f)); + delete prev; } void PacketFilter::AddDst(const IPAddr& dst, uint32_t tcp_flags, double probability) @@ -21,7 +36,8 @@ void PacketFilter::AddDst(const IPAddr& dst, uint32_t tcp_flags, double probabil Filter* f = new Filter; f->tcp_flags = tcp_flags; f->probability = uint32_t(probability * RAND_MAX); - dst_filter.Insert(dst, 128, f); + auto prev = static_cast(dst_filter.Insert(dst, 128, f)); + delete prev; } void PacketFilter::AddDst(Val* dst, uint32_t tcp_flags, double probability) @@ -29,27 +45,36 @@ void PacketFilter::AddDst(Val* dst, uint32_t tcp_flags, double probability) Filter* f = new Filter; f->tcp_flags = tcp_flags; f->probability = uint32_t(probability * RAND_MAX); - dst_filter.Insert(dst, f); + auto prev = static_cast(dst_filter.Insert(dst, f)); + delete prev; } bool PacketFilter::RemoveSrc(const IPAddr& src) { - return src_filter.Remove(src, 128) != 0; + auto f = static_cast(src_filter.Remove(src, 128)); + delete f; + return f != nullptr; } bool PacketFilter::RemoveSrc(Val* src) { - return src_filter.Remove(src) != NULL; + auto f = static_cast(src_filter.Remove(src)); + delete f; + return f != nullptr; } bool PacketFilter::RemoveDst(const IPAddr& dst) { - return dst_filter.Remove(dst, 128) != NULL; + auto f = static_cast(dst_filter.Remove(dst, 128)); + delete f; + return f != nullptr; } bool PacketFilter::RemoveDst(Val* dst) { - return dst_filter.Remove(dst) != NULL; + auto f = static_cast(dst_filter.Remove(dst)); + delete f; + return f != nullptr; } bool PacketFilter::Match(const IP_Hdr* ip, int len, int caplen) diff --git a/src/PacketFilter.h b/src/PacketFilter.h index 1b5111800f..384ce503c5 100644 --- a/src/PacketFilter.h +++ b/src/PacketFilter.h @@ -7,7 +7,7 @@ class PacketFilter { public: - explicit PacketFilter(bool arg_default) { default_match = arg_default; } + explicit PacketFilter(bool arg_default); ~PacketFilter() {} // Drops all packets from a particular source (which may be given @@ -34,6 +34,8 @@ private: uint32_t probability; }; + static void DeleteFilter(void* data); + bool MatchFilter(const Filter& f, const IP_Hdr& ip, int len, int caplen); bool default_match; diff --git a/src/PrefixTable.h b/src/PrefixTable.h index 35da3533ed..e22a89fff8 100644 --- a/src/PrefixTable.h +++ b/src/PrefixTable.h @@ -18,8 +18,8 @@ private: }; public: - PrefixTable() { tree = New_Patricia(128); } - ~PrefixTable() { Destroy_Patricia(tree, 0); } + PrefixTable() { tree = New_Patricia(128); delete_function = nullptr; } + ~PrefixTable() { Destroy_Patricia(tree, delete_function); } // Addr in network byte order. If data is zero, acts like a set. // Returns ptr to old data if already existing. @@ -43,7 +43,10 @@ public: void* Remove(const IPAddr& addr, int width); void* Remove(const Val* value); - void Clear() { Clear_Patricia(tree, 0); } + void Clear() { Clear_Patricia(tree, delete_function); } + + // Sets a function to call for each node when table is cleared/destroyed. + void SetDeleteFunction(data_fn_t del_fn) { delete_function = del_fn; } iterator InitIterator(); void* GetNext(iterator* i); @@ -53,4 +56,5 @@ private: static IPPrefix PrefixToIPPrefix(prefix_t* p); patricia_tree_t* tree; + data_fn_t delete_function; }; diff --git a/src/patricia.c b/src/patricia.c index 1928d8ed0e..27fe5e004c 100644 --- a/src/patricia.c +++ b/src/patricia.c @@ -432,7 +432,7 @@ New_Patricia (int maxbits) */ void -Clear_Patricia (patricia_tree_t *patricia, void_fn_t func) +Clear_Patricia (patricia_tree_t *patricia, data_fn_t func) { assert (patricia); if (patricia->head) { @@ -476,7 +476,7 @@ Clear_Patricia (patricia_tree_t *patricia, void_fn_t func) void -Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func) +Destroy_Patricia (patricia_tree_t *patricia, data_fn_t func) { Clear_Patricia (patricia, func); Delete (patricia); @@ -489,7 +489,7 @@ Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func) */ void -patricia_process (patricia_tree_t *patricia, void_fn_t func) +patricia_process (patricia_tree_t *patricia, prefix_data_fn_t func) { patricia_node_t *node; assert (func); diff --git a/src/patricia.h b/src/patricia.h index 819230be1d..a32c5e3e81 100644 --- a/src/patricia.h +++ b/src/patricia.h @@ -51,8 +51,6 @@ #include -/* typedef unsigned int u_int; */ -typedef void (*void_fn_t)(); /* { from defs.h */ #define prefix_touchar(prefix) ((u_char *)&(prefix)->add.sin) #define MAXLINE 1024 @@ -84,6 +82,9 @@ typedef struct _prefix_t { } add; } prefix_t; +typedef void (*data_fn_t)(void*); +typedef void (*prefix_data_fn_t)(prefix_t*, void*); + /* } */ typedef struct _patricia_node_t { @@ -110,9 +111,9 @@ patricia_node_t * patricia_search_best2 (patricia_tree_t *patricia, prefix_t *pr patricia_node_t *patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix); void patricia_remove (patricia_tree_t *patricia, patricia_node_t *node); patricia_tree_t *New_Patricia (int maxbits); -void Clear_Patricia (patricia_tree_t *patricia, void_fn_t func); -void Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func); -void patricia_process (patricia_tree_t *patricia, void_fn_t func); +void Clear_Patricia (patricia_tree_t *patricia, data_fn_t func); +void Destroy_Patricia (patricia_tree_t *patricia, data_fn_t func); +void patricia_process (patricia_tree_t *patricia, prefix_data_fn_t func); void Deref_Prefix (prefix_t * prefix); From 5e7394932788cda9f33d9855c89810f8960ba91b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 30 Dec 2019 11:17:43 -0800 Subject: [PATCH 16/28] Fix memory leak in initializing log writers with no local backend --- src/logging/WriterFrontend.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/logging/WriterFrontend.cc b/src/logging/WriterFrontend.cc index fdc4a7a97b..342c4f06a6 100644 --- a/src/logging/WriterFrontend.cc +++ b/src/logging/WriterFrontend.cc @@ -133,6 +133,11 @@ WriterFrontend::WriterFrontend(const WriterBackend::WriterInfo& arg_info, EnumVa WriterFrontend::~WriterFrontend() { + for ( auto i = 0; i < num_fields; ++i ) + delete fields[i]; + + delete [] fields; + Unref(stream); Unref(writer); delete info; @@ -165,7 +170,14 @@ void WriterFrontend::Init(int arg_num_fields, const Field* const * arg_fields) initialized = true; if ( backend ) - backend->SendIn(new InitMessage(backend, arg_num_fields, arg_fields)); + { + auto fs = new Field*[num_fields]; + + for ( auto i = 0; i < num_fields; ++i ) + fs[i] = new Field(*fields[i]); + + backend->SendIn(new InitMessage(backend, arg_num_fields, fs)); + } if ( remote ) { From 9e494452f10f3931ea3bc41df0fbdf445314945d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 30 Dec 2019 14:04:19 -0800 Subject: [PATCH 17/28] Clean up triggers awaiting global state modification at shutdown Otherwise they can be reported as memory leaks since no more global state modifications will take place to notify the trigger to clean itself up. --- src/Notifier.cc | 11 +++++++++++ src/Notifier.h | 12 ++++++++++++ src/Trigger.cc | 21 +++++++++++++++++++++ src/Trigger.h | 4 ++++ src/main.cc | 1 + 5 files changed, 49 insertions(+) diff --git a/src/Notifier.cc b/src/Notifier.cc index 511eb33beb..265c574b2a 100644 --- a/src/Notifier.cc +++ b/src/Notifier.cc @@ -65,6 +65,17 @@ void notifier::Registry::Modified(Modifiable* m) i->second->Modified(m); } +void notifier::Registry::Terminate() + { + std::set receivers; + + for ( auto& r : registrations ) + receivers.emplace(r.second); + + for ( auto& r : receivers ) + r->Terminate(); + } + notifier::Modifiable::~Modifiable() { if ( num_receivers ) diff --git a/src/Notifier.h b/src/Notifier.h index 01ab3e3dc1..e85345fa81 100644 --- a/src/Notifier.h +++ b/src/Notifier.h @@ -30,6 +30,12 @@ public: * @param m object that was modified */ virtual void Modified(Modifiable* m) = 0; + + /** + * Callback executed when notification registry is terminating and + * no further modifications can possibly occur. + */ + virtual void Terminate() { } }; /** Singleton class tracking all notification requests globally. */ @@ -69,6 +75,12 @@ public: */ void Unregister(Modifiable* m); + /** + * Notifies all receivers that no further modifications will occur + * as the registry is shutting down. + */ + void Terminate(); + private: friend class Modifiable; diff --git a/src/Trigger.cc b/src/Trigger.cc index 5caffaa74d..3df2e9e43e 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -171,6 +171,27 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts, Unref(this); } +void Trigger::Terminate() + { + if ( is_return ) + { + auto parent = frame->GetTrigger(); + + if ( ! parent->Disabled() ) + { + // If the trigger was already disabled due to interpreter + // exception, an Unref already happened at that point. + parent->Disable(); + Unref(parent); + } + + frame->ClearTrigger(); + } + + Disable(); + Unref(this); + } + Trigger::~Trigger() { DBG_LOG(DBG_NOTIFIERS, "%s: deleting", Name()); diff --git a/src/Trigger.h b/src/Trigger.h index 59ba30b300..e9fcc087a2 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -62,6 +62,10 @@ public: // later to avoid race conditions. void Modified(notifier::Modifiable* m) override { QueueTrigger(this); } + // Overridden from notifer::Receiver. If we're still waiting + // on an ID/Val to be modified at termination time, we can't hope + // for any further progress to be made, so just Unref ourselves. + void Terminate() override; const char* Name() const; diff --git a/src/main.cc b/src/main.cc index 8a698f29e1..a3e7f37e9d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -343,6 +343,7 @@ void terminate_bro() mgr.Drain(); + notifier::registry.Terminate(); log_mgr->Terminate(); input_mgr->Terminate(); thread_mgr->Terminate(); From 273eb19ff5780d8d823631f906fb2fcf2e81b312 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 31 Dec 2019 09:20:06 -0800 Subject: [PATCH 18/28] Fix memory leak in system_env() BIF --- src/zeek.bif | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zeek.bif b/src/zeek.bif index c710de01f0..2f56ca52c0 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -397,7 +397,7 @@ function terminate%(%): bool // is false). static bool prepare_environment(TableVal* tbl, bool set) { - ListVal* idxs = tbl->ConvertToPureList(); + IntrusivePtr idxs{tbl->ConvertToPureList(), false}; for ( int i = 0; i < idxs->Length(); ++i ) { From bf05add5423cdeedddad21c07b08a3a65ce98431 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 31 Dec 2019 10:40:48 -0800 Subject: [PATCH 19/28] Fix reference counting of Log::Filter "config" field Which can potentially be a minor memory leak if there's a lot of dynamic adding/removing of logging filters. --- src/logging/Manager.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 0fe75b91db..ac4477aad8 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -98,6 +98,7 @@ Manager::Filter::~Filter() free(fields); Unref(path_val); + Unref(config); } Manager::Stream::~Stream() From 3b6a2a5f4ebb04dda32f7f35fad4ed603d226a6d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 31 Dec 2019 10:55:37 -0800 Subject: [PATCH 20/28] Fix memory leak in Reporter::get_weird_sampling_whitelist() BIF --- src/reporter.bif | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reporter.bif b/src/reporter.bif index dd74b944d6..c1f2d16430 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -156,7 +156,8 @@ function Reporter::get_weird_sampling_whitelist%(%): string_set TableVal* set = new TableVal(string_set); for ( auto el : reporter->GetWeirdSamplingWhitelist() ) { - set->Assign(new StringVal(el), nullptr); + auto idx = make_intrusive(el); + set->Assign(idx.get(), nullptr); } return set; %} From 6f5f7df9705e7eff95b88203b2b4ee95d52d55b8 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 31 Dec 2019 11:08:45 -0800 Subject: [PATCH 21/28] Fix memory leaks in various input framework error-handling cases --- src/input/Manager.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 44b819f04d..cbfa4086d9 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -444,6 +444,7 @@ bool Manager::CreateEventStream(RecordVal* fval) if ( status ) { reporter->Error("Input stream %s: Problem unrolling", stream_name.c_str()); + for ( auto& f : fieldsV ) delete f; return false; } @@ -453,6 +454,7 @@ bool Manager::CreateEventStream(RecordVal* fval) if ( ! res ) { delete stream; + for ( auto& f : fieldsV ) delete f; return false; } @@ -671,6 +673,7 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( (valfields > 1) && (want_record->InternalInt() != 1) ) { reporter->Error("Input stream %s: Stream does not want a record (want_record=F), but has more then one value field.", stream_name.c_str()); + for ( auto& f : fieldsV ) delete f; return false; } @@ -680,6 +683,7 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( status ) { reporter->Error("Input stream %s: Problem unrolling", stream_name.c_str()); + for ( auto& f : fieldsV ) delete f; return false; } @@ -689,6 +693,7 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( ! res ) { delete stream; + for ( auto& f : fieldsV ) delete f; return false; } } From 09578c6176e5be2f794ebbfc323ef517e45131e9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 31 Dec 2019 11:53:09 -0800 Subject: [PATCH 22/28] Fix memory leak when a logging plugin hook prevents a write --- src/logging/Manager.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index ac4477aad8..a5ed5e3c35 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -920,6 +920,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns) filter->fields, vals), true) ) { + Unref(columns); DeleteVals(filter->num_fields, vals); #ifdef DEBUG From d9177377668190bb058d6894c3ce91eb0573b9f9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 31 Dec 2019 13:04:29 -0800 Subject: [PATCH 23/28] Rewrite the btest for when-statement timeouts To avoid a memory leak in DNS lookups that's hard to work around and does not otherwise effect typical operation when Zeek is allowed to continue to run after zeek_init(). --- .../language.timeout/{out => zeek..stdout} | 0 testing/btest/language/timeout.zeek | 24 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) rename testing/btest/Baseline/language.timeout/{out => zeek..stdout} (100%) diff --git a/testing/btest/Baseline/language.timeout/out b/testing/btest/Baseline/language.timeout/zeek..stdout similarity index 100% rename from testing/btest/Baseline/language.timeout/out rename to testing/btest/Baseline/language.timeout/zeek..stdout diff --git a/testing/btest/language/timeout.zeek b/testing/btest/language/timeout.zeek index b23839cd53..98990611eb 100644 --- a/testing/btest/language/timeout.zeek +++ b/testing/btest/language/timeout.zeek @@ -1,19 +1,21 @@ -# @TEST-EXEC: unset ZEEK_DNS_FAKE && unset BRO_DNS_FAKE && zeek -b %INPUT >out -# @TEST-EXEC: btest-diff out +# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT +# @TEST-EXEC: btest-bg-wait 10 +# @TEST-EXEC: btest-diff zeek/.stdout +redef exit_only_after_terminate=T; + +global myset = set("yes"); event zeek_init() -{ - local h1: addr = 1.2.3.4; - - when ( local h1name = lookup_addr(h1) ) - { + { + when ( "no" in myset ) + { print "lookup successful"; + terminate(); } - timeout 3 secs + timeout 0.25sec { print "timeout"; + terminate(); } - -} - + } From 0fe2a14d9855dfa434655ae7797b8591ece53bc8 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 23 Dec 2019 11:21:46 -0800 Subject: [PATCH 24/28] Disable LeakSanitizer for btests that have known leaks E.g. ones that throw interpreter exceptions, as those are currently known to potentially cause leaks. Fixing the underlying leaks involves the larger task of more IntrusivePtr usage. Reference cycles may also cause leaks. --- testing/btest/Baseline/core.div-by-zero/out | 4 +- .../Baseline/core.expr-exception/reporter.log | 18 ++++----- .../core.reporter-error-in-handler/output | 4 +- .../zeek.output | 8 ++-- .../language.expire-expr-error/output | 2 +- .../language.expire-func-undef/output | 38 +++++++++---------- .../language.index-assignment-invalid/out | 6 +-- .../btest/Baseline/language.invalid_index/out | 4 +- .../language.type-cast-error-dynamic/output | 6 +-- .../language.uninitialized-local2/out | 2 +- .../Baseline/plugins.reporter-hook/output | 20 +++++----- .../plugins.reporter-hook/reporter.log | 8 ++-- .../reporter.log | 2 +- .../.stderr | 2 +- .../reporter.log | 2 +- testing/btest/core/div-by-zero.zeek | 3 +- testing/btest/core/expr-exception.zeek | 3 +- .../btest/core/reporter-error-in-handler.zeek | 3 +- .../core/when-interpreter-exceptions.zeek | 3 +- testing/btest/language/common-mistakes.zeek | 7 ++-- testing/btest/language/copy-cycle.zeek | 4 +- testing/btest/language/expire-expr-error.zeek | 3 +- testing/btest/language/expire-func-undef.zeek | 3 +- .../language/index-assignment-invalid.zeek | 3 +- testing/btest/language/invalid_index.zeek | 3 +- testing/btest/language/subnet-errors.zeek | 3 +- .../language/type-cast-error-dynamic.zeek | 3 +- .../btest/language/type-coerce-numerics.zeek | 3 +- .../btest/language/uninitialized-local2.zeek | 3 +- testing/btest/plugins/reporter-hook.zeek | 3 +- .../frameworks/reporter/disable-stderr.zeek | 3 +- .../base/frameworks/reporter/stderr.zeek | 3 +- 32 files changed, 100 insertions(+), 82 deletions(-) diff --git a/testing/btest/Baseline/core.div-by-zero/out b/testing/btest/Baseline/core.div-by-zero/out index 702d00c156..d85b92e8d9 100644 --- a/testing/btest/Baseline/core.div-by-zero/out +++ b/testing/btest/Baseline/core.div-by-zero/out @@ -1,5 +1,5 @@ expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 6: division by zero (a / b) expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 11: division by zero (a / b) expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 16: division by zero (a / b) -expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 21: modulo by zero (a % b) -expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 26: modulo by zero (a % b) +expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 22: modulo by zero (a % b) +expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.div-by-zero/div-by-zero.zeek, line 27: modulo by zero (a % b) diff --git a/testing/btest/Baseline/core.expr-exception/reporter.log b/testing/btest/Baseline/core.expr-exception/reporter.log index e2e1a4103f..65227ce285 100644 --- a/testing/btest/Baseline/core.expr-exception/reporter.log +++ b/testing/btest/Baseline/core.expr-exception/reporter.log @@ -6,13 +6,13 @@ #open 2011-03-18-19-06-08 #fields ts level message location #types time enum string string -1300475168.783842 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.915940 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.916118 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.918295 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.952193 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.952228 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.954761 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475168.962628 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 -1300475169.780331 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 10 +1300475168.783842 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.915940 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.916118 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.918295 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.952193 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.952228 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.954761 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475168.962628 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 +1300475169.780331 Reporter::ERROR field value missing (c$ftp) /da/home/robin/bro/master/testing/btest/.tmp/core.expr-exception/expr-exception.zeek, line 11 #close 2011-03-18-19-06-13 diff --git a/testing/btest/Baseline/core.reporter-error-in-handler/output b/testing/btest/Baseline/core.reporter-error-in-handler/output index 85014657a3..6d46cdaa50 100644 --- a/testing/btest/Baseline/core.reporter-error-in-handler/output +++ b/testing/btest/Baseline/core.reporter-error-in-handler/output @@ -1,3 +1,3 @@ -expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.reporter-error-in-handler/reporter-error-in-handler.zeek, line 28: no such index (a[1]) -expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.reporter-error-in-handler/reporter-error-in-handler.zeek, line 22: no such index (a[2]) +expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.reporter-error-in-handler/reporter-error-in-handler.zeek, line 29: no such index (a[1]) +expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/core.reporter-error-in-handler/reporter-error-in-handler.zeek, line 23: no such index (a[2]) 1st error printed on script level diff --git a/testing/btest/Baseline/core.when-interpreter-exceptions/zeek.output b/testing/btest/Baseline/core.when-interpreter-exceptions/zeek.output index 3abe7bcfd0..50463d99e5 100644 --- a/testing/btest/Baseline/core.when-interpreter-exceptions/zeek.output +++ b/testing/btest/Baseline/core.when-interpreter-exceptions/zeek.output @@ -1,7 +1,7 @@ -expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 47: field value missing (myrecord$notset) -expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 91: field value missing (myrecord$notset) -expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 72: field value missing (myrecord$notset) -expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 103: field value missing (myrecord$notset) +expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 48: field value missing (myrecord$notset) +expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 92: field value missing (myrecord$notset) +expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 73: field value missing (myrecord$notset) +expression error in /Users/jon/Projects/bro/bro/testing/btest/.tmp/core.when-interpreter-exceptions/when-interpreter-exceptions.zeek, line 104: field value missing (myrecord$notset) received termination signal [f(F)] f() done, no exception, T diff --git a/testing/btest/Baseline/language.expire-expr-error/output b/testing/btest/Baseline/language.expire-expr-error/output index 5bc22b8202..7faceb19e0 100644 --- a/testing/btest/Baseline/language.expire-expr-error/output +++ b/testing/btest/Baseline/language.expire-expr-error/output @@ -1,2 +1,2 @@ -expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-expr-error/expire-expr-error.zeek, line 8: no such index (x[kaputt]) +expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-expr-error/expire-expr-error.zeek, line 9: no such index (x[kaputt]) received termination signal diff --git a/testing/btest/Baseline/language.expire-func-undef/output b/testing/btest/Baseline/language.expire-func-undef/output index fb783261be..0d72390ef3 100644 --- a/testing/btest/Baseline/language.expire-func-undef/output +++ b/testing/btest/Baseline/language.expire-func-undef/output @@ -1,20 +1,20 @@ -1299470395.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299470405.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299473995.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299474005.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299477595.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299477605.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299481195.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299481205.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299484795.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299484805.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299488395.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299488405.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299491995.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299492005.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299495595.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299495605.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299499195.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299499205.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) -1299502795.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 12: value used but not set (segfault::scan_summary) +1299470395.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299470405.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299473995.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299474005.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299477595.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299477605.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299481195.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299481205.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299484795.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299484805.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299488395.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299488405.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299491995.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299492005.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299495595.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299495605.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299499195.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299499205.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) +1299502795.000000 expression error in /home/robin/bro/master/testing/btest/.tmp/language.expire-func-undef/expire-func-undef.zeek, line 13: value used but not set (segfault::scan_summary) orig: 10.0.0.2: peers: {\x0a\x0910.0.0.3\x0a} diff --git a/testing/btest/Baseline/language.index-assignment-invalid/out b/testing/btest/Baseline/language.index-assignment-invalid/out index a30ecf891f..1d164cabd9 100644 --- a/testing/btest/Baseline/language.index-assignment-invalid/out +++ b/testing/btest/Baseline/language.index-assignment-invalid/out @@ -1,5 +1,5 @@ runtime error in /home/jon/pro/zeek/zeek/scripts/base/utils/queue.zeek, line 152: vector index assignment failed for invalid type 'myrec', value: [a=T, b=hi, c=], expression: Queue::ret[Queue::j], call stack: - #0 Queue::get_vector([initialized=T, vals={[2] = test,[6] = jkl;,[4] = asdf,[1] = goodbye,[5] = 3,[0] = hello,[3] = [a=T, b=hi, c=]}, settings=[max_len=], top=7, bottom=0, size=0], [hello, goodbye, test]) at /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.zeek:19 - #1 bar(55) at /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.zeek:27 - #2 foo(hi, 13) at /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.zeek:39 + #0 Queue::get_vector([initialized=T, vals={[2] = test,[6] = jkl;,[4] = asdf,[1] = goodbye,[5] = 3,[0] = hello,[3] = [a=T, b=hi, c=]}, settings=[max_len=], top=7, bottom=0, size=0], [hello, goodbye, test]) at /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.zeek:20 + #1 bar(55) at /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.zeek:28 + #2 foo(hi, 13) at /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.zeek:40 #3 zeek_init() diff --git a/testing/btest/Baseline/language.invalid_index/out b/testing/btest/Baseline/language.invalid_index/out index aa3784aa3e..b8d99f7664 100644 --- a/testing/btest/Baseline/language.invalid_index/out +++ b/testing/btest/Baseline/language.invalid_index/out @@ -1,5 +1,5 @@ -expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.invalid_index/invalid_index.zeek, line 10: no such index (foo[1]) -expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.invalid_index/invalid_index.zeek, line 16: no such index (foo2[1]) +expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.invalid_index/invalid_index.zeek, line 11: no such index (foo[1]) +expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.invalid_index/invalid_index.zeek, line 17: no such index (foo2[1]) foo[0], 42 foo2[0], 13 done diff --git a/testing/btest/Baseline/language.type-cast-error-dynamic/output b/testing/btest/Baseline/language.type-cast-error-dynamic/output index dfac361f11..aaf367b3f1 100644 --- a/testing/btest/Baseline/language.type-cast-error-dynamic/output +++ b/testing/btest/Baseline/language.type-cast-error-dynamic/output @@ -1,4 +1,4 @@ -expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.type-cast-error-dynamic/type-cast-error-dynamic.zeek, line 11: invalid cast of value with type 'count' to type 'string' (a as string) -expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.type-cast-error-dynamic/type-cast-error-dynamic.zeek, line 11: invalid cast of value with type 'record { a:addr; b:port; }' to type 'string' (a as string) -expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.type-cast-error-dynamic/type-cast-error-dynamic.zeek, line 11: invalid cast of value with type 'record { data:opaque of Broker::Data; }' to type 'string' (nil $data field) (a as string) +expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.type-cast-error-dynamic/type-cast-error-dynamic.zeek, line 12: invalid cast of value with type 'count' to type 'string' (a as string) +expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.type-cast-error-dynamic/type-cast-error-dynamic.zeek, line 12: invalid cast of value with type 'record { a:addr; b:port; }' to type 'string' (a as string) +expression error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.type-cast-error-dynamic/type-cast-error-dynamic.zeek, line 12: invalid cast of value with type 'record { data:opaque of Broker::Data; }' to type 'string' (nil $data field) (a as string) data is string, F diff --git a/testing/btest/Baseline/language.uninitialized-local2/out b/testing/btest/Baseline/language.uninitialized-local2/out index ba668f08ff..36e9b6bffc 100644 --- a/testing/btest/Baseline/language.uninitialized-local2/out +++ b/testing/btest/Baseline/language.uninitialized-local2/out @@ -1,2 +1,2 @@ -expression error in /home/jon/projects/bro/bro/testing/btest/.tmp/language.uninitialized-local2/uninitialized-local2.zeek, line 19: value used but not set (var_b) +expression error in /home/jon/projects/bro/bro/testing/btest/.tmp/language.uninitialized-local2/uninitialized-local2.zeek, line 20: value used but not set (var_b) var_a is, baz diff --git a/testing/btest/Baseline/plugins.reporter-hook/output b/testing/btest/Baseline/plugins.reporter-hook/output index 36418d2405..99f0b789f9 100644 --- a/testing/btest/Baseline/plugins.reporter-hook/output +++ b/testing/btest/Baseline/plugins.reporter-hook/output @@ -1,10 +1,10 @@ - | Hook Some Info <...>/reporter-hook.zeek, line 16 - | Hook error An Error <...>/reporter-hook.zeek, line 18 - | Hook error An Error that does not show up in the log <...>/reporter-hook.zeek, line 19 - | Hook expression error field value missing (b$a) <...>/reporter-hook.zeek, line 23 - | Hook warning A warning <...>/reporter-hook.zeek, line 17 -<...>/reporter-hook.zeek, line 16: Some Info -error in <...>/reporter-hook.zeek, line 18: An Error -error in <...>/reporter-hook.zeek, line 19: An Error that does not show up in the log -expression error in <...>/reporter-hook.zeek, line 23: field value missing (b$a) -warning in <...>/reporter-hook.zeek, line 17: A warning + | Hook Some Info <...>/reporter-hook.zeek, line 17 + | Hook error An Error <...>/reporter-hook.zeek, line 19 + | Hook error An Error that does not show up in the log <...>/reporter-hook.zeek, line 20 + | Hook expression error field value missing (b$a) <...>/reporter-hook.zeek, line 24 + | Hook warning A warning <...>/reporter-hook.zeek, line 18 +<...>/reporter-hook.zeek, line 17: Some Info +error in <...>/reporter-hook.zeek, line 19: An Error +error in <...>/reporter-hook.zeek, line 20: An Error that does not show up in the log +expression error in <...>/reporter-hook.zeek, line 24: field value missing (b$a) +warning in <...>/reporter-hook.zeek, line 18: A warning diff --git a/testing/btest/Baseline/plugins.reporter-hook/reporter.log b/testing/btest/Baseline/plugins.reporter-hook/reporter.log index fc5a79bc86..acd2200291 100644 --- a/testing/btest/Baseline/plugins.reporter-hook/reporter.log +++ b/testing/btest/Baseline/plugins.reporter-hook/reporter.log @@ -6,8 +6,8 @@ #open 2017-07-26-17-58-52 #fields ts level message location #types time enum string string -0.000000 Reporter::INFO Some Info /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 16 -0.000000 Reporter::WARNING A warning /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 17 -0.000000 Reporter::ERROR An Error /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 18 -0.000000 Reporter::ERROR field value missing (b$a) /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 23 +0.000000 Reporter::INFO Some Info /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 17 +0.000000 Reporter::WARNING A warning /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 18 +0.000000 Reporter::ERROR An Error /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 19 +0.000000 Reporter::ERROR field value missing (b$a) /Users/johanna/corelight/bro/testing/btest/.tmp/plugins.reporter-hook/reporter-hook.zeek, line 24 #close 2017-07-26-17-58-52 diff --git a/testing/btest/Baseline/scripts.base.frameworks.reporter.disable-stderr/reporter.log b/testing/btest/Baseline/scripts.base.frameworks.reporter.disable-stderr/reporter.log index 744f050046..823afde707 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.reporter.disable-stderr/reporter.log +++ b/testing/btest/Baseline/scripts.base.frameworks.reporter.disable-stderr/reporter.log @@ -6,5 +6,5 @@ #open 2012-08-10-20-09-16 #fields ts level message location #types time enum string string -0.000000 Reporter::ERROR no such index (test[3]) /da/home/robin/bro/master/testing/btest/.tmp/scripts.base.frameworks.reporter.disable-stderr/disable-stderr.zeek, line 12 +0.000000 Reporter::ERROR no such index (test[3]) /da/home/robin/bro/master/testing/btest/.tmp/scripts.base.frameworks.reporter.disable-stderr/disable-stderr.zeek, line 13 #close 2012-08-10-20-09-16 diff --git a/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/.stderr b/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/.stderr index b01cfa1e84..bce0629fd3 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/.stderr +++ b/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/.stderr @@ -1 +1 @@ -expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/scripts.base.frameworks.reporter.stderr/stderr.zeek, line 9: no such index (test[3]) +expression error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/scripts.base.frameworks.reporter.stderr/stderr.zeek, line 10: no such index (test[3]) diff --git a/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/reporter.log b/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/reporter.log index 705bb357fa..1c45222ee7 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/reporter.log +++ b/testing/btest/Baseline/scripts.base.frameworks.reporter.stderr/reporter.log @@ -6,5 +6,5 @@ #open 2013-01-18-18-29-30 #fields ts level message location #types time enum string string -0.000000 Reporter::ERROR no such index (test[3]) /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/scripts.base.frameworks.reporter.stderr/stderr.zeek, line 9 +0.000000 Reporter::ERROR no such index (test[3]) /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/scripts.base.frameworks.reporter.stderr/stderr.zeek, line 10 #close 2013-01-18-18-29-30 diff --git a/testing/btest/core/div-by-zero.zeek b/testing/btest/core/div-by-zero.zeek index d1c95db88c..1d0f7013ca 100644 --- a/testing/btest/core/div-by-zero.zeek +++ b/testing/btest/core/div-by-zero.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT >out 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >out 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out event div_int(a: int, b: int) diff --git a/testing/btest/core/expr-exception.zeek b/testing/btest/core/expr-exception.zeek index 79f460b1e4..4cbb4b1c47 100644 --- a/testing/btest/core/expr-exception.zeek +++ b/testing/btest/core/expr-exception.zeek @@ -1,7 +1,8 @@ # Expressions in an event handler that raise interpreter exceptions # shouldn't abort Zeek entirely, but just return from the function body. # -# @TEST-EXEC: zeek -r $TRACES/wikipedia.trace %INPUT >output +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -r $TRACES/wikipedia.trace %INPUT >output # @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps" btest-diff reporter.log # @TEST-EXEC: btest-diff output diff --git a/testing/btest/core/reporter-error-in-handler.zeek b/testing/btest/core/reporter-error-in-handler.zeek index e7de8a1a75..1b13c0ddbe 100644 --- a/testing/btest/core/reporter-error-in-handler.zeek +++ b/testing/btest/core/reporter-error-in-handler.zeek @@ -2,7 +2,8 @@ # This test procudes a recursive error: the error handler is itself broken. Rather # than looping indefinitly, the error inside the handler should reported to stderr. # -# @TEST-EXEC: zeek %INPUT >output 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek %INPUT >output 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output global a: table[count] of count; diff --git a/testing/btest/core/when-interpreter-exceptions.zeek b/testing/btest/core/when-interpreter-exceptions.zeek index 1a713fd1af..2c1a3d879d 100644 --- a/testing/btest/core/when-interpreter-exceptions.zeek +++ b/testing/btest/core/when-interpreter-exceptions.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: btest-bg-run zeek "zeek -b %INPUT >output 2>&1" +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" btest-bg-run zeek "zeek -b %INPUT >output 2>&1" # @TEST-EXEC: btest-bg-wait 15 # @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps | $SCRIPTS/diff-sort" btest-diff zeek/output diff --git a/testing/btest/language/common-mistakes.zeek b/testing/btest/language/common-mistakes.zeek index b829b5315b..6b8701b877 100644 --- a/testing/btest/language/common-mistakes.zeek +++ b/testing/btest/language/common-mistakes.zeek @@ -2,13 +2,14 @@ # handled internally by way of throwing an exception to unwind out # of the current event handler body. -# @TEST-EXEC: zeek -b 1.zeek >1.out 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b 1.zeek >1.out 2>&1 # @TEST-EXEC: btest-diff 1.out -# @TEST-EXEC: zeek -b 2.zeek >2.out 2>&1 +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b 2.zeek >2.out 2>&1 # @TEST-EXEC: btest-diff 2.out -# @TEST-EXEC: zeek -b 3.zeek >3.out 2>&1 +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b 3.zeek >3.out 2>&1 # @TEST-EXEC: btest-diff 3.out @TEST-START-FILE 1.zeek diff --git a/testing/btest/language/copy-cycle.zeek b/testing/btest/language/copy-cycle.zeek index 347affeb40..edda97547c 100644 --- a/testing/btest/language/copy-cycle.zeek +++ b/testing/btest/language/copy-cycle.zeek @@ -1,4 +1,6 @@ -# @TEST-EXEC: zeek -b %INPUT >out +# TODO: There's explicitly a reference cycle being created in this test that +# causes a memory leak, so just disable leak checking. +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >out # @TEST-EXEC: btest-diff out type B: record { diff --git a/testing/btest/language/expire-expr-error.zeek b/testing/btest/language/expire-expr-error.zeek index 5e6f0b4e6f..907d5b8460 100644 --- a/testing/btest/language/expire-expr-error.zeek +++ b/testing/btest/language/expire-expr-error.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT # @TEST-EXEC: cp .stderr output # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output diff --git a/testing/btest/language/expire-func-undef.zeek b/testing/btest/language/expire-func-undef.zeek index 9198edc6c4..dba8f6c873 100644 --- a/testing/btest/language/expire-func-undef.zeek +++ b/testing/btest/language/expire-func-undef.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -r $TRACES/rotation.trace -b %INPUT >output 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -r $TRACES/rotation.trace -b %INPUT >output 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output module segfault; diff --git a/testing/btest/language/index-assignment-invalid.zeek b/testing/btest/language/index-assignment-invalid.zeek index a42c81320b..ad7bc38384 100644 --- a/testing/btest/language/index-assignment-invalid.zeek +++ b/testing/btest/language/index-assignment-invalid.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT >output 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >output 2>&1 # @TEST-EXEC: grep "error" output >output2 # @TEST-EXEC: for i in 1 2 3 4 5; do cat output2 | cut -d'|' -f$i >>out; done # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out diff --git a/testing/btest/language/invalid_index.zeek b/testing/btest/language/invalid_index.zeek index 80f294c68b..e55d691520 100644 --- a/testing/btest/language/invalid_index.zeek +++ b/testing/btest/language/invalid_index.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT >out 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >out 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out global foo: vector of count = { 42 }; diff --git a/testing/btest/language/subnet-errors.zeek b/testing/btest/language/subnet-errors.zeek index 875817c433..4968e381ec 100644 --- a/testing/btest/language/subnet-errors.zeek +++ b/testing/btest/language/subnet-errors.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT >out 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >out 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out event zeek_init() diff --git a/testing/btest/language/type-cast-error-dynamic.zeek b/testing/btest/language/type-cast-error-dynamic.zeek index 1edf9e3d2a..3ae4cfcb6b 100644 --- a/testing/btest/language/type-cast-error-dynamic.zeek +++ b/testing/btest/language/type-cast-error-dynamic.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT >output 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >output 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output type X: record { diff --git a/testing/btest/language/type-coerce-numerics.zeek b/testing/btest/language/type-coerce-numerics.zeek index 996326361b..3e7c919f16 100644 --- a/testing/btest/language/type-coerce-numerics.zeek +++ b/testing/btest/language/type-coerce-numerics.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b first_set.zeek >first_set.out 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b first_set.zeek >first_set.out 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff first_set.out # @TEST-EXEC-FAIL: zeek -b double_convert_failure1.zeek >double_convert_failure1.out 2>&1 diff --git a/testing/btest/language/uninitialized-local2.zeek b/testing/btest/language/uninitialized-local2.zeek index 4b8f0c8275..8d270cc041 100644 --- a/testing/btest/language/uninitialized-local2.zeek +++ b/testing/btest/language/uninitialized-local2.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek -b %INPUT >out 2>&1 +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek -b %INPUT >out 2>&1 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out event test() diff --git a/testing/btest/plugins/reporter-hook.zeek b/testing/btest/plugins/reporter-hook.zeek index 01229b3d49..7d1f2b1093 100644 --- a/testing/btest/plugins/reporter-hook.zeek +++ b/testing/btest/plugins/reporter-hook.zeek @@ -1,7 +1,8 @@ # @TEST-EXEC: ${DIST}/aux/zeek-aux/plugin-support/init-plugin -u . Reporter Hook # @TEST-EXEC: cp -r %DIR/reporter-hook-plugin/* . # @TEST-EXEC: ./configure --zeek-dist=${DIST} && make -# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Reporter::Hook" ZEEK_PLUGIN_PATH=`pwd` zeek -b %INPUT 2>&1 | $SCRIPTS/diff-remove-abspath | sort | uniq >output +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" ZEEK_PLUGIN_ACTIVATE="Reporter::Hook" ZEEK_PLUGIN_PATH=`pwd` zeek -b %INPUT 2>&1 | $SCRIPTS/diff-remove-abspath | sort | uniq >output # @TEST-EXEC: btest-diff output # @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps" btest-diff reporter.log diff --git a/testing/btest/scripts/base/frameworks/reporter/disable-stderr.zeek b/testing/btest/scripts/base/frameworks/reporter/disable-stderr.zeek index 1395f20807..0f1b48bab7 100644 --- a/testing/btest/scripts/base/frameworks/reporter/disable-stderr.zeek +++ b/testing/btest/scripts/base/frameworks/reporter/disable-stderr.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek %INPUT +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek %INPUT # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr # @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps" btest-diff reporter.log diff --git a/testing/btest/scripts/base/frameworks/reporter/stderr.zeek b/testing/btest/scripts/base/frameworks/reporter/stderr.zeek index 5c3793b435..bfbecc206f 100644 --- a/testing/btest/scripts/base/frameworks/reporter/stderr.zeek +++ b/testing/btest/scripts/base/frameworks/reporter/stderr.zeek @@ -1,4 +1,5 @@ -# @TEST-EXEC: zeek %INPUT +# TODO: interpreter exceptions currently may cause memory leaks, so disable leak checks +# @TEST-EXEC: ASAN_OPTIONS="detect_leaks=0" zeek %INPUT # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr # @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps" btest-diff reporter.log From 44d922c4b5e67c32cb8ca87d6f2be5c3e5abdacc Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 1 Jan 2020 12:13:02 -0800 Subject: [PATCH 25/28] Fix reference counting issues related to lambdas/closures For example, circular references between a lambda function the frame it's stored within and/or its closure could cause memory leaks. This also fixes other various reference-count ownership issues that could lead to memory errors. There may still be some potential/undiscovered issues because the "outer ID" finding logic doesn't look quite right as the AST traversal descends within nested lambdas and considers their locals as "outer", but possibly the other logic for locating values in closures or cloning closures just works around that behavior. --- src/Brofiler.cc | 13 ++++++- src/Brofiler.h | 4 +- src/Expr.cc | 7 +++- src/Frame.cc | 89 +++++++++++++++++++++++++++++++++++++++----- src/Frame.h | 34 ++++++++++++++++- src/Func.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++++-- src/Func.h | 16 +++++++- src/Val.cc | 7 +++- src/Var.cc | 85 +++++++++++++++++------------------------- src/Var.h | 5 --- src/parse.y | 2 +- 11 files changed, 283 insertions(+), 78 deletions(-) diff --git a/src/Brofiler.cc b/src/Brofiler.cc index 5080e25f54..5603040786 100644 --- a/src/Brofiler.cc +++ b/src/Brofiler.cc @@ -15,6 +15,17 @@ Brofiler::Brofiler() Brofiler::~Brofiler() { + for ( auto& s : stmts ) + Unref(s); + } + +void Brofiler::AddStmt(Stmt* s) + { + if ( ignoring != 0 ) + return; + + ::Ref(s); + stmts.push_back(s); } bool Brofiler::ReadStats() @@ -109,7 +120,7 @@ bool Brofiler::WriteStats() return false; } - for ( list::const_iterator it = stmts.begin(); + for ( list::const_iterator it = stmts.begin(); it != stmts.end(); ++it ) { ODesc location_info; diff --git a/src/Brofiler.h b/src/Brofiler.h index b9a0a00244..504b6e324f 100644 --- a/src/Brofiler.h +++ b/src/Brofiler.h @@ -38,13 +38,13 @@ public: void IncIgnoreDepth() { ignoring++; } void DecIgnoreDepth() { ignoring--; } - void AddStmt(const Stmt* s) { if ( ignoring == 0 ) stmts.push_back(s); } + void AddStmt(Stmt* s); private: /** * The current, global Brofiler instance creates this list at parse-time. */ - list stmts; + list stmts; /** * Indicates whether new statments will not be considered as part of diff --git a/src/Expr.cc b/src/Expr.cc index 9eba79f02c..f5db8ff0fb 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4339,6 +4339,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, // Install a dummy version of the function globally for use only // when broker provides a closure. + ::Ref(ingredients->body); BroFunc* dummy_func = new BroFunc( ingredients->id, ingredients->body, @@ -4378,6 +4379,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, dummy_func->SetName(my_name.c_str()); Val* v = new Val(dummy_func); + Unref(dummy_func); id->SetVal(v); // id will unref v when its done. id->SetType(ingredients->id->Type()->Ref()); id->SetConst(); @@ -4385,6 +4387,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, Val* LambdaExpr::Eval(Frame* f) const { + ::Ref(ingredients->body); BroFunc* lamb = new BroFunc( ingredients->id, ingredients->body, @@ -4398,7 +4401,9 @@ Val* LambdaExpr::Eval(Frame* f) const // Allows for lookups by the receiver. lamb->SetName(my_name.c_str()); - return new Val(lamb); + auto rval = new Val(lamb); + Unref(lamb); + return rval; } void LambdaExpr::ExprDescribe(ODesc* d) const diff --git a/src/Frame.cc b/src/Frame.cc index f4eb49cbac..249d988b7b 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -31,20 +31,54 @@ Frame::Frame(int arg_size, const BroFunc* func, const val_list* fn_args) Frame::~Frame() { + for ( auto& func : functions_with_closure_frame_reference ) + { + func->StrengthenClosureReference(this); + Unref(func); + } + // Deleting a Frame that is a view is a no-op. Unref(trigger); - Unref(closure); + + if ( ! weak_closure_ref ) + Unref(closure); for ( auto& i : outer_ids ) Unref(i); Release(); + + delete [] weak_refs; } -void Frame::SetElement(int n, Val* v) +void Frame::AddFunctionWithClosureRef(BroFunc* func) { - Unref(frame[n]); + ::Ref(func); + functions_with_closure_frame_reference.emplace_back(func); + } + +void Frame::SetElement(int n, Val* v, bool weak_ref) + { + UnrefElement(n); frame[n] = v; + + if ( weak_ref ) + { + if ( ! weak_refs ) + { + weak_refs = new bool[size]; + + for ( auto i = 0; i < size; ++i ) + weak_refs[i] = false; + } + + weak_refs[n] = true; + } + else + { + if ( weak_refs ) + weak_refs[n] = false; + } } void Frame::SetElement(const ID* id, Val* v) @@ -62,8 +96,15 @@ void Frame::SetElement(const ID* id, Val* v) if ( offset_map.size() ) { auto where = offset_map.find(std::string(id->Name())); + if ( where != offset_map.end() ) - SetElement(where->second, v); + { + // Need to add a Ref to 'v' since the SetElement() for + // id->Offset() below is otherwise responsible for keeping track + // of the implied reference count of the passed-in 'v' argument. + // i.e. if we end up storing it twice, we need an addition Ref. + SetElement(where->second, v->Ref()); + } } SetElement(id->Offset(), v); @@ -92,7 +133,7 @@ void Frame::Reset(int startIdx) { for ( int i = startIdx; i < size; ++i ) { - Unref(frame[i]); + UnrefElement(i); frame[i] = 0; } } @@ -100,7 +141,7 @@ void Frame::Reset(int startIdx) void Frame::Release() { for ( int i = 0; i < size; ++i ) - Unref(frame[i]); + UnrefElement(i); delete [] frame; } @@ -145,7 +186,34 @@ Frame* Frame::Clone() const return other; } -Frame* Frame::SelectiveClone(const id_list& selection) const +static bool val_is_func(Val* v, BroFunc* func) + { + if ( v->Type()->Tag() != TYPE_FUNC ) + return false; + + return v->AsFunc() == func; + } + +static Val* clone_if_not_func(Val** frame, int offset, BroFunc* func, + Frame* other) + { + auto v = frame[offset]; + + if ( ! v ) + return nullptr; + + if ( val_is_func(v, func) ) + { + other->SetElement(offset, v, true); + return v; + } + + auto rval = v->Clone(); + other->SetElement(offset, rval); + return rval; + } + +Frame* Frame::SelectiveClone(const id_list& selection, BroFunc* func) const { if ( selection.length() == 0 ) return nullptr; @@ -171,7 +239,7 @@ Frame* Frame::SelectiveClone(const id_list& selection) const auto where = offset_map.find(std::string(id->Name())); if ( where != offset_map.end() ) { - other->frame[where->second] = frame[where->second]->Clone(); + clone_if_not_func(frame, where->second, func, other); continue; } } @@ -179,7 +247,7 @@ Frame* Frame::SelectiveClone(const id_list& selection) const if ( ! frame[id->Offset()] ) reporter->InternalError("Attempted to clone an id ('%s') with no associated value.", id->Name()); - other->frame[id->Offset()] = frame[id->Offset()]->Clone(); + clone_if_not_func(frame, id->Offset(), func, other); } /** @@ -379,6 +447,7 @@ std::pair Frame::Unserialize(const broker::vector& data) // Frame takes ownership of unref'ing elements in outer_ids rf->outer_ids = std::move(outer_ids); rf->closure = closure; + rf->weak_closure_ref = false; for ( int i = 0; i < frame_size; ++i ) { @@ -437,7 +506,7 @@ void Frame::CaptureClosure(Frame* c, id_list arg_outer_ids) closure = c; if ( closure ) - Ref(closure); + weak_closure_ref = true; /** * Want to capture closures by copy? diff --git a/src/Frame.h b/src/Frame.h index efb1e2c398..133ab45978 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -44,8 +44,11 @@ public: * * @param n the index to set * @param v the value to set it to + * @param weak_ref whether the frame owns the value and should unref + * it upon destruction. Used to break circular references between + * lambda functions and closure frames. */ - void SetElement(int n, Val* v); + void SetElement(int n, Val* v, bool weak_ref = false); /** * Associates *id* and *v* in the frame. Future lookups of @@ -149,7 +152,7 @@ public: * *selection* have been cloned. All other values are made to be * null. */ - Frame* SelectiveClone(const id_list& selection) const; + Frame* SelectiveClone(const id_list& selection, BroFunc* func) const; /** * Serializes the Frame into a Broker representation. @@ -215,8 +218,28 @@ public: void SetDelayed() { delayed = true; } bool HasDelayed() const { return delayed; } + /** + * Track a new function that refers to this frame for use as a closure. + * This frame's destructor will then upgrade that functions reference + * from weak to strong (by making a copy). The initial use of + * weak references prevents unbreakable circular references that + * otherwise cause memory leaks. + */ + void AddFunctionWithClosureRef(BroFunc* func); private: + + /** + * Unrefs the value at offset 'n' frame unless it's a weak reference. + */ + void UnrefElement(int n) + { + if ( weak_refs && weak_refs[n] ) + return; + + Unref(frame[n]); + } + /** Have we captured this id? */ bool IsOuterID(const ID* in) const; @@ -242,8 +265,13 @@ private: /** Associates ID's offsets with values. */ Val** frame; + /** Values that are weakly referenced by the frame. Used to + * prevent circular reference memory leaks in lambda/closures */ + bool* weak_refs = nullptr; + /** The enclosing frame of this frame. */ Frame* closure; + bool weak_closure_ref = false; /** ID's used in this frame from the enclosing frame. */ id_list outer_ids; @@ -268,6 +296,8 @@ private: Trigger* trigger; const CallExpr* call; bool delayed; + + std::vector functions_with_closure_frame_reference; }; /** diff --git a/src/Func.cc b/src/Func.cc index 747029e4f8..fb90e2e3d2 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -132,6 +132,7 @@ Func* Func::DoClone() { // By default, ok just to return a reference. Func does not have any state // that is different across instances. + ::Ref(this); return this; } @@ -286,7 +287,9 @@ BroFunc::~BroFunc() { std::for_each(bodies.begin(), bodies.end(), [](Body& b) { Unref(b.stmts); }); - Unref(closure); + + if ( ! weak_closure_ref ) + Unref(closure); } int BroFunc::IsPure() const @@ -490,14 +493,35 @@ void BroFunc::AddClosure(id_list ids, Frame* f) SetClosureFrame(f); } +bool BroFunc::StrengthenClosureReference(Frame* f) + { + if ( closure != f ) + return false; + + if ( ! weak_closure_ref ) + return false; + + closure = closure->SelectiveClone(outer_ids, this); + weak_closure_ref = false; + return true; + } + void BroFunc::SetClosureFrame(Frame* f) { if ( closure ) reporter->InternalError("Tried to override closure for BroFunc %s.", Name()); + // Have to use weak references initially because otherwise Ref'ing the + // original frame creates a circular reference: the function holds a + // reference to the frame and the frame contains a reference to this + // function value. And we can't just do a shallow clone of the frame + // up front because the closure semantics in Zeek allow mutating + // the outer frame. + closure = f; - Ref(closure); + weak_closure_ref = true; + f->AddFunctionWithClosureRef(this); } bool BroFunc::UpdateClosure(const broker::vector& data) @@ -510,9 +534,10 @@ bool BroFunc::UpdateClosure(const broker::vector& data) if ( new_closure ) new_closure->SetFunction(this); - if ( closure ) + if ( ! weak_closure_ref ) Unref(closure); + weak_closure_ref = false; closure = new_closure; return true; @@ -528,7 +553,8 @@ Func* BroFunc::DoClone() CopyStateInto(other); other->frame_size = frame_size; - other->closure = closure ? closure->SelectiveClone(outer_ids) : nullptr; + other->closure = closure ? closure->SelectiveClone(outer_ids, this) : nullptr; + other->weak_closure_ref = false; other->outer_ids = outer_ids; return other; @@ -811,3 +837,68 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call) return true; } + +// Gets a function's priority from its Scope's attributes. Errors if it sees any +// problems. +static int get_func_priority(const attr_list& attrs) + { + int priority = 0; + + for ( const auto& a : attrs ) + { + if ( a->Tag() == ATTR_DEPRECATED ) + continue; + + if ( a->Tag() != ATTR_PRIORITY ) + { + a->Error("illegal attribute for function body"); + continue; + } + + Val* v = a->AttrExpr()->Eval(0); + if ( ! v ) + { + a->Error("cannot evaluate attribute expression"); + continue; + } + + if ( ! IsIntegral(v->Type()->Tag()) ) + { + a->Error("expression is not of integral type"); + continue; + } + + priority = v->InternalInt(); + } + + return priority; + } + +function_ingredients::function_ingredients(Scope* scope, Stmt* body) + { + frame_size = scope->Length(); + inits = scope->GetInits(); + + this->scope = scope; + ::Ref(this->scope); + id = scope->ScopeID(); + ::Ref(id); + + auto attrs = scope->Attrs(); + + priority = (attrs ? get_func_priority(*attrs) : 0); + this->body = body; + ::Ref(this->body); + } + +function_ingredients::~function_ingredients() + { + Unref(id); + Unref(body); + Unref(scope); + + for ( const auto& i : *inits ) + Unref(i); + + delete inits; + } diff --git a/src/Func.h b/src/Func.h index fc565d61ab..802c4509da 100644 --- a/src/Func.h +++ b/src/Func.h @@ -114,6 +114,12 @@ public: */ bool UpdateClosure(const broker::vector& data); + /** + * If the function's closure is a weak reference to the given frame, + * upgrade to a strong reference of a shallow clone of that frame. + */ + bool StrengthenClosureReference(Frame* f); + /** * Serializes this function's closure. * @@ -154,6 +160,7 @@ private: id_list outer_ids; // The frame the BroFunc was initialized in. Frame* closure = nullptr; + bool weak_closure_ref = false; }; typedef Val* (*built_in_func)(Frame* frame, val_list* args); @@ -192,13 +199,20 @@ struct CallInfo { // Struct that collects all the specifics defining a Func. Used for BroFuncs // with closures. struct function_ingredients { + + // Gathers all of the information from a scope and a function body needed + // to build a function. + function_ingredients(Scope* scope, Stmt* body); + + ~function_ingredients(); + ID* id; Stmt* body; id_list* inits; int frame_size; int priority; Scope* scope; - }; +}; extern vector call_stack; diff --git a/src/Val.cc b/src/Val.cc index 53aecb0bbb..40533ba748 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -120,7 +120,12 @@ Val* Val::DoClone(CloneState* state) // Derived classes are responsible for this. Exception: // Functions and files. There aren't any derived classes. if ( type->Tag() == TYPE_FUNC ) - return new Val(AsFunc()->DoClone()); + { + auto c = AsFunc()->DoClone(); + auto rval = new Val(c); + Unref(c); + return rval; + } if ( type->Tag() == TYPE_FILE ) { diff --git a/src/Var.cc b/src/Var.cc index f7e15041e8..212ee58a54 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -416,13 +416,30 @@ public: : scope(s) { } virtual TraversalCode PreExpr(const Expr*); + virtual TraversalCode PostExpr(const Expr*); Scope* scope; vector outer_id_references; + int lambda_depth = 0; + // Note: think we really ought to toggle this to false to prevent + // considering locals within inner-lambdas as "outer", but other logic + // for "selective cloning" and locating IDs in the closure chain may + // depend on current behavior and also needs to be changed. + bool search_inner_lambdas = true; }; TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) { + if ( expr->Tag() == EXPR_LAMBDA ) + ++lambda_depth; + + if ( lambda_depth > 0 && ! search_inner_lambdas ) + // Don't inspect the bodies of inner lambdas as they will have their + // own traversal to find outer IDs and we don't want to detect + // references to local IDs inside and accidentally treat them as + // "outer" since they can't be found in current scope. + return TC_CONTINUE; + if ( expr->Tag() != EXPR_NAME ) return TC_CONTINUE; @@ -438,45 +455,20 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) return TC_CONTINUE; } -// Gets a function's priority from its Scope's attributes. Errors if it sees any -// problems. -static int get_func_priotity(const attr_list& attrs) +TraversalCode OuterIDBindingFinder::PostExpr(const Expr* expr) { - int priority = 0; - - for ( const auto& a : attrs ) + if ( expr->Tag() == EXPR_LAMBDA ) { - if ( a->Tag() == ATTR_DEPRECATED ) - continue; - - if ( a->Tag() != ATTR_PRIORITY ) - { - a->Error("illegal attribute for function body"); - continue; - } - - Val* v = a->AttrExpr()->Eval(0); - if ( ! v ) - { - a->Error("cannot evaluate attribute expression"); - continue; - } - - if ( ! IsIntegral(v->Type()->Tag()) ) - { - a->Error("expression is not of integral type"); - continue; - } - - priority = v->InternalInt(); + --lambda_depth; + assert(lambda_depth >= 0); } - return priority; + return TC_CONTINUE; } void end_func(Stmt* body) { - std::unique_ptr ingredients = gather_function_ingredients(pop_scope(), body); + auto ingredients = std::make_unique(pop_scope(), body); if ( streq(ingredients->id->Name(), "anonymous-function") ) { @@ -508,24 +500,10 @@ void end_func(Stmt* body) } ingredients->id->ID_Val()->AsFunc()->SetScope(ingredients->scope); - } - -std::unique_ptr gather_function_ingredients(Scope* scope, Stmt* body) - { - auto ingredients = std::make_unique(); - - ingredients->frame_size = scope->Length(); - ingredients->inits = scope->GetInits(); - - ingredients->scope = scope; - ingredients->id = scope->ScopeID(); - - auto attrs = scope->Attrs(); - - ingredients->priority = (attrs ? get_func_priotity(*attrs) : 0); - ingredients->body = body; - - return ingredients; + // Note: ideally, something would take ownership of this memory until the + // end of script execution, but that's essentially the same as the + // lifetime of the process at the moment, so ok to "leak" it. + ingredients.release(); } Val* internal_val(const char* name) @@ -548,7 +526,14 @@ id_list gather_outer_ids(Scope* scope, Stmt* body) id_list idl ( cb.outer_id_references.size() ); for ( size_t i = 0; i < cb.outer_id_references.size(); ++i ) - idl.append(cb.outer_id_references[i]->Id()); + { + auto id = cb.outer_id_references[i]->Id(); + + if ( idl.is_member(id) ) + continue; + + idl.append(id); + } return idl; } diff --git a/src/Var.h b/src/Var.h index f90250a3b1..5ae6720b62 100644 --- a/src/Var.h +++ b/src/Var.h @@ -26,11 +26,6 @@ extern void begin_func(ID* id, const char* module_name, function_flavor flavor, int is_redef, FuncType* t, attr_list* attrs = nullptr); extern void end_func(Stmt* body); -// Gathers all of the information from a scope and a function body needed to -// build a function and collects it into a function_ingredients struct. -// Gathered elements are not refeed. -extern std::unique_ptr gather_function_ingredients(Scope* scope, Stmt* body); - // Gather all IDs referenced inside a body that aren't part of a given scope. extern id_list gather_outer_ids(Scope* scope, Stmt* body); diff --git a/src/parse.y b/src/parse.y index 6e8b4dc327..c409942cca 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1234,7 +1234,7 @@ anonymous_function: // a lambda expression. // Gather the ingredients for a BroFunc from the current scope - std::unique_ptr ingredients = gather_function_ingredients(current_scope(), $5); + auto ingredients = std::make_unique(current_scope(), $5); id_list outer_ids = gather_outer_ids(pop_scope(), $5); $$ = new LambdaExpr(std::move(ingredients), std::move(outer_ids)); From e6f4e01041aad2565cb08e82d5c9c9769dfad718 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 1 Jan 2020 14:29:31 -0800 Subject: [PATCH 26/28] Remove redundant memory leak btests Or otherwise convert into a regular btest if it didn't already seem to be covered. There's no need for a separate memory leak test group since compiling with LeakSanitizer now covers leak checking for the full btest suite. --- .../manager-1..stdout | 0 .../worker-1..stdout | 0 .../worker-2..stdout | 0 .../manager-1.metrics.log | 12 - .../clone.clone.out | 24 -- .../core.leaks.broker.data/zeek..stdout | 120 ------- .../recv.recv.out | 6 - .../send.send.out | 11 - .../recv.recv.out | 0 .../recv.test.log | 15 - .../send.send.out | 1 - .../send.test.log | 15 - .../core.leaks.closure-sending/recv.recv.out | 26 -- .../core.leaks.closure-sending/send.send.out | 31 -- .../scripts.base.protocols.irc.basic/out | 58 ++++ .../conn.log | 10 + .../kerberos.log | 10 + .../{core/leaks => bifs}/hll_cluster.zeek | 15 +- testing/btest/core/leaks/ayiya.test | 8 - testing/btest/core/leaks/basic-cluster.zeek | 90 ------ testing/btest/core/leaks/bloomfilter.zeek | 101 ------ .../btest/core/leaks/broker/clone_store.zeek | 144 --------- testing/btest/core/leaks/broker/data.zeek | 270 ---------------- .../btest/core/leaks/broker/master_store.zeek | 149 --------- .../btest/core/leaks/broker/remote_event.test | 85 ----- .../btest/core/leaks/broker/remote_log.test | 88 ------ testing/btest/core/leaks/closure-sending.zeek | 168 ---------- .../btest/core/leaks/copy-all-opaques.zeek | 90 ------ testing/btest/core/leaks/copy-all-types.zeek | 196 ------------ testing/btest/core/leaks/dns-nsec3.zeek | 40 --- testing/btest/core/leaks/dns-txt.zeek | 42 --- testing/btest/core/leaks/dns.zeek | 81 ----- testing/btest/core/leaks/dtls.zeek | 15 - testing/btest/core/leaks/exec.test | 79 ----- .../core/leaks/file-analysis-http-get.zeek | 15 - .../btest/core/leaks/function-closures.zeek | 107 ------- testing/btest/core/leaks/gridftp.test | 25 -- testing/btest/core/leaks/gtp_opt_header.test | 16 - testing/btest/core/leaks/hook.zeek | 101 ------ testing/btest/core/leaks/http-connect.zeek | 14 - testing/btest/core/leaks/incr-vec-expr.test | 36 --- testing/btest/core/leaks/input-basic.zeek | 67 ---- testing/btest/core/leaks/input-errors.zeek | 196 ------------ .../btest/core/leaks/input-missing-enum.zeek | 41 --- .../core/leaks/input-optional-event.zeek | 65 ---- .../core/leaks/input-optional-table.zeek | 68 ---- testing/btest/core/leaks/input-patterns.zeek | 52 --- testing/btest/core/leaks/input-raw.zeek | 72 ----- testing/btest/core/leaks/input-reread.zeek | 164 ---------- testing/btest/core/leaks/input-sqlite.zeek | 105 ------ .../btest/core/leaks/input-with-remove.zeek | 63 ---- testing/btest/core/leaks/ip-in-ip.test | 33 -- .../btest/core/leaks/ipv6_ext_headers.test | 37 --- testing/btest/core/leaks/irc.test | 13 - .../btest/core/leaks/krb-service-name.test | 8 - testing/btest/core/leaks/krb.test | 10 - testing/btest/core/leaks/kv-iteration.zeek | 22 -- testing/btest/core/leaks/mysql.test | 10 - testing/btest/core/leaks/paraglob.zeek | 34 -- testing/btest/core/leaks/pattern.zeek | 67 ---- testing/btest/core/leaks/pe.test | 12 - testing/btest/core/leaks/print-log.zeek | 14 - testing/btest/core/leaks/radius.test | 10 - testing/btest/core/leaks/returnwhen.zeek | 84 ----- testing/btest/core/leaks/set.zeek | 194 ------------ testing/btest/core/leaks/sip.test | 10 - testing/btest/core/leaks/smtp_attachment.test | 10 - testing/btest/core/leaks/snmp.test | 10 - testing/btest/core/leaks/ssh.test | 10 - testing/btest/core/leaks/stats.zeek | 15 - testing/btest/core/leaks/string-indexing.zeek | 27 -- .../btest/core/leaks/switch-statement.zeek | 299 ------------------ testing/btest/core/leaks/teredo.zeek | 38 --- testing/btest/core/leaks/test-all.zeek | 8 - testing/btest/core/leaks/to_json.zeek | 140 -------- testing/btest/core/leaks/vector-indexing.zeek | 30 -- testing/btest/core/leaks/vector-val-bifs.test | 28 -- testing/btest/core/leaks/while.zeek | 80 ----- .../btest/core/leaks/x509_ocsp_verify.zeek | 19 -- testing/btest/core/leaks/x509_verify.zeek | 33 -- .../scripts/base/protocols/irc/basic.test | 8 +- .../base/protocols/krb/krb-service-name.test | 3 + testing/btest/scripts/policy/misc/stats.zeek | 10 + testing/external/commit-hash.zeek-testing | 2 +- .../external/commit-hash.zeek-testing-private | 2 +- 85 files changed, 105 insertions(+), 4432 deletions(-) rename testing/btest/Baseline/{core.leaks.hll_cluster => bifs.hll_cluster}/manager-1..stdout (100%) rename testing/btest/Baseline/{core.leaks.hll_cluster => bifs.hll_cluster}/worker-1..stdout (100%) rename testing/btest/Baseline/{core.leaks.hll_cluster => bifs.hll_cluster}/worker-2..stdout (100%) delete mode 100644 testing/btest/Baseline/core.leaks.basic-cluster/manager-1.metrics.log delete mode 100644 testing/btest/Baseline/core.leaks.broker.clone_store/clone.clone.out delete mode 100644 testing/btest/Baseline/core.leaks.broker.data/zeek..stdout delete mode 100644 testing/btest/Baseline/core.leaks.broker.remote_event/recv.recv.out delete mode 100644 testing/btest/Baseline/core.leaks.broker.remote_event/send.send.out delete mode 100644 testing/btest/Baseline/core.leaks.broker.remote_log/recv.recv.out delete mode 100644 testing/btest/Baseline/core.leaks.broker.remote_log/recv.test.log delete mode 100644 testing/btest/Baseline/core.leaks.broker.remote_log/send.send.out delete mode 100644 testing/btest/Baseline/core.leaks.broker.remote_log/send.test.log delete mode 100644 testing/btest/Baseline/core.leaks.closure-sending/recv.recv.out delete mode 100644 testing/btest/Baseline/core.leaks.closure-sending/send.send.out create mode 100644 testing/btest/Baseline/scripts.base.protocols.irc.basic/out create mode 100644 testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/conn.log create mode 100644 testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/kerberos.log rename testing/btest/{core/leaks => bifs}/hll_cluster.zeek (80%) delete mode 100644 testing/btest/core/leaks/ayiya.test delete mode 100644 testing/btest/core/leaks/basic-cluster.zeek delete mode 100644 testing/btest/core/leaks/bloomfilter.zeek delete mode 100644 testing/btest/core/leaks/broker/clone_store.zeek delete mode 100644 testing/btest/core/leaks/broker/data.zeek delete mode 100644 testing/btest/core/leaks/broker/master_store.zeek delete mode 100644 testing/btest/core/leaks/broker/remote_event.test delete mode 100644 testing/btest/core/leaks/broker/remote_log.test delete mode 100644 testing/btest/core/leaks/closure-sending.zeek delete mode 100644 testing/btest/core/leaks/copy-all-opaques.zeek delete mode 100644 testing/btest/core/leaks/copy-all-types.zeek delete mode 100644 testing/btest/core/leaks/dns-nsec3.zeek delete mode 100644 testing/btest/core/leaks/dns-txt.zeek delete mode 100644 testing/btest/core/leaks/dns.zeek delete mode 100644 testing/btest/core/leaks/dtls.zeek delete mode 100644 testing/btest/core/leaks/exec.test delete mode 100644 testing/btest/core/leaks/file-analysis-http-get.zeek delete mode 100644 testing/btest/core/leaks/function-closures.zeek delete mode 100644 testing/btest/core/leaks/gridftp.test delete mode 100644 testing/btest/core/leaks/gtp_opt_header.test delete mode 100644 testing/btest/core/leaks/hook.zeek delete mode 100644 testing/btest/core/leaks/http-connect.zeek delete mode 100644 testing/btest/core/leaks/incr-vec-expr.test delete mode 100644 testing/btest/core/leaks/input-basic.zeek delete mode 100644 testing/btest/core/leaks/input-errors.zeek delete mode 100644 testing/btest/core/leaks/input-missing-enum.zeek delete mode 100644 testing/btest/core/leaks/input-optional-event.zeek delete mode 100644 testing/btest/core/leaks/input-optional-table.zeek delete mode 100644 testing/btest/core/leaks/input-patterns.zeek delete mode 100644 testing/btest/core/leaks/input-raw.zeek delete mode 100644 testing/btest/core/leaks/input-reread.zeek delete mode 100644 testing/btest/core/leaks/input-sqlite.zeek delete mode 100644 testing/btest/core/leaks/input-with-remove.zeek delete mode 100644 testing/btest/core/leaks/ip-in-ip.test delete mode 100644 testing/btest/core/leaks/ipv6_ext_headers.test delete mode 100644 testing/btest/core/leaks/irc.test delete mode 100644 testing/btest/core/leaks/krb-service-name.test delete mode 100644 testing/btest/core/leaks/krb.test delete mode 100644 testing/btest/core/leaks/kv-iteration.zeek delete mode 100644 testing/btest/core/leaks/mysql.test delete mode 100644 testing/btest/core/leaks/paraglob.zeek delete mode 100644 testing/btest/core/leaks/pattern.zeek delete mode 100644 testing/btest/core/leaks/pe.test delete mode 100644 testing/btest/core/leaks/print-log.zeek delete mode 100644 testing/btest/core/leaks/radius.test delete mode 100644 testing/btest/core/leaks/returnwhen.zeek delete mode 100644 testing/btest/core/leaks/set.zeek delete mode 100644 testing/btest/core/leaks/sip.test delete mode 100644 testing/btest/core/leaks/smtp_attachment.test delete mode 100644 testing/btest/core/leaks/snmp.test delete mode 100644 testing/btest/core/leaks/ssh.test delete mode 100644 testing/btest/core/leaks/stats.zeek delete mode 100644 testing/btest/core/leaks/string-indexing.zeek delete mode 100644 testing/btest/core/leaks/switch-statement.zeek delete mode 100644 testing/btest/core/leaks/teredo.zeek delete mode 100644 testing/btest/core/leaks/test-all.zeek delete mode 100644 testing/btest/core/leaks/to_json.zeek delete mode 100644 testing/btest/core/leaks/vector-indexing.zeek delete mode 100644 testing/btest/core/leaks/vector-val-bifs.test delete mode 100644 testing/btest/core/leaks/while.zeek delete mode 100644 testing/btest/core/leaks/x509_ocsp_verify.zeek delete mode 100644 testing/btest/core/leaks/x509_verify.zeek create mode 100644 testing/btest/scripts/base/protocols/krb/krb-service-name.test create mode 100644 testing/btest/scripts/policy/misc/stats.zeek diff --git a/testing/btest/Baseline/core.leaks.hll_cluster/manager-1..stdout b/testing/btest/Baseline/bifs.hll_cluster/manager-1..stdout similarity index 100% rename from testing/btest/Baseline/core.leaks.hll_cluster/manager-1..stdout rename to testing/btest/Baseline/bifs.hll_cluster/manager-1..stdout diff --git a/testing/btest/Baseline/core.leaks.hll_cluster/worker-1..stdout b/testing/btest/Baseline/bifs.hll_cluster/worker-1..stdout similarity index 100% rename from testing/btest/Baseline/core.leaks.hll_cluster/worker-1..stdout rename to testing/btest/Baseline/bifs.hll_cluster/worker-1..stdout diff --git a/testing/btest/Baseline/core.leaks.hll_cluster/worker-2..stdout b/testing/btest/Baseline/bifs.hll_cluster/worker-2..stdout similarity index 100% rename from testing/btest/Baseline/core.leaks.hll_cluster/worker-2..stdout rename to testing/btest/Baseline/bifs.hll_cluster/worker-2..stdout diff --git a/testing/btest/Baseline/core.leaks.basic-cluster/manager-1.metrics.log b/testing/btest/Baseline/core.leaks.basic-cluster/manager-1.metrics.log deleted file mode 100644 index cb1bd5af01..0000000000 --- a/testing/btest/Baseline/core.leaks.basic-cluster/manager-1.metrics.log +++ /dev/null @@ -1,12 +0,0 @@ -#separator \x09 -#set_separator , -#empty_field (empty) -#unset_field - -#path metrics -#open 2012-07-20-01-50-41 -#fields ts metric_id filter_name index.host index.str index.network value -#types time enum string addr string subnet count -1342749041.601712 TEST_METRIC foo-bar 6.5.4.3 - - 4 -1342749041.601712 TEST_METRIC foo-bar 7.2.1.5 - - 2 -1342749041.601712 TEST_METRIC foo-bar 1.2.3.4 - - 6 -#close 2012-07-20-01-50-49 diff --git a/testing/btest/Baseline/core.leaks.broker.clone_store/clone.clone.out b/testing/btest/Baseline/core.leaks.broker.clone_store/clone.clone.out deleted file mode 100644 index 9ae8d91491..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.clone_store/clone.clone.out +++ /dev/null @@ -1,24 +0,0 @@ ----- -clone, one, Broker::SUCCESS, [data=broker::data{110}] -clone, two, Broker::SUCCESS, [data=broker::data{223}] -clone, [1, 2], Broker::SUCCESS, [data=broker::data{1947/tcp}] -clone, three, Broker::FAILURE, [data=] -clone, four, Broker::FAILURE, [data=] -clone, five, Broker::FAILURE, [data=] -clone, six, Broker::FAILURE, [data=] ----- -clone, one, Broker::SUCCESS, [data=broker::data{110}] -clone, two, Broker::SUCCESS, [data=broker::data{223}] -clone, [1, 2], Broker::SUCCESS, [data=broker::data{1947/tcp}] -clone, three, Broker::SUCCESS, [data=broker::data{3.140000}] -clone, four, Broker::SUCCESS, [data=broker::data{1.2.3.4}] -clone, five, Broker::FAILURE, [data=] -clone, six, Broker::FAILURE, [data=] ----- -clone, one, Broker::SUCCESS, [data=broker::data{110}] -clone, two, Broker::SUCCESS, [data=broker::data{223}] -clone, [1, 2], Broker::SUCCESS, [data=broker::data{1947/tcp}] -clone, three, Broker::SUCCESS, [data=broker::data{3.140000}] -clone, four, Broker::FAILURE, [data=] -clone, five, Broker::SUCCESS, [data=broker::data{555}] -clone, six, Broker::SUCCESS, [data=broker::data{666}] diff --git a/testing/btest/Baseline/core.leaks.broker.data/zeek..stdout b/testing/btest/Baseline/core.leaks.broker.data/zeek..stdout deleted file mode 100644 index 033e8af5f2..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.data/zeek..stdout +++ /dev/null @@ -1,120 +0,0 @@ -Broker::BOOL -Broker::INT -Broker::COUNT -Broker::DOUBLE -Broker::STRING -Broker::ADDR -Broker::SUBNET -Broker::PORT -Broker::TIME -Broker::INTERVAL -Broker::ENUM -Broker::SET -Broker::TABLE -Broker::VECTOR -Broker::VECTOR -*************************** -T -F -1 -0 --1 -1 -0 -1.1 --11.1 -hello -1.2.3.4 -192.168.0.0/16 -22/tcp -42.0 -180.0 -Broker::BOOL -{ -two, -one, -three -} -{ -[two] = 2, -[one] = 1, -[three] = 3 -} -[zero, one, two] -[a=, b=bee, c=1] -[a=test, b=bee, c=1] -[a=test, b=testagain, c=1] -*************************** -0 -T -1 -T -F -T -2 -F -2 -T -1 -F -{ -bye -} -T -0 -{ - -} -*************************** -0 -[data=] -1 -T -42 -F -[data=] -2 -[data=broker::data{7}] -2 -37 -[data=broker::data{42}] -1 -[data=] -1 -T -0 -{ - -} -*************************** -0 -T -T -T -T -[hi, salutations, hello, greetings] -4 -[data=broker::data{hello}] -[data=broker::data{bah}] -[data=broker::data{hi}] -[hi, salutations, bah, greetings] -[data=broker::data{bah}] -[hi, salutations, greetings] -3 -T -0 -[] -*************************** -3 -T -T -T -[data=broker::data{hi}] -[data=broker::data{hello}] -[data=broker::data{37}] -3 -T -3 -[data=broker::data{goodbye}] -*************************** -T diff --git a/testing/btest/Baseline/core.leaks.broker.remote_event/recv.recv.out b/testing/btest/Baseline/core.leaks.broker.remote_event/recv.recv.out deleted file mode 100644 index 7dab0284ea..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.remote_event/recv.recv.out +++ /dev/null @@ -1,6 +0,0 @@ -got event msg, ping, 0 -got event msg, ping, 1 -got event msg, ping, 2 -got event msg, ping, 3 -got event msg, ping, 4 -got event msg, ping, 5 diff --git a/testing/btest/Baseline/core.leaks.broker.remote_event/send.send.out b/testing/btest/Baseline/core.leaks.broker.remote_event/send.send.out deleted file mode 100644 index 7446e7ac5d..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.remote_event/send.send.out +++ /dev/null @@ -1,11 +0,0 @@ -Broker peer added, 127.0.0.1 -got event msg, pong, 0 -got auto event msg, ping, 0 -got event msg, pong, 1 -got auto event msg, ping, 1 -got event msg, pong, 2 -got auto event msg, ping, 2 -got event msg, pong, 3 -got auto event msg, ping, 3 -got event msg, pong, 4 -got auto event msg, ping, 4 diff --git a/testing/btest/Baseline/core.leaks.broker.remote_log/recv.recv.out b/testing/btest/Baseline/core.leaks.broker.remote_log/recv.recv.out deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/testing/btest/Baseline/core.leaks.broker.remote_log/recv.test.log b/testing/btest/Baseline/core.leaks.broker.remote_log/recv.test.log deleted file mode 100644 index f0f279a626..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.remote_log/recv.test.log +++ /dev/null @@ -1,15 +0,0 @@ -#separator \x09 -#set_separator , -#empty_field (empty) -#unset_field - -#path test -#open 2017-04-26-01-04-25 -#fields msg num -#types string count -ping 0 -ping 1 -ping 2 -ping 3 -ping 4 -ping 5 -#close 2017-04-26-01-04-26 diff --git a/testing/btest/Baseline/core.leaks.broker.remote_log/send.send.out b/testing/btest/Baseline/core.leaks.broker.remote_log/send.send.out deleted file mode 100644 index b467bc6375..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.remote_log/send.send.out +++ /dev/null @@ -1 +0,0 @@ -Broker peer added, 127.0.0.1 diff --git a/testing/btest/Baseline/core.leaks.broker.remote_log/send.test.log b/testing/btest/Baseline/core.leaks.broker.remote_log/send.test.log deleted file mode 100644 index f0f279a626..0000000000 --- a/testing/btest/Baseline/core.leaks.broker.remote_log/send.test.log +++ /dev/null @@ -1,15 +0,0 @@ -#separator \x09 -#set_separator , -#empty_field (empty) -#unset_field - -#path test -#open 2017-04-26-01-04-25 -#fields msg num -#types string count -ping 0 -ping 1 -ping 2 -ping 3 -ping 4 -ping 5 -#close 2017-04-26-01-04-26 diff --git a/testing/btest/Baseline/core.leaks.closure-sending/recv.recv.out b/testing/btest/Baseline/core.leaks.closure-sending/recv.recv.out deleted file mode 100644 index a4d7269e39..0000000000 --- a/testing/btest/Baseline/core.leaks.closure-sending/recv.recv.out +++ /dev/null @@ -1,26 +0,0 @@ -hello :-) -peer added -receiver got ping: function 2 -inside: 1 | outside: 11 | global: 100 -77 -receiver got ping: function 1 -begin: 100 | base_step: 2 -begin: 100 | base_step: 2 | step: 76 -178 -receiver got ping: function 2 -inside: 3 | outside: 11 | global: 100 -79 -receiver got ping: function 1 -begin: 100 | base_step: 4 -begin: 100 | base_step: 4 | step: 76 -180 -receiver got ping: function 2 -inside: 5 | outside: 11 | global: 100 -81 -receiver got ping: function 1 -begin: 100 | base_step: 6 -begin: 100 | base_step: 6 | step: 76 -182 -receiver got ping: function 2 -inside: 7 | outside: 11 | global: 100 -83 diff --git a/testing/btest/Baseline/core.leaks.closure-sending/send.send.out b/testing/btest/Baseline/core.leaks.closure-sending/send.send.out deleted file mode 100644 index 3ff9a31aa4..0000000000 --- a/testing/btest/Baseline/core.leaks.closure-sending/send.send.out +++ /dev/null @@ -1,31 +0,0 @@ -hello :) -peer added -begin: 100 | base_step: 50 -sender got pong: function 2 -inside: 1 | outside: 11 | global: 10 -77 -begin: 100 | base_step: 50 -sender got pong: function 1 -begin: 178 | base_step: 2 -begin: 178 | base_step: 2 | step: 76 -256 -begin: 100 | base_step: 50 -sender got pong: function 2 -inside: 3 | outside: 11 | global: 10 -79 -begin: 100 | base_step: 50 -sender got pong: function 1 -begin: 180 | base_step: 4 -begin: 180 | base_step: 4 | step: 76 -260 -begin: 100 | base_step: 50 -sender got pong: function 2 -inside: 5 | outside: 11 | global: 10 -81 -begin: 100 | base_step: 50 -sender got pong: function 1 -begin: 182 | base_step: 6 -begin: 182 | base_step: 6 | step: 76 -264 -begin: 100 | base_step: 50 -peer lost diff --git a/testing/btest/Baseline/scripts.base.protocols.irc.basic/out b/testing/btest/Baseline/scripts.base.protocols.irc.basic/out new file mode 100644 index 0000000000..0c5e8030aa --- /dev/null +++ b/testing/btest/Baseline/scripts.base.protocols.irc.basic/out @@ -0,0 +1,58 @@ +irc_names_info, #easymovies, { +WhatmeWor, +starred, +fvlkni, +NeverServe, +zgdB8_VzO, ++TrEeHoUsE, +zEmm, +dezmond411, +mikejo1, +freeeman33, +aJerk, ++Luccutis, +jafafar, +|EasyMovie|, +cguide, +skillZ, ++i-am-mojo, +mo5, ++Xedrethor, +kitts, +macbeth420, +Picard, +`Xenu, ++gordon1`^, +N2Oblivion, +scum, +bloed, +katniss, +GordonCamero, ++Max_Renn, +mzazzali, +Verge, +bouleemil, +eag, ++`AngelnTx, ++Killazherb, +gasman2, +HagBard, +wanker, +habzels, +ericdraven, +nofire, ++thenagualII, +bga, +friida, ++ladyvampress, +tonysaunt, +Peebo, +slickrick2 +} +irc_names_info, #easymovies, { +dx3d51, +TinCan, +Nachos, +Latika, +TooFast +} diff --git a/testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/conn.log b/testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/conn.log new file mode 100644 index 0000000000..069ad7c9e8 --- /dev/null +++ b/testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/conn.log @@ -0,0 +1,10 @@ +#separator \x09 +#set_separator , +#empty_field (empty) +#unset_field - +#path conn +#open 2020-01-01-22-01-07 +#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p proto service duration orig_bytes resp_bytes conn_state local_orig local_resp missed_bytes history orig_pkts orig_ip_bytes resp_pkts resp_ip_bytes tunnel_parents +#types time string addr port addr port enum string interval count count string bool bool count string count count count count set[string] +1331918844.980000 CHhAvVGS1DHFjwGM9 192.168.202.110 43792 192.168.229.251 88 tcp krb_tcp 0.010000 110 90 S1 - - 0 ^hADd 2 214 2 206 - +#close 2020-01-01-22-01-07 diff --git a/testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/kerberos.log b/testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/kerberos.log new file mode 100644 index 0000000000..c04aa04da0 --- /dev/null +++ b/testing/btest/Baseline/scripts.base.protocols.krb.krb-service-name/kerberos.log @@ -0,0 +1,10 @@ +#separator \x09 +#set_separator , +#empty_field (empty) +#unset_field - +#path kerberos +#open 2020-01-01-22-01-07 +#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p request_type client service success error_msg from till cipher forwardable renewable client_cert_subject client_cert_fuid server_cert_subject server_cert_fuid +#types time string addr port addr port string string string bool string time time string bool bool string string string string +1331918844.990000 CHhAvVGS1DHFjwGM9 192.168.202.110 43792 192.168.229.251 88 AS /kerberos_realm_time.nasl krbtgt/HEC.NET F KRB_ERR_GENERIC - 2136422885.000000 - T F - - - - +#close 2020-01-01-22-01-07 diff --git a/testing/btest/core/leaks/hll_cluster.zeek b/testing/btest/bifs/hll_cluster.zeek similarity index 80% rename from testing/btest/core/leaks/hll_cluster.zeek rename to testing/btest/bifs/hll_cluster.zeek index 90379fffa4..c0fcb92da5 100644 --- a/testing/btest/core/leaks/hll_cluster.zeek +++ b/testing/btest/bifs/hll_cluster.zeek @@ -1,17 +1,12 @@ -# Needs perftools support. -# # @TEST-PORT: BROKER_PORT1 # @TEST-PORT: BROKER_PORT2 # @TEST-PORT: BROKER_PORT3 -# @TEST-GROUP: leaks # -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: zeek -m %INPUT>out -# @TEST-EXEC: btest-bg-run manager-1 HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -m %INPUT -# @TEST-EXEC: btest-bg-run worker-1 HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-1 zeek -m runnumber=1 %INPUT -# @TEST-EXEC: btest-bg-run worker-2 HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-2 zeek -m runnumber=2 %INPUT -# @TEST-EXEC: btest-bg-wait 120 +# @TEST-EXEC: zeek %INPUT>out +# @TEST-EXEC: btest-bg-run manager-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek %INPUT +# @TEST-EXEC: btest-bg-run worker-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-1 zeek runnumber=1 %INPUT +# @TEST-EXEC: btest-bg-run worker-2 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-2 zeek runnumber=2 %INPUT +# @TEST-EXEC: btest-bg-wait 30 # # @TEST-EXEC: btest-diff manager-1/.stdout # @TEST-EXEC: btest-diff worker-1/.stdout diff --git a/testing/btest/core/leaks/ayiya.test b/testing/btest/core/leaks/ayiya.test deleted file mode 100644 index 6aa1d5be24..0000000000 --- a/testing/btest/core/leaks/ayiya.test +++ /dev/null @@ -1,8 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/tunnels/ayiya3.trace -# @TEST-EXEC: btest-bg-wait 90 diff --git a/testing/btest/core/leaks/basic-cluster.zeek b/testing/btest/core/leaks/basic-cluster.zeek deleted file mode 100644 index eb1ce6c23e..0000000000 --- a/testing/btest/core/leaks/basic-cluster.zeek +++ /dev/null @@ -1,90 +0,0 @@ -# Needs perftools support. -# -# @TEST-PORT: BROKER_PORT1 -# @TEST-PORT: BROKER_PORT2 -# @TEST-PORT: BROKER_PORT3 -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: btest-bg-run manager-1 HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -m %INPUT -# @TEST-EXEC: btest-bg-run worker-1 HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-1 zeek -m %INPUT -# @TEST-EXEC: btest-bg-run worker-2 HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-2 zeek -m %INPUT -# @TEST-EXEC: btest-bg-wait 120 - -@TEST-START-FILE cluster-layout.zeek -redef Cluster::nodes = { - ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1", $interface="eth0"], - ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1", $interface="eth1"], -}; -@TEST-END-FILE - -redef Log::default_rotation_interval = 0secs; - -global n = 0; - -event zeek_init() &priority=5 - { - local r1: SumStats::Reducer = [$stream="test", $apply=set(SumStats::SUM, SumStats::MIN, SumStats::MAX, SumStats::AVERAGE, SumStats::STD_DEV, SumStats::VARIANCE, SumStats::UNIQUE)]; - SumStats::create([$name="test", - $epoch=5secs, - $reducers=set(r1), - $epoch_result(ts: time, key: SumStats::Key, result: SumStats::Result) = - { - local r = result["test"]; - print fmt("Host: %s - num:%d - sum:%.1f - avg:%.1f - max:%.1f - min:%.1f - var:%.1f - std_dev:%.1f - unique:%d", key$host, r$num, r$sum, r$average, r$max, r$min, r$variance, r$std_dev, r$unique); - }, - $epoch_finished(ts: time) = - { - terminate(); - }]); - } - -event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) - { - terminate(); - } - -global ready_for_data: event(); - -event zeek_init() - { - Broker::auto_publish(Cluster::worker_topic, ready_for_data); - } - -event ready_for_data() - { - if ( Cluster::node == "worker-1" ) - { - SumStats::observe("test", [$host=1.2.3.4], [$num=34]); - SumStats::observe("test", [$host=1.2.3.4], [$num=30]); - SumStats::observe("test", [$host=6.5.4.3], [$num=1]); - SumStats::observe("test", [$host=7.2.1.5], [$num=54]); - } - if ( Cluster::node == "worker-2" ) - { - SumStats::observe("test", [$host=1.2.3.4], [$num=75]); - SumStats::observe("test", [$host=1.2.3.4], [$num=30]); - SumStats::observe("test", [$host=1.2.3.4], [$num=3]); - SumStats::observe("test", [$host=1.2.3.4], [$num=57]); - SumStats::observe("test", [$host=1.2.3.4], [$num=52]); - SumStats::observe("test", [$host=1.2.3.4], [$num=61]); - SumStats::observe("test", [$host=1.2.3.4], [$num=95]); - SumStats::observe("test", [$host=6.5.4.3], [$num=5]); - SumStats::observe("test", [$host=7.2.1.5], [$num=91]); - SumStats::observe("test", [$host=10.10.10.10], [$num=5]); - } - } - -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -global peer_count = 0; -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - ++peer_count; - if ( peer_count == 2 ) - event ready_for_data(); - } - -@endif diff --git a/testing/btest/core/leaks/bloomfilter.zeek b/testing/btest/core/leaks/bloomfilter.zeek deleted file mode 100644 index 607aaf97f9..0000000000 --- a/testing/btest/core/leaks/bloomfilter.zeek +++ /dev/null @@ -1,101 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -function test_basic_bloom_filter() - { - # Basic usage with counts. - local bf_cnt = bloomfilter_basic_init(0.1, 1000); - bloomfilter_add(bf_cnt, 42); - bloomfilter_add(bf_cnt, 84); - bloomfilter_add(bf_cnt, 168); - print bloomfilter_lookup(bf_cnt, 0); - print bloomfilter_lookup(bf_cnt, 42); - print bloomfilter_lookup(bf_cnt, 168); - print bloomfilter_lookup(bf_cnt, 336); - bloomfilter_add(bf_cnt, 0.5); # Type mismatch - bloomfilter_add(bf_cnt, "foo"); # Type mismatch - - # Alternative constructor. - local bf_dbl = bloomfilter_basic_init2(4, 10); - bloomfilter_add(bf_dbl, 4.2); - bloomfilter_add(bf_dbl, 3.14); - print bloomfilter_lookup(bf_dbl, 4.2); - print bloomfilter_lookup(bf_dbl, 3.14); - - # Basic usage with strings. - local bf_str = bloomfilter_basic_init(0.9, 10); - bloomfilter_add(bf_str, "foo"); - bloomfilter_add(bf_str, "bar"); - print bloomfilter_lookup(bf_str, "foo"); - print bloomfilter_lookup(bf_str, "bar"); - print bloomfilter_lookup(bf_str, "bazzz"), "fp"; # FP - print bloomfilter_lookup(bf_str, "quuux"), "fp"; # FP - bloomfilter_add(bf_str, 0.5); # Type mismatch - bloomfilter_add(bf_str, 100); # Type mismatch - - # Edge cases. - local bf_edge0 = bloomfilter_basic_init(0.000000000001, 1); - local bf_edge1 = bloomfilter_basic_init(0.00000001, 100000000); - local bf_edge2 = bloomfilter_basic_init(0.9999999, 1); - local bf_edge3 = bloomfilter_basic_init(0.9999999, 100000000000); - - # Invalid parameters. - local bf_bug0 = bloomfilter_basic_init(-0.5, 42); - local bf_bug1 = bloomfilter_basic_init(1.1, 42); - - # Merging - local bf_cnt2 = bloomfilter_basic_init(0.1, 1000); - bloomfilter_add(bf_cnt2, 42); - bloomfilter_add(bf_cnt, 100); - local bf_merged = bloomfilter_merge(bf_cnt, bf_cnt2); - print bloomfilter_lookup(bf_merged, 42); - print bloomfilter_lookup(bf_merged, 84); - print bloomfilter_lookup(bf_merged, 100); - print bloomfilter_lookup(bf_merged, 168); - - #empty filter tests - local bf_empty = bloomfilter_basic_init(0.1, 1000); - local bf_empty_merged = bloomfilter_merge(bf_merged, bf_empty); - print bloomfilter_lookup(bf_empty_merged, 42); - } - -function test_counting_bloom_filter() - { - local bf = bloomfilter_counting_init(3, 32, 3); - bloomfilter_add(bf, "foo"); - print bloomfilter_lookup(bf, "foo"); # 1 - bloomfilter_add(bf, "foo"); - print bloomfilter_lookup(bf, "foo"); # 2 - bloomfilter_add(bf, "foo"); - print bloomfilter_lookup(bf, "foo"); # 3 - bloomfilter_add(bf, "foo"); - print bloomfilter_lookup(bf, "foo"); # still 3 - - - bloomfilter_add(bf, "bar"); - bloomfilter_add(bf, "bar"); - print bloomfilter_lookup(bf, "bar"); # 2 - print bloomfilter_lookup(bf, "foo"); # still 3 - - # Merging - local bf2 = bloomfilter_counting_init(3, 32, 3); - bloomfilter_add(bf2, "baz"); - bloomfilter_add(bf2, "baz"); - bloomfilter_add(bf2, "bar"); - local bf_merged = bloomfilter_merge(bf, bf2); - print bloomfilter_lookup(bf_merged, "foo"); - print bloomfilter_lookup(bf_merged, "bar"); - print bloomfilter_lookup(bf_merged, "baz"); - } - -event new_connection(c: connection) - { - test_basic_bloom_filter(); - test_counting_bloom_filter(); - } diff --git a/testing/btest/core/leaks/broker/clone_store.zeek b/testing/btest/core/leaks/broker/clone_store.zeek deleted file mode 100644 index f45ca6b771..0000000000 --- a/testing/btest/core/leaks/broker/clone_store.zeek +++ /dev/null @@ -1,144 +0,0 @@ -# @TEST-PORT: BROKER_PORT -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-GROUP: leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run clone "zeek -m -b ../clone.zeek >clone.out" -# @TEST-EXEC: btest-bg-run master "zeek -b ../master.zeek >master.out" - -# @TEST-EXEC: btest-bg-wait 90 -# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff clone/clone.out - -@TEST-START-FILE master.zeek - -redef exit_only_after_terminate = T; -global query_timeout = 1sec; - -global ready: event(); - -global h: opaque of Broker::Store; - -function print_index(k: any) - { - when ( local r = Broker::get(h, k) ) - { - print "master", k, r$status, r$result; - } - timeout query_timeout - { - print "master", fmt("clone ", k); - } - } - -event done() - { - terminate(); - } - -event inserted() - { - Broker::erase(h, "four"); - - print("----"); - print_index("one"); - print_index("two"); - print_index(vector(1,2)); - print_index("three"); - print_index("four"); - print_index("five"); - print_index("six"); - schedule 2secs { done() }; - } - -event zeek_init() - { - Broker::auto_publish("bro/events", done); - Broker::subscribe("bro/"); - - h = Broker::create_master("test"); - Broker::put(h, "one", "110"); - Broker::put(h, "two", 223); - Broker::put(h, vector(1,2), 1947/tcp); - - Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -event insert_more() - { - Broker::put(h, "three", 3.14); - Broker::put(h, "four", 1.2.3.4); - } - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - schedule 4secs { insert_more() }; - } - -@TEST-END-FILE - - -@TEST-START-FILE clone.zeek - -redef exit_only_after_terminate = T; - -global query_timeout = 1sec; - -global h: opaque of Broker::Store; - - -global inserted: event(); - -function print_index(k: any) - { - when ( local r = Broker::get(h, k) ) - { - print "clone", k, r$status, r$result; - } - timeout query_timeout - { - print "clone", fmt("clone ", k); - } - } - -event lookup(stage: count) - { - print("----"); - print_index("one"); - print_index("two"); - print_index(vector(1,2)); - print_index("three"); - print_index("four"); - print_index("five"); - print_index("six"); - - if ( stage == 1 ) - schedule 4secs { lookup(2) }; - - if ( stage == 2 ) - { - Broker::put(h, "five", "555"); - Broker::put(h, "six", "666"); - event inserted(); - schedule 2secs { lookup(3) }; - } - } - -event done() - { - terminate(); - } - -event zeek_init() - { - Broker::auto_publish("bro/events", inserted); - Broker::subscribe("bro/"); - Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - h = Broker::create_clone("test"); - schedule 2secs { lookup(1) }; - } - -@TEST-END-FILE - diff --git a/testing/btest/core/leaks/broker/data.zeek b/testing/btest/core/leaks/broker/data.zeek deleted file mode 100644 index c3f7b6cc43..0000000000 --- a/testing/btest/core/leaks/broker/data.zeek +++ /dev/null @@ -1,270 +0,0 @@ -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-GROUP: leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 -# @TEST-EXEC: btest-diff zeek/.stdout - -type bro_set: set[string]; -type bro_table: table[string] of count; -type bro_vector: vector of string; - -type bro_record : record { - a: string &optional; - b: string &default = "bee"; - c: count; -}; - -function broker_to_bro_record_recurse(it: opaque of Broker::RecordIterator, - rval: bro_record, - idx: count): bro_record - { - if ( Broker::record_iterator_last(it) ) - return rval; - - local field_value = Broker::record_iterator_value(it); - - if ( field_value?$data ) - switch ( idx ) { - case 0: - rval$a = field_value as string; - break; - case 1: - rval$b = field_value as string; - break; - case 2: - rval$c = field_value as count; - break; - }; - - ++idx; - Broker::record_iterator_next(it); - return broker_to_bro_record_recurse(it, rval, idx); - } - -function broker_to_bro_record(d: Broker::Data): bro_record - { - return broker_to_bro_record_recurse(Broker::record_iterator(d), - bro_record($c = 0), 0); - } - -function -broker_to_bro_set_recurse(it: opaque of Broker::SetIterator, - rval: bro_set): bro_set - { - if ( Broker::set_iterator_last(it) ) - return rval; - - add rval[Broker::set_iterator_value(it) as string]; - Broker::set_iterator_next(it); - return broker_to_bro_set_recurse(it, rval); - } - - -function broker_to_bro_set(d: Broker::Data): bro_set - { - return broker_to_bro_set_recurse(Broker::set_iterator(d), bro_set()); - } - -function -broker_to_bro_table_recurse(it: opaque of Broker::TableIterator, - rval: bro_table): bro_table - { - if ( Broker::table_iterator_last(it) ) - return rval; - - local item = Broker::table_iterator_value(it); - rval[item$key as string] = item$val as count; - Broker::table_iterator_next(it); - return broker_to_bro_table_recurse(it, rval); - } - -function broker_to_bro_table(d: Broker::Data): bro_table - { - return broker_to_bro_table_recurse(Broker::table_iterator(d), - bro_table()); - } - -function broker_to_bro_vector_recurse(it: opaque of Broker::VectorIterator, - rval: bro_vector): bro_vector - { - if ( Broker::vector_iterator_last(it) ) - return rval; - - rval += Broker::vector_iterator_value(it) as string; - Broker::vector_iterator_next(it); - return broker_to_bro_vector_recurse(it, rval); - } - -function broker_to_bro_vector(d: Broker::Data): bro_vector - { - return broker_to_bro_vector_recurse(Broker::vector_iterator(d), - bro_vector()); - } - -global did_it = F; - -event new_connection(c: connection) -{ -if ( did_it ) return; - -did_it = T; - -### Print every Broker data type - -print Broker::data_type(Broker::data(T)); -print Broker::data_type(Broker::data(+1)); -print Broker::data_type(Broker::data(1)); -print Broker::data_type(Broker::data(1.1)); -print Broker::data_type(Broker::data("1 (how creative)")); -print Broker::data_type(Broker::data(1.1.1.1)); -print Broker::data_type(Broker::data(1.1.1.1/1)); -print Broker::data_type(Broker::data(1/udp)); -print Broker::data_type(Broker::data(double_to_time(1))); -print Broker::data_type(Broker::data(1sec)); -print Broker::data_type(Broker::data(Broker::BOOL)); -local s: bro_set = bro_set("one", "two", "three"); -local t: bro_table = bro_table(["one"] = 1, ["two"] = 2, ["three"] = 3); -local v: bro_vector = bro_vector("zero", "one", "two"); -local r: bro_record = bro_record($c = 1); -print Broker::data_type(Broker::data(s)); -print Broker::data_type(Broker::data(t)); -print Broker::data_type(Broker::data(v)); -print Broker::data_type(Broker::data(r)); - -print "***************************"; - -### Convert a Zeek value to a Broker value, then print the result - -print (Broker::data(T)) as bool; -print (Broker::data(F)) as bool; -print (Broker::data(+1)) as int; -print (Broker::data(+0)) as int; -print (Broker::data(-1)) as int; -print (Broker::data(1)) as count; -print (Broker::data(0)) as count; -print (Broker::data(1.1)) as double; -print (Broker::data(-11.1)) as double; -print (Broker::data("hello")) as string; -print (Broker::data(1.2.3.4)) as addr; -print (Broker::data(192.168.1.1/16)) as subnet; -print (Broker::data(22/tcp)) as port; -print (Broker::data(double_to_time(42))) as time; -print (Broker::data(3min)) as interval; -print (Broker::data(Broker::BOOL)) as Broker::DataType; - -local cs = Broker::data(s); -print broker_to_bro_set(cs); - -local ct = Broker::data(t); -print broker_to_bro_table(ct); - -local cv = Broker::data(v); -print broker_to_bro_vector(cv); - -local cr = Broker::data(r); -print broker_to_bro_record(cr); - -r$a = "test"; -cr = Broker::data(r); -print broker_to_bro_record(cr); - -r$b = "testagain"; -cr = Broker::data(r); -print broker_to_bro_record(cr); - -print "***************************"; - -### Test the Broker set BIFs - -cs = Broker::set_create(); -print Broker::set_size(cs); -print Broker::set_insert(cs, ("hi")); -print Broker::set_size(cs); -print Broker::set_contains(cs, ("hi")); -print Broker::set_contains(cs, ("bye")); -print Broker::set_insert(cs, ("bye")); -print Broker::set_size(cs); -print Broker::set_insert(cs, ("bye")); -print Broker::set_size(cs); -print Broker::set_remove(cs, ("hi")); -print Broker::set_size(cs); -print Broker::set_remove(cs, ("hi")); -print broker_to_bro_set(cs); -print Broker::set_clear(cs); -print Broker::set_size(cs); -print broker_to_bro_set(cs); - -print "***************************"; - -### Test the Broker table BIFs - -ct = Broker::table_create(); -print Broker::table_size(ct); -print Broker::table_insert(ct, ("hi"), (42)); -print Broker::table_size(ct); -print Broker::table_contains(ct, ("hi")); -print (Broker::table_lookup(ct, ("hi"))) as count; -print Broker::table_contains(ct, ("bye")); -print Broker::table_insert(ct, ("bye"), (7)); -print Broker::table_size(ct); -print Broker::table_insert(ct, ("bye"), (37)); -print Broker::table_size(ct); -print (Broker::table_lookup(ct, ("bye"))) as count; -print Broker::table_remove(ct, ("hi")); -print Broker::table_size(ct); -print Broker::table_remove(ct, ("hi")); -print Broker::table_size(ct); -print Broker::table_clear(ct); -print Broker::table_size(ct); -print broker_to_bro_table(ct); - -print "***************************"; - -### Test the Broker vector BIFs - -cv = Broker::vector_create(); -print Broker::vector_size(cv); -print Broker::vector_insert(cv, 0, ("hi")); -print Broker::vector_insert(cv, 1, ("hello")); -print Broker::vector_insert(cv, 2, ("greetings")); -print Broker::vector_insert(cv, 1, ("salutations")); -print broker_to_bro_vector(cv); -print Broker::vector_size(cv); -print Broker::vector_replace(cv, 2, ("bah")); -print Broker::vector_lookup(cv, 2); -print Broker::vector_lookup(cv, 0); -print broker_to_bro_vector(cv); -print Broker::vector_remove(cv, 2); -print broker_to_bro_vector(cv); -print Broker::vector_size(cv); -print Broker::vector_clear(cv); -print Broker::vector_size(cv); -print broker_to_bro_vector(cv); - -print "***************************"; - -### Test the Broker record BIFs - -cr = Broker::record_create(3); -print Broker::record_size(cr); -print Broker::record_assign(cr, 0, ("hi")); -print Broker::record_assign(cr, 1, ("hello")); -print Broker::record_assign(cr, 2, (37)); -print Broker::record_lookup(cr, 0); -print Broker::record_lookup(cr, 1); -print Broker::record_lookup(cr, 2); -print Broker::record_size(cr); -print Broker::record_assign(cr, 1, ("goodbye")); -print Broker::record_size(cr); -print Broker::record_lookup(cr, 1); - -print "***************************"; - -### Test an opaque value - -local k1: opaque of topk = topk_init(4); -topk_add(k1, "a"); -print Broker::data(k1) is opaque of topk; -Broker::data(k1) as opaque of topk; -} diff --git a/testing/btest/core/leaks/broker/master_store.zeek b/testing/btest/core/leaks/broker/master_store.zeek deleted file mode 100644 index baced9869d..0000000000 --- a/testing/btest/core/leaks/broker/master_store.zeek +++ /dev/null @@ -1,149 +0,0 @@ -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-GROUP: leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef exit_only_after_terminate = T; - -global query_timeout = 45sec; - -global h: opaque of Broker::Store; - -global step: count = 0; - -function print_index(k: any) - { - when ( local r = Broker::get(h, k) ) - { - step += 1; - print fmt("[%d]", step), k, r$status, r$result; - } - timeout query_timeout - { - step += 1; - print fmt("[%d] ", step, k); - } - } - -function print_exists(k: any) - { - when ( local r = Broker::exists(h, k) ) - { - step += 1; - print fmt("[%d]", step), k, r; - } - timeout query_timeout - { - step += 1; - print fmt("[%d] ", step, k); - } - } - -function print_index_from_value(k: any, i: any) - { - when ( local r = Broker::get_index_from_value(h, k, i) ) - { - step += 1; - print fmt("[%d]", step), k, r$status, r$result; - } - timeout query_timeout - { - step += 1; - print fmt("[%d] ", step, k); - } - } - -function print_keys() - { - when ( local s = Broker::keys(h) ) - { - step += 1; - print "keys", s; - } - timeout query_timeout - { - step += 1; - print fmt("[%d] ", step); - } - } - -event done() - { - terminate(); - } - -event pk2() - { - print_keys(); - } - -event pk1() - { - print_keys(); - Broker::clear(h); - schedule 1sec { pk2() }; - } - -event zeek_init() - { - h = Broker::create_master("master"); - Broker::put(h, "one", "110"); - Broker::put(h, "two", 220); - Broker::put(h, "three", 330); - Broker::put(h, "four", set(1, 2,3)); - Broker::put(h, set("x", "y"), vector(1/tcp, 2/tcp, 3/tcp)); - - Broker::put(h, "str", "foo"); - Broker::put(h, "vec", vector(1, 2,3)); - Broker::put(h, "set", set("A", "B")); - Broker::put(h, "table", table(["a"] = 1, ["b"] = 2)); - - print_index("one"); - print_index("two"); - print_index("three"); - print_index("four"); - print_index("five"); - print_index(set("x", "y")); - - when ( step == 6 ) - { - Broker::increment(h, "two"); - Broker::increment(h, "two", 9); - Broker::decrement(h, "three"); - Broker::decrement(h, "three", 9); - print_index("two"); - print_index("three"); - print_index("four"); - print_keys(); - Broker::erase(h, "four"); - - Broker::append(h, "str", "bar"); - Broker::insert_into_set(h, "set", "C"); - Broker::insert_into_table(h, "table", "c", 3); - Broker::remove_from(h, "set", 2); - Broker::remove_from(h, "table", "b"); - Broker::push(h, "vec", 4); - Broker::push(h, "vec", 5); - Broker::pop(h, "vec"); - - print_index("str"); - print_index("set"); - print_index("table"); - print_index("vec"); - - print_exists("one"); - print_exists("NOPE"); - - print_index_from_value("vec", 1); - print_index_from_value("set", "A"); - print_index_from_value("table", "a"); - print_index_from_value("table", "X"); - - schedule 1sec { pk1() }; - } - - schedule 15secs { done() }; - } - - diff --git a/testing/btest/core/leaks/broker/remote_event.test b/testing/btest/core/leaks/broker/remote_event.test deleted file mode 100644 index a70274a19a..0000000000 --- a/testing/btest/core/leaks/broker/remote_event.test +++ /dev/null @@ -1,85 +0,0 @@ -# @TEST-PORT: BROKER_PORT -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-GROUP: leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run recv "zeek -m -b ../recv.zeek >recv.out" -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run send "zeek -m -b ../send.zeek >send.out" - -# @TEST-EXEC: btest-bg-wait 90 -# @TEST-EXEC: btest-diff recv/recv.out -# @TEST-EXEC: btest-diff send/send.out - -@TEST-START-FILE recv.zeek - -redef exit_only_after_terminate = T; - -global event_handler: event(msg: string, c: count); -global auto_event_handler: event(msg: string, c: count); - -event zeek_init() - { - Broker::subscribe("bro/event/"); - Broker::auto_publish("bro/event/my_topic", auto_event_handler); - Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -global event_count = 0; -global events_to_recv = 6; - -event event_handler(msg: string, n: count) - { - ++event_count; - print "got event msg", msg, n; - - if ( event_count == events_to_recv ) - { - terminate(); - return; - } - - event auto_event_handler(msg, n); - Broker::publish("bro/event/my_topic", event_handler, "pong", n); - } - -@TEST-END-FILE - -@TEST-START-FILE send.zeek - -redef exit_only_after_terminate = T; - -global event_handler: event(msg: string, c: count); -global auto_event_handler: event(msg: string, c: count); - -event zeek_init() - { - Broker::subscribe("bro/event/my_topic"); - Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT")), 1secs); - } - -global event_count = 0; - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - print "Broker peer added", endpoint$network$address; - Broker::publish("bro/event/hi", event_handler, "ping", event_count); - ++event_count; - } - -event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) - { - terminate(); - } - -event event_handler(msg: string, n: count) - { - print "got event msg", msg, n; - Broker::publish("bro/event/hi", event_handler, "ping", event_count); - ++event_count; - } - -event auto_event_handler(msg: string, n: count) - { - print "got auto event msg", msg, n; - } - -@TEST-END-FILE diff --git a/testing/btest/core/leaks/broker/remote_log.test b/testing/btest/core/leaks/broker/remote_log.test deleted file mode 100644 index 8fb872ae7f..0000000000 --- a/testing/btest/core/leaks/broker/remote_log.test +++ /dev/null @@ -1,88 +0,0 @@ -# @TEST-PORT: BROKER_PORT -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-GROUP: leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run recv "zeek -m -b ../recv.zeek >recv.out" -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run send "zeek -m -b ../send.zeek >send.out" - -# @TEST-EXEC: btest-bg-wait 90 -# @TEST-EXEC: btest-diff recv/recv.out -# @TEST-EXEC: btest-diff recv/test.log -# @TEST-EXEC: btest-diff send/send.out -# @TEST-EXEC: btest-diff send/test.log - -@TEST-START-FILE common.zeek - -redef exit_only_after_terminate = T; - -module Test; - -export { - redef enum Log::ID += { LOG }; - - type Info: record { - msg: string &log; - nolog: string &default="no"; - num: count &log; - }; -} - -event zeek_init() &priority=5 - { - Log::create_stream(Test::LOG, [$columns=Test::Info]); - } - -event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) - { - terminate(); - } - -@TEST-END-FILE - -@TEST-START-FILE recv.zeek - -@load ./common - -event zeek_init() - { - Broker::subscribe("zeek/"); - Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -event Broker::peer_removed(endpoint: Broker::EndpointInfo, msg: string) - { - terminate(); - } - -@TEST-END-FILE - -@TEST-START-FILE send.zeek - -@load ./common - -event zeek_init() - { - Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -global n = 0; - -event do_write() - { - if ( n == 6 ) - terminate(); - else - { - Log::write(Test::LOG, [$msg = "ping", $num = n]); - ++n; - schedule 0.1secs { do_write() }; - } - } - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - print "Broker peer added", endpoint$network$address; - event do_write(); - } - -@TEST-END-FILE diff --git a/testing/btest/core/leaks/closure-sending.zeek b/testing/btest/core/leaks/closure-sending.zeek deleted file mode 100644 index 32db29097a..0000000000 --- a/testing/btest/core/leaks/closure-sending.zeek +++ /dev/null @@ -1,168 +0,0 @@ -# @TEST-PORT: BROKER_PORT -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-GROUP: leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run recv "zeek -m -b ../recv.zeek >recv.out" -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run send "zeek -m -b ../send.zeek >send.out" - -# @TEST-EXEC: btest-bg-wait 90 -# @TEST-EXEC: btest-diff recv/recv.out -# @TEST-EXEC: btest-diff send/send.out - -@TEST-START-FILE send.zeek - -redef exit_only_after_terminate = T; -type myfunctype: function(c: count) : function(d: count) : count; - -global global_with_same_name = 10; - -global ping: event(msg: string, f: myfunctype); - -event zeek_init() - { - print "hello :)"; - Broker::subscribe("zeek/event/my_topic"); - Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -global n = 0; - -function send_event() - { - # in this frame event_count has an offset of three. - # in the receiving frame it has an offset of one. - # this tests to ensure that id lookups are being routed properly. - local dog = 0; - local not_dog = 1; - local event_count = 11; - - local log : myfunctype = function(c: count) : function(d: count) : count - { - print fmt("inside: %s | outside: %s | global: %s", c, event_count, global_with_same_name); - return function(d: count) : count { return d + c; }; - }; - - local two_part_adder_maker = function (begin : count) : function (base_step : count) : function ( step : count) : count - { - return function (base_step : count) : function (step : count) : count - { - print fmt("begin: %s | base_step: %s", begin, base_step); - return function (step : count) : count - { - print fmt("begin: %s | base_step: %s | step: %s", begin, base_step, step); - return (begin += base_step + step); }; }; }; - - local l = two_part_adder_maker(100); - local stepper = l(50); - - ++n; - if ( n % 2 == 0) - { - local e2 = Broker::make_event(ping, "function 1", l); - Broker::publish("zeek/event/my_topic", e2); - } - else - { - local e = Broker::make_event(ping, "function 2", log); - Broker::publish("zeek/event/my_topic", e); - } - } - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - print "peer added"; - send_event(); - } - -event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) - { - print "peer lost"; - terminate(); - } - -event pong(msg: string, f: myfunctype) - { - print fmt("sender got pong: %s", msg); - local adder = f(n); - print adder(76); - send_event(); - } - -@TEST-END-FILE - -@TEST-START-FILE recv.zeek - -redef exit_only_after_terminate = T; -const events_to_recv = 7; -type myfunctype: function(c: count) : function(d: count) : count; -# type myfunctype: function(c: count); - -global global_with_same_name = 100; - -global pong: event(msg: string, f: myfunctype); - -# This is one, of many, ways to declare your functions that you plan to receive. -# All you are doing is giving the parser a version of their body, so they can be -# anywhere. This seems to work quite nicely because it keeps them scoped and stops -# them from ever being evaluated. -function my_funcs() - { - return; - - local begin = 100; - local event_count = begin; - - local l : myfunctype = function(c: count) : function(d: count) : count - { - print fmt("inside: %s | outside: %s | global: %s", c, event_count, global_with_same_name); - return function(d: count) : count { return d + c; }; - }; - - local dog_fish = function (base_step : count) : function (step : count) : count - { -# actual formatting doesn't matter for name resolution. -print fmt("begin: %s | base_step: %s", begin, base_step); - return function (step : count) : count - { - print fmt("begin: %s | base_step: %s | step: %s", begin, base_step, step); - return (begin += base_step + step); }; }; - } - -event zeek_init() - { - print "hello :-)"; - Broker::subscribe("zeek/event/my_topic"); - Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT"))); - } - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - print "peer added"; - } - -event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) - { - print "peer lost"; - } - -global n = 0; - -event ping(msg: string, f: myfunctype) - { - print fmt("receiver got ping: %s", msg); - ++n; - local adder = f(n); - print adder(76); - - if ( n == events_to_recv ) - { - terminate(); - } - else - { - local e = Broker::make_event(pong, msg, f); - Broker::publish("zeek/event/my_topic", e); - } - } - -@TEST-END-FILE diff --git a/testing/btest/core/leaks/copy-all-opaques.zeek b/testing/btest/core/leaks/copy-all-opaques.zeek deleted file mode 100644 index e8568f4eae..0000000000 --- a/testing/btest/core/leaks/copy-all-opaques.zeek +++ /dev/null @@ -1,90 +0,0 @@ -# @TEST-GROUP: leaks -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -global did_it = F; - -event new_connection(c: connection) - { - if ( did_it ) - return; - - did_it = T; - - print "============ Topk"; - local k1: opaque of topk = topk_init(4); - topk_add(k1, "a"); - topk_add(k1, "b"); - topk_add(k1, "b"); - topk_add(k1, "c"); - local k2 = copy(k1); - print topk_get_top(k1, 5); - topk_add(k1, "shoulnotshowup"); - print topk_get_top(k2, 5); - - - print "============ HLL"; - local c1 = hll_cardinality_init(0.01, 0.95); - hll_cardinality_add(c1, 2001); - hll_cardinality_add(c1, 2002); - hll_cardinality_add(c1, 2003); - - print hll_cardinality_estimate(c1); - local c2 = copy(c1); - hll_cardinality_add(c1, 2004); - print hll_cardinality_estimate(c2); - - print "============ Bloom"; - local bf_cnt = bloomfilter_basic_init(0.1, 1000); - bloomfilter_add(bf_cnt, 42); - bloomfilter_add(bf_cnt, 84); - bloomfilter_add(bf_cnt, 168); - print bloomfilter_lookup(bf_cnt, 0); - print bloomfilter_lookup(bf_cnt, 42); - local bf_copy = copy(bf_cnt); - bloomfilter_add(bf_cnt, 0); - print bloomfilter_lookup(bf_copy, 0); - print bloomfilter_lookup(bf_copy, 42); - # check that typefication transfered. - bloomfilter_add(bf_copy, 0.5); # causes stderr output - - print "============ Hashes"; - local md5a = md5_hash_init(); - md5_hash_update(md5a, "one"); - local md5b = copy(md5a); - md5_hash_update(md5a, "two"); - md5_hash_update(md5b, "two"); - print md5_hash_finish(md5a); - print md5_hash_finish(md5b); - - local sha1a = sha1_hash_init(); - sha1_hash_update(sha1a, "one"); - local sha1b = copy(sha1a); - sha1_hash_update(sha1a, "two"); - sha1_hash_update(sha1b, "two"); - print sha1_hash_finish(sha1a); - print sha1_hash_finish(sha1b); - - local sha256a = sha256_hash_init(); - sha256_hash_update(sha256a, "one"); - local sha256b = copy(sha256a); - sha256_hash_update(sha256a, "two"); - sha256_hash_update(sha256b, "two"); - print sha256_hash_finish(sha256a); - print sha256_hash_finish(sha256b); - - print "============ X509"; - local x509 = x509_from_der("\x30\x82\x03\x75\x30\x82\x02\x5D\xA0\x03\x02\x01\x02\x02\x0B\x04\x00\x00\x00\x00\x01\x15\x4B\x5A\xC3\x94\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x05\x05\x00\x30\x57\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x42\x45\x31\x19\x30\x17\x06\x03\x55\x04\x0A\x13\x10\x47\x6C\x6F\x62\x61\x6C\x53\x69\x67\x6E\x20\x6E\x76\x2D\x73\x61\x31\x10\x30\x0E\x06\x03\x55\x04\x0B\x13\x07\x52\x6F\x6F\x74\x20\x43\x41\x31\x1B\x30\x19\x06\x03\x55\x04\x03\x13\x12\x47\x6C\x6F\x62\x61\x6C\x53\x69\x67\x6E\x20\x52\x6F\x6F\x74\x20\x43\x41\x30\x1E\x17\x0D\x39\x38\x30\x39\x30\x31\x31\x32\x30\x30\x30\x30\x5A\x17\x0D\x32\x38\x30\x31\x32\x38\x31\x32\x30\x30\x30\x30\x5A\x30\x57\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x42\x45\x31\x19\x30\x17\x06\x03\x55\x04\x0A\x13\x10\x47\x6C\x6F\x62\x61\x6C\x53\x69\x67\x6E\x20\x6E\x76\x2D\x73\x61\x31\x10\x30\x0E\x06\x03\x55\x04\x0B\x13\x07\x52\x6F\x6F\x74\x20\x43\x41\x31\x1B\x30\x19\x06\x03\x55\x04\x03\x13\x12\x47\x6C\x6F\x62\x61\x6C\x53\x69\x67\x6E\x20\x52\x6F\x6F\x74\x20\x43\x41\x30\x82\x01\x22\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00\x03\x82\x01\x0F\x00\x30\x82\x01\x0A\x02\x82\x01\x01\x00\xDA\x0E\xE6\x99\x8D\xCE\xA3\xE3\x4F\x8A\x7E\xFB\xF1\x8B\x83\x25\x6B\xEA\x48\x1F\xF1\x2A\xB0\xB9\x95\x11\x04\xBD\xF0\x63\xD1\xE2\x67\x66\xCF\x1C\xDD\xCF\x1B\x48\x2B\xEE\x8D\x89\x8E\x9A\xAF\x29\x80\x65\xAB\xE9\xC7\x2D\x12\xCB\xAB\x1C\x4C\x70\x07\xA1\x3D\x0A\x30\xCD\x15\x8D\x4F\xF8\xDD\xD4\x8C\x50\x15\x1C\xEF\x50\xEE\xC4\x2E\xF7\xFC\xE9\x52\xF2\x91\x7D\xE0\x6D\xD5\x35\x30\x8E\x5E\x43\x73\xF2\x41\xE9\xD5\x6A\xE3\xB2\x89\x3A\x56\x39\x38\x6F\x06\x3C\x88\x69\x5B\x2A\x4D\xC5\xA7\x54\xB8\x6C\x89\xCC\x9B\xF9\x3C\xCA\xE5\xFD\x89\xF5\x12\x3C\x92\x78\x96\xD6\xDC\x74\x6E\x93\x44\x61\xD1\x8D\xC7\x46\xB2\x75\x0E\x86\xE8\x19\x8A\xD5\x6D\x6C\xD5\x78\x16\x95\xA2\xE9\xC8\x0A\x38\xEB\xF2\x24\x13\x4F\x73\x54\x93\x13\x85\x3A\x1B\xBC\x1E\x34\xB5\x8B\x05\x8C\xB9\x77\x8B\xB1\xDB\x1F\x20\x91\xAB\x09\x53\x6E\x90\xCE\x7B\x37\x74\xB9\x70\x47\x91\x22\x51\x63\x16\x79\xAE\xB1\xAE\x41\x26\x08\xC8\x19\x2B\xD1\x46\xAA\x48\xD6\x64\x2A\xD7\x83\x34\xFF\x2C\x2A\xC1\x6C\x19\x43\x4A\x07\x85\xE7\xD3\x7C\xF6\x21\x68\xEF\xEA\xF2\x52\x9F\x7F\x93\x90\xCF\x02\x03\x01\x00\x01\xA3\x42\x30\x40\x30\x0E\x06\x03\x55\x1D\x0F\x01\x01\xFF\x04\x04\x03\x02\x01\x06\x30\x0F\x06\x03\x55\x1D\x13\x01\x01\xFF\x04\x05\x30\x03\x01\x01\xFF\x30\x1D\x06\x03\x55\x1D\x0E\x04\x16\x04\x14\x60\x7B\x66\x1A\x45\x0D\x97\xCA\x89\x50\x2F\x7D\x04\xCD\x34\xA8\xFF\xFC\xFD\x4B\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x05\x05\x00\x03\x82\x01\x01\x00\xD6\x73\xE7\x7C\x4F\x76\xD0\x8D\xBF\xEC\xBA\xA2\xBE\x34\xC5\x28\x32\xB5\x7C\xFC\x6C\x9C\x2C\x2B\xBD\x09\x9E\x53\xBF\x6B\x5E\xAA\x11\x48\xB6\xE5\x08\xA3\xB3\xCA\x3D\x61\x4D\xD3\x46\x09\xB3\x3E\xC3\xA0\xE3\x63\x55\x1B\xF2\xBA\xEF\xAD\x39\xE1\x43\xB9\x38\xA3\xE6\x2F\x8A\x26\x3B\xEF\xA0\x50\x56\xF9\xC6\x0A\xFD\x38\xCD\xC4\x0B\x70\x51\x94\x97\x98\x04\xDF\xC3\x5F\x94\xD5\x15\xC9\x14\x41\x9C\xC4\x5D\x75\x64\x15\x0D\xFF\x55\x30\xEC\x86\x8F\xFF\x0D\xEF\x2C\xB9\x63\x46\xF6\xAA\xFC\xDF\xBC\x69\xFD\x2E\x12\x48\x64\x9A\xE0\x95\xF0\xA6\xEF\x29\x8F\x01\xB1\x15\xB5\x0C\x1D\xA5\xFE\x69\x2C\x69\x24\x78\x1E\xB3\xA7\x1C\x71\x62\xEE\xCA\xC8\x97\xAC\x17\x5D\x8A\xC2\xF8\x47\x86\x6E\x2A\xC4\x56\x31\x95\xD0\x67\x89\x85\x2B\xF9\x6C\xA6\x5D\x46\x9D\x0C\xAA\x82\xE4\x99\x51\xDD\x70\xB7\xDB\x56\x3D\x61\xE4\x6A\xE1\x5C\xD6\xF6\xFE\x3D\xDE\x41\xCC\x07\xAE\x63\x52\xBF\x53\x53\xF4\x2B\xE9\xC7\xFD\xB6\xF7\x82\x5F\x85\xD2\x41\x18\xDB\x81\xB3\x04\x1C\xC5\x1F\xA4\x80\x6F\x15\x20\xC9\xDE\x0C\x88\x0A\x1D\xD6\x66\x55\xE2\xFC\x48\xC9\x29\x26\x69\xE0"); - local x5092 = copy(x509); - print x509_parse(x509); - print x509_parse(x5092); - - print "============ Entropy"; - local handle = entropy_test_init(); - entropy_test_add(handle, "dh3Hie02uh^s#Sdf9L3frd243h$d78r2G4cM6*Q05d(7rh46f!0|4-f"); - local handle2 = copy(handle); - print entropy_test_finish(handle); - print entropy_test_finish(handle2); - } diff --git a/testing/btest/core/leaks/copy-all-types.zeek b/testing/btest/core/leaks/copy-all-types.zeek deleted file mode 100644 index 24bbb52fa6..0000000000 --- a/testing/btest/core/leaks/copy-all-types.zeek +++ /dev/null @@ -1,196 +0,0 @@ -# Note: opaque types in separate test -# @TEST-GROUP: leaks -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -type MyEnum: enum { ENUMME }; - -type InnerTestRecord: record { - a: string; -}; - -type TestRecord: record { - s1: string; - s2: string; - i1: InnerTestRecord; - i2: InnerTestRecord &optional; - donotset: InnerTestRecord &optional; - def: count &default=5; -}; - -function join_count_set(ss: set[count], j: string): string - { - local output=""; - local i=0; - for ( s in ss ) - { - if ( i > 0 ) - output = cat(output, j); - - output = cat(output, s); - ++i; - } - return output; - } - -function do_format(i: any): any - { - local tpe = type_name(i); - - switch ( tpe ) - { - case "set[count]": - return join_count_set(i, ","); - case "table[string] of string": - local cast: table[string] of string = i; - local vout: vector of string = vector(); - for ( el in cast ) - { - vout += cat(el, "=", cast[el]); - } - return join_string_vec(vout, ";"); - } - return i; - } - -function check(o1: any, o2: any, equal: bool, expect_same: bool) - { - local expect_msg = (equal ? "ok" : "FAIL0"); - local same = same_object(o1, o2); - - if ( expect_same && ! same ) - expect_msg = "FAIL1"; - - if ( ! expect_same && same ) - expect_msg = "FAIL2"; - - print fmt("orig=%s (%s) clone=%s (%s) equal=%s same_object=%s (%s)", do_format(o1), type_name(o1), do_format(o2), type_name(o2), equal, same, expect_msg); - } - -function check_vector_equal(a: vector of count, b: vector of count): bool - { - if ( |a| != |b| ) - return F; - - for ( i in a ) - { - if ( a[i] != b[i] ) - return F; - } - - return T; - } - -function check_string_table_equal(a: table[string] of string, b: table[string] of string): bool - { - if ( |a| != |b| ) - return F; - - for ( i in a ) - { - if ( a[i] != b[i] ) - return F; - } - - return T; - } - -function compare_otr(a: TestRecord, b: TestRecord): bool - { - if ( a$s1 != b$s1 ) - return F; - if ( a$s2 != b$s2 ) - return F; - if ( a$i1$a != b$i1$a ) - return F; - if ( a$i2$a != b$i2$a ) - return F; - - if ( same_object(a$i1, b$i1) ) - return F; - if ( same_object(a$i2, b$i2) ) - return F; - - # check that we restroe that i1 & i2 point to same object - if ( ! same_object(a$i1, a$i2) ) - return F; - if ( ! same_object(b$i1, b$i2) ) - return F; - - if ( a$def != b$def ) - return F; - - return T; - } - -global did_it = F; - -event new_connection(c: connection) - { - if ( did_it ) - return; - - did_it = T; - - local i1 = -42; - local i2 = copy(i1); - check(i1, i2, i1 == i2, T); - - local c1 : count = 42; - local c2 = copy(c1); - check(c1, c2, c1 == c2, T); - - local a1 = 127.0.0.1; - local a2 = copy(a1); - check(a1, a2, a1 == a2, T); - - local p1 = 42/tcp; - local p2 = copy(p1); - check(p1, p2, p1 == p2, T); - - local sn1 = 127.0.0.1/24; - local sn2 = copy(sn1); - check(sn1, sn2, sn1 == sn2, T); - - local s1 = "Foo"; - local s2 = copy(s1); - check(s1, s2, s1 == s2, F); - - local pat1 = /.*PATTERN.*/; - local pat2 = copy(pat1); - # patterns cannot be directoy compared - if ( same_object(pat1, pat2) ) - print "FAIL P1"; - if ( ! ( pat1 == "PATTERN" ) ) - print "FAIL P2"; - if ( ! ( pat2 == "PATTERN" ) ) - print "FAIL P3"; - if ( pat2 == "PATERN" ) - print "FAIL P4"; - print fmt("orig=%s (%s) clone=%s (%s) same_object=%s", pat1, type_name(pat1), pat2, type_name(pat2), same_object(pat1, pat2)); - - local set1 = [1, 2, 3, 4, 5]; - local set2 = copy(set1); - check(set1, set2, set1 == set2, F); - - local v1 = vector(1, 2, 3, 4, 5); - local v2 = copy(v1); - check(v1, v2, check_vector_equal(v1, v2), F); - - local t1 : table[string] of string = table(); - t1["a"] = "va"; - t1["b"] = "vb"; - local t2 = copy(t1); - check(t1, t2, check_string_table_equal(t1, t2), F); - - local e1 = ENUMME; - local e2 = copy(ENUMME); - check(e1, e2, e1 == e2, T); - - local itr = InnerTestRecord($a="a"); - local otr1 = TestRecord($s1="s1", $s2="s2", $i1=itr, $i2=itr); - local otr2 = copy(otr1); - check(otr1, otr2, compare_otr(otr1, otr2), F); - } diff --git a/testing/btest/core/leaks/dns-nsec3.zeek b/testing/btest/core/leaks/dns-nsec3.zeek deleted file mode 100644 index 067a8426a4..0000000000 --- a/testing/btest/core/leaks/dns-nsec3.zeek +++ /dev/null @@ -1,40 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -C -m -r $TRACES/dnssec/nsec3.pcap %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load policy/protocols/dns/auth-addl - -event dns_RRSIG(c: connection, msg: dns_msg, ans: dns_answer, rrsig: dns_rrsig_rr) - { - print "RRSIG", rrsig, bytestring_to_hexstr(rrsig$signature); - } - -event dns_DNSKEY(c: connection, msg: dns_msg, ans: dns_answer, dnskey: dns_dnskey_rr) - { - print "DNSKEY", dnskey, bytestring_to_hexstr(dnskey$public_key); - } - -event dns_NSEC(c: connection, msg: dns_msg, ans: dns_answer, next_name: string, bitmaps: string_vec) - { - print "NSEC", next_name, bitmaps; - - for ( i in bitmaps ) - print bytestring_to_hexstr(bitmaps[i]); - } - -event dns_NSEC3(c: connection, msg: dns_msg, ans: dns_answer, nsec3: dns_nsec3_rr) - { - print "NSEC3", nsec3, - bytestring_to_hexstr(nsec3$nsec_salt), - bytestring_to_hexstr(nsec3$nsec_hash); - } - -event dns_DS(c: connection, msg: dns_msg, ans: dns_answer, ds: dns_ds_rr) - { - print "DS", ds, bytestring_to_hexstr(ds$digest_val); - } diff --git a/testing/btest/core/leaks/dns-txt.zeek b/testing/btest/core/leaks/dns-txt.zeek deleted file mode 100644 index 41e16ff3da..0000000000 --- a/testing/btest/core/leaks/dns-txt.zeek +++ /dev/null @@ -1,42 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef exit_only_after_terminate = T; - -global n1 = 0; - -function check_term_conditions() - { - if ( n1 > 7 ) - terminate(); - } - - -event do_txt(s: string) - { - when ( local t1 = lookup_hostname_txt(s) ) - { - print "t1", t1; - ++n1; - check_term_conditions(); - } - timeout 100secs - { - print "t1 timeout"; - ++n1; - check_term_conditions(); - } - } - -event connection_established(c: connection) - { - event do_txt("localhost"); - schedule 5sec { do_txt("localhost") }; - } - diff --git a/testing/btest/core/leaks/dns.zeek b/testing/btest/core/leaks/dns.zeek deleted file mode 100644 index 5e3f4c9bf1..0000000000 --- a/testing/btest/core/leaks/dns.zeek +++ /dev/null @@ -1,81 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef exit_only_after_terminate = T; - -const foo: set[addr] = { - google.com -}; - -global n1 = 0; -global n2 = 0; -global n3 = 0; -global n4 = 0; - -function check_term_conditions() - { - if ( n1 > 4 && n2 > 4 && n3 > 4 && n4 > 4 ) - terminate(); - } - -event connection_established(c: connection) - { - when ( local addrs = lookup_hostname("localhost") ) - { - print "1a", c$id$resp_h, addrs; - ++n1; - check_term_conditions(); - } - timeout 100secs - { - print "1b", c$id$resp_h; - ++n1; - check_term_conditions(); - } - - when ( local addrs2 = lookup_hostname("qq.ww.ee.rrrrr") ) - { - print "2a", c$id$resp_h, addrs2; - ++n2; - check_term_conditions(); - } - timeout 100secs - { - print "2b", c$id$resp_h; - ++n2; - check_term_conditions(); - } - - when ( local a = lookup_addr(c$id$resp_h) ) - { - print "3a", c$id$resp_h, a; - ++n3; - check_term_conditions(); - } - timeout 100secs - { - print "3b", c$id$resp_h; - ++n3; - check_term_conditions(); - } - - when ( local a2 = lookup_addr(1.2.3.4) ) - { - print "4a", c$id$resp_h, a2; - ++n4; - check_term_conditions(); - } - timeout 100secs - { - print "4b", c$id$resp_h; - ++n4; - check_term_conditions(); - } - } - diff --git a/testing/btest/core/leaks/dtls.zeek b/testing/btest/core/leaks/dtls.zeek deleted file mode 100644 index b894cb6fb9..0000000000 --- a/testing/btest/core/leaks/dtls.zeek +++ /dev/null @@ -1,15 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/tls/dtls1_0.pcap %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/ssl - -event ssl_established(c: connection) &priority=3 - { - print "established"; - } diff --git a/testing/btest/core/leaks/exec.test b/testing/btest/core/leaks/exec.test deleted file mode 100644 index f6ddf9998e..0000000000 --- a/testing/btest/core/leaks/exec.test +++ /dev/null @@ -1,79 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b ../exectest.zeek -# @TEST-EXEC: btest-bg-wait 90 - -@TEST-START-FILE exectest.zeek - -@load base/utils/exec -redef exit_only_after_terminate = T; - -global c: count = 0; - -function check_exit_condition() - { - c += 1; - - if ( c == 3 ) - terminate(); - } - -function test_cmd(label: string, cmd: Exec::Command) - { - when ( local result = Exec::run(cmd) ) - { - print label, result; - check_exit_condition(); - } - } - -event zeek_init() - { - test_cmd("test1", [$cmd="bash ../somescript.sh", - $read_files=set("out1", "out2")]); - test_cmd("test2", [$cmd="bash ../nofiles.sh"]); - # Not sure of a portable way to test signals yet. - #test_cmd("test3", [$cmd="bash ../suicide.sh"]); - test_cmd("test4", [$cmd="bash ../stdin.sh", $stdin="hibye"]); - } - -@TEST-END-FILE - -@TEST-START-FILE somescript.sh -#! /usr/bin/env bash -echo "insert text here" > out1 -echo "and here" >> out1 -echo "insert more text here" > out2 -echo "and there" >> out2 -echo "done" -echo "exit" -echo "stop" -@TEST-END-FILE - -@TEST-START-FILE nofiles.sh -#! /usr/bin/env bash -echo "here's something on stdout" -echo "some more stdout" -echo "last stdout" -echo "and some stderr" 1>&2 -echo "more stderr" 1>&2 -echo "last stderr" 1>&2 -exit 1 -@TEST-END-FILE - -@TEST-START-FILE suicide.sh -#! /usr/bin/env bash -echo "FML" -kill -9 $$ -echo "nope" -@TEST-END-FILE - -@TEST-START-FILE stdin.sh -#! /usr/bin/env bash -read -r line -echo "$line" -@TEST-END-FILE diff --git a/testing/btest/core/leaks/file-analysis-http-get.zeek b/testing/btest/core/leaks/file-analysis-http-get.zeek deleted file mode 100644 index c86e6aea4f..0000000000 --- a/testing/btest/core/leaks/file-analysis-http-get.zeek +++ /dev/null @@ -1,15 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/http/get.trace $SCRIPTS/file-analysis-test.zeek %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef test_file_analysis_source = "HTTP"; - -redef test_get_file_name = function(f: fa_file): string - { - return fmt("%s-file", f$id); - }; diff --git a/testing/btest/core/leaks/function-closures.zeek b/testing/btest/core/leaks/function-closures.zeek deleted file mode 100644 index 1f5ee9eb55..0000000000 --- a/testing/btest/core/leaks/function-closures.zeek +++ /dev/null @@ -1,107 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/http/get.trace $SCRIPTS/file-analysis-test.zeek %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -# maps a function to a vector -function map_1 (f: function(a: count): count, v: vector of count) : vector of count - { - local out: vector of count; - - for ( i in v ) - out += f(v[i]); - - return out; - } - -# stacks two functions -function stacker (one : function(a: count): count, two: function (b: count): count): function(c: count): count - { - return function (c: count): count - { - return one(two(c)); - }; - } - -function make_dog(name: string, weight: count) : function(i: string, item: string) - { - return function(i: string, item: string) - { - switch i - { - case "set name": - name = item; - break; - case "get name": - print name; - break; - case "eat": - print ++weight; - break; - case "run": - print --weight; - break; - default: - print "bark"; - break; - } - }; - } - -event new_connection(c: connection) - { - local v = vector(vector(1, 2, 3), vector(4, 5, 6)); - - local make_laster = function(start: count) : function(i: count): count - { - return function(i: count): count - { - local temp = i; - i += start; - start = temp; - return i; - }; - }; - - local test = vector(1, 2, 3); - print "expect [1, 3, 5]"; - print map_1(make_laster(0), test); - - local times_two = function(i: count): count { return i*2; }; - local times_four = stacker(times_two, times_two); - local times_eight = stacker(times_four, times_two); - - print "expect 16"; - print times_eight(2); - - print "expect [8, 16, 24]"; - print map_1(times_eight, test); - - # things like this are only possible becuse we allow functions to - # mutate their closures. - local thunder= make_dog("thunder", 10); - thunder("get name", ""); - thunder("set name", "buster"); - thunder("get name", ""); - thunder("eat", ""); - thunder("eat", ""); - thunder("run", ""); - - - # why this works is a little bit of a mystery to me. - # I suspect it has something to do with how for loops handle frames. - # the above test shows that we are properly capturing primitives - # by reference. - local mfs: vector of function(); - local vs = vector("dog", "cat", "fish"); - for (i in vs) - { - mfs += function() { print i, vs[i]; }; - } - for ( i in mfs) - mfs[i](); - } diff --git a/testing/btest/core/leaks/gridftp.test b/testing/btest/core/leaks/gridftp.test deleted file mode 100644 index fd60776dfd..0000000000 --- a/testing/btest/core/leaks/gridftp.test +++ /dev/null @@ -1,25 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/globus-url-copy.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/ftp/gridftp - -module GridFTP; - -redef size_threshold = 2; - -redef enum Notice::Type += { - Data_Channel -}; - -event GridFTP::data_channel_detected(c: connection) - { - local msg = fmt("GridFTP data channel over threshold %d bytes", - size_threshold); - NOTICE([$note=Data_Channel, $msg=msg, $conn=c]); - } diff --git a/testing/btest/core/leaks/gtp_opt_header.test b/testing/btest/core/leaks/gtp_opt_header.test deleted file mode 100644 index ddfdd133d7..0000000000 --- a/testing/btest/core/leaks/gtp_opt_header.test +++ /dev/null @@ -1,16 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/tunnels/gtp/gtp6_gtp_0x32.pcap %INPUT >out -# @TEST-EXEC: btest-bg-wait 90 - -# Some GTPv1 headers have some optional fields totaling to a 4-byte extension -# of the mandatory header. - -event gtpv1_g_pdu_packet(outer: connection, inner_gtp: gtpv1_hdr, inner_ip: pkt_hdr) - { - print "gtpv1_packet", inner_gtp; - } diff --git a/testing/btest/core/leaks/hook.zeek b/testing/btest/core/leaks/hook.zeek deleted file mode 100644 index 039d830bb8..0000000000 --- a/testing/btest/core/leaks/hook.zeek +++ /dev/null @@ -1,101 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -type rec: record { - a: count; - b: string; -}; - -global myhook: hook(r: rec); -global myhook2: hook(s: string); -# a hook doesn't have to take any arguments -global myhook4: hook(); - -hook myhook(r: rec) &priority=5 - { - print "myhook, &priority=5", r; - # break statement short-circuits the hook handling chain. - break; - print "ERROR: break statement should return from hook handler body"; - } - -hook myhook(r: rec) - { - # This handler shouldn't execute ever because of the handler at priority=5 - # exiting the body from a "break" statement. - print "myhook, &priority=0", rec; - } - -hook myhook(r: rec) &priority=10 - { - print "myhook, &priority=10", r; - # modifications to the record argument will be seen by remaining handlers. - r$a = 37; - r$b = "goobye world"; - # returning from the handler early, is fine, remaining handlers still run. - return; - print "ERROR: return statement should return from hook handler body"; - } - -hook myhook(r: rec) &priority=9 - { - print "myhook return F"; - # return value is ignored, remaining handlers still run, final return - # value is whether any hook body returned via break statement - return F; - print "ERROR: return statement should return from hook handler body"; - } - -hook myhook(r: rec) &priority=8 - { - print "myhook return T"; - # return value is ignored, remaining handlers still run, final return - # value is whether any hook body returned via break statement - return T; - print "ERROR: return statement should return from hook handler body"; - } - -# hook function doesn't need a declaration, we can go straight to defining -# a handler body. -hook myhook3(i: count) - { - print "myhook3", i; - } - -hook myhook4() &priority=1 - { - print "myhook4", 1; - } - -hook myhook4() &priority=2 - { - print "myhook4", 2; - } - -event new_connection(c: connection) - { - print "new_connection", c$id; - - print hook myhook([$a=1156, $b="hello world"]); - - # A hook with no handlers is fine, it's just a no-op. - print hook myhook2("nope"); - - print hook myhook3(8); - print hook myhook4(); - if ( hook myhook4() ) - { - print "myhook4 all handlers ran"; - } - - # A hook can be treated like other data types and doesn't have to be - # invoked directly by name. - local h = myhook; - print hook h([$a=2, $b="it works"]); - } diff --git a/testing/btest/core/leaks/http-connect.zeek b/testing/btest/core/leaks/http-connect.zeek deleted file mode 100644 index 60de095030..0000000000 --- a/testing/btest/core/leaks/http-connect.zeek +++ /dev/null @@ -1,14 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/http/connect-with-smtp.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/conn -@load base/protocols/http -@load base/protocols/smtp -@load base/protocols/tunnels -@load base/frameworks/dpd diff --git a/testing/btest/core/leaks/incr-vec-expr.test b/testing/btest/core/leaks/incr-vec-expr.test deleted file mode 100644 index c562c7c3ed..0000000000 --- a/testing/btest/core/leaks/incr-vec-expr.test +++ /dev/null @@ -1,36 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/chksums/ip4-udp-good-chksum.pcap %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -type rec: record { - a: count; - b: string; - c: vector of count; -}; - -global vec: vector of count = vector(0,0,0); - -global v: rec = [$a=0, $b="test", $c=vector(1,2,3)]; - -event new_connection(c: connection) - { - print vec; - print v; - - ++vec; - - print vec; - - ++v$a; - - print v; - - ++v$c; - - print v; - } diff --git a/testing/btest/core/leaks/input-basic.zeek b/testing/btest/core/leaks/input-basic.zeek deleted file mode 100644 index 773cedfe1f..0000000000 --- a/testing/btest/core/leaks/input-basic.zeek +++ /dev/null @@ -1,67 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef exit_only_after_terminate = T; - -@TEST-START-FILE input.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve ns -#types bool int enum count port subnet addr double time interval string table table table vector vector string -T -42 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY 4242 -@TEST-END-FILE - -@load base/protocols/ssh - -global outfile: file; - -redef InputAscii::empty_field = "EMPTY"; - -module A; - -type Idx: record { - i: int; -}; - -type Val: record { - b: bool; - e: Log::ID; - c: count; - p: port; - sn: subnet; - a: addr; - d: double; - t: time; - iv: interval; - s: string; - ns: string; - sc: set[count]; - ss: set[string]; - se: set[string]; - vc: vector of int; - ve: vector of int; -}; - -global servers: table[int] of Val = table(); - -event zeek_init() - { - outfile = open("../out"); - # first read in the old stuff into the table... - Input::add_table([$source="../input.log", $name="ssh", $idx=Idx, $val=Val, $destination=servers]); - } - -event Input::end_of_data(name: string, source:string) - { - print outfile, servers; - print outfile, to_count(servers[-42]$ns); # try to actually use a string. If null-termination is wrong this will fail. - Input::remove("ssh"); - close(outfile); - terminate(); - } diff --git a/testing/btest/core/leaks/input-errors.zeek b/testing/btest/core/leaks/input-errors.zeek deleted file mode 100644 index e5d4aafa47..0000000000 --- a/testing/btest/core/leaks/input-errors.zeek +++ /dev/null @@ -1,196 +0,0 @@ -# Needs perftools support. -# Test different kinds of errors of the input framework -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@TEST-START-FILE input.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve ns -#types bool int enum count port subnet addr double time interval string table table table vector vector string -T -42 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY 4242 -@TEST-END-FILE - -redef Input::accept_unsupported_types = T; - -redef exit_only_after_terminate = T; - -module Test; - -global outfile: file; - -type Idx: record { - c: count; -}; - -type Idx2: record { - c: count; - i: int; -}; - -type FileVal: record { - i: int; - s: file; -}; - -type Val: record { - i: int; - s: string; - a: addr; -}; - -type OptionalRecordVal: record { - i: int; - r: FileVal &optional; -}; - -type OptionalFileVal: record { - i: int; - s: file &optional; -}; - -global file_table: table[count] of FileVal = table(); -global optional_file_table: table[count] of OptionalFileVal = table(); -global record_table: table[count] of OptionalRecordVal = table(); -global string_table: table[string] of OptionalRecordVal = table(); - -global val_table: table[count] of Val = table(); -global val_table2: table[count, int] of Val = table(); -global val_table3: table[count, int] of int = table(); -global val_table4: table[count] of int; - -event line_file(description: Input::EventDescription, tpe: Input::Event, r:FileVal) - { - print outfile, description$name; - print outfile, r; - } - -event optional_line_file(description: Input::EventDescription, tpe: Input::Event, r:OptionalFileVal) - { - print outfile, description$name; - print outfile, r; - } - -event line_record(description: Input::EventDescription, tpe: Input::Event, r: OptionalRecordVal) - { - print outfile, description$name; - print outfile, r; - } - -event event1(description: Input::EventDescription, tpe: Input::Event, r: OptionalRecordVal, r2: OptionalRecordVal) - { - } - -event event2(description: Input::TableDescription, tpe: string, r: OptionalRecordVal, r2: OptionalRecordVal) - { - } - -event event3(description: Input::TableDescription, tpe: Input::Event, r: OptionalRecordVal, r2: OptionalRecordVal) - { - } - -event event4(description: Input::TableDescription, tpe: Input::Event, r: Idx, r2: OptionalRecordVal) - { - } - -event event5(description: Input::EventDescription, tpe: string, r: OptionalRecordVal, r2: OptionalRecordVal) - { - } - -event event6(description: Input::EventDescription, tpe: Input::Event, r: OptionalRecordVal) - { - } - -event event7(description: Input::EventDescription, tpe: Input::Event, r: OptionalRecordVal, r2:OptionalRecordVal) - { - } - -event event8(description: Input::EventDescription, tpe: Input::Event, i: int, s:string, a:string) - { - } - -event event9(description: Input::EventDescription, tpe: Input::Event, i: int, s:string, a:addr, ii: int) - { - } - -event event10(description: Input::TableDescription, tpe: Input::Event, i: Idx, c: count) - { - } - -# these are legit to test the error events -event event11(description: Input::EventDescription, tpe: Input::Event, v: Val) - { - } - -event errorhandler1(desc: Input::TableDescription, msg: string, level: Reporter::Level) - { - } - -event errorhandler2(desc: Input::EventDescription, msg: string, level: Reporter::Level) - { - } - -event errorhandler3(desc: string, msg: string, level: Reporter::Level) - { - } - -event errorhandler4(desc: Input::EventDescription, msg: count, level: Reporter::Level) - { - } - -event errorhandler5(desc: Input::EventDescription, msg: string, level: count) - { - } - -event kill_me() - { - terminate(); - } - -event zeek_init() - { - outfile = open("out"); - Input::add_event([$source="input.log", $name="file", $fields=FileVal, $ev=line_file, $want_record=T]); - Input::add_event([$source="input.log", $name="optionalrecord", $fields=OptionalRecordVal, $ev=line_record, $want_record=T]); - Input::add_event([$source="input.log", $name="optionalfile", $fields=OptionalFileVal, $ev=optional_line_file, $want_record=T]); - Input::add_table([$source="input.log", $name="filetable", $idx=Idx, $val=FileVal, $destination=file_table]); - Input::add_table([$source="input.log", $name="optionalrecordtable", $idx=Idx, $val=OptionalRecordVal, $destination=record_table]); - Input::add_table([$source="input.log", $name="optionalfiletable", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table]); - Input::add_table([$source="input.log", $name="optionalfiletable", $idx=Idx, $val=OptionalFileVal, $destination=record_table]); - Input::add_table([$source="input.log", $name="optionalfiletable2", $idx=Idx, $val=OptionalFileVal, $destination=string_table]); - Input::add_table([$source="input.log", $name="optionalfiletable3", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=terminate]); - Input::add_table([$source="input.log", $name="optionalfiletable3", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=kill_me]); - Input::add_table([$source="input.log", $name="optionalfiletable4", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=event1]); - Input::add_table([$source="input.log", $name="optionalfiletable5", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=event2]); - Input::add_table([$source="input.log", $name="optionalfiletable6", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=event3]); - Input::add_table([$source="input.log", $name="optionalfiletable7", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=event4]); - Input::add_table([$source="input.log", $name="optionalfiletable8", $idx=Idx, $val=Val, $destination=val_table4, $want_record=F]); - Input::add_table([$source="input.log", $name="optionalfiletable9", $idx=Idx2, $val=Val, $destination=val_table, $want_record=F]); - Input::add_table([$source="input.log", $name="optionalfiletable10", $idx=Idx, $val=Val, $destination=val_table2, $want_record=F]); - Input::add_table([$source="input.log", $name="optionalfiletable11", $idx=Idx2, $val=Idx, $destination=val_table3, $want_record=F]); - Input::add_table([$source="input.log", $name="optionalfiletable12", $idx=Idx2, $val=Idx, $destination=val_table2, $want_record=F]); - Input::add_table([$source="input.log", $name="optionalfiletable14", $idx=Idx, $val=OptionalFileVal, $destination=optional_file_table, $ev=event10, $want_record=F]); - Input::add_table([$source="input.log", $name="optionalfiletable15", $idx=Idx2, $val=Idx, $destination=val_table2, $want_record=T]); - Input::add_event([$source="input.log", $name="event1", $fields=OptionalFileVal, $ev=terminate, $want_record=T]); - Input::add_event([$source="input.log", $name="event2", $fields=OptionalFileVal, $ev=kill_me, $want_record=T]); - Input::add_event([$source="input.log", $name="event3", $fields=OptionalFileVal, $ev=event3, $want_record=T]); - Input::add_event([$source="input.log", $name="event4", $fields=OptionalFileVal, $ev=event5, $want_record=T]); - Input::add_event([$source="input.log", $name="event5", $fields=OptionalFileVal, $ev=event6, $want_record=T]); - Input::add_event([$source="input.log", $name="event6", $fields=OptionalFileVal, $ev=event7, $want_record=T]); - Input::add_event([$source="input.log", $name="event7", $fields=OptionalFileVal, $ev=event7, $want_record=F]); - Input::add_event([$source="input.log", $name="event8", $fields=Val, $ev=event8, $want_record=F]); - Input::add_event([$source="input.log", $name="event9", $fields=Val, $ev=event9, $want_record=F]); - - Input::add_event([$source="input.log", $name="error1", $fields=Val, $ev=event11, $want_record=T, $error_ev=errorhandler1]); - Input::add_table([$source="input.log", $name="error2", $idx=Idx, $val=Val, $destination=val_table, $error_ev=errorhandler2]); - Input::add_event([$source="input.log", $name="error3", $fields=Val, $ev=event11, $want_record=T, $error_ev=errorhandler3]); - Input::add_event([$source="input.log", $name="error4", $fields=Val, $ev=event11, $want_record=T, $error_ev=errorhandler4]); - Input::add_event([$source="input.log", $name="error5", $fields=Val, $ev=event11, $want_record=T, $error_ev=errorhandler5]); - - schedule 3secs { kill_me() }; - } diff --git a/testing/btest/core/leaks/input-missing-enum.zeek b/testing/btest/core/leaks/input-missing-enum.zeek deleted file mode 100644 index 589b9e5cc6..0000000000 --- a/testing/btest/core/leaks/input-missing-enum.zeek +++ /dev/null @@ -1,41 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@TEST-START-FILE input.log -#fields e i -IdoNot::Exist 1 -@TEST-END-FILE - -redef exit_only_after_terminate = T; - -module A; - -type Idx: record { - i: int; -}; - -type Val: record { - e: Log::ID; -}; - -global etable: table[int] of Log::ID = table(); - -event zeek_init() - { - # first read in the old stuff into the table... - Input::add_table([$source="../input.log", $name="enum", $idx=Idx, $val=Val, $destination=etable, $want_record=F]); - } - -event Input::end_of_data(name: string, source:string) - { - print "Table:"; - print etable; - Input::remove("enum"); - terminate(); - } diff --git a/testing/btest/core/leaks/input-optional-event.zeek b/testing/btest/core/leaks/input-optional-event.zeek deleted file mode 100644 index 92c4c4dc19..0000000000 --- a/testing/btest/core/leaks/input-optional-event.zeek +++ /dev/null @@ -1,65 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@TEST-START-FILE input.log -#separator \x09 -#path ssh -#fields i b r.a r.b r.c -#types int bool string string string -1 T a b c -2 T a b c -3 F ba bb bc -4 T bb bd - -5 F a b c -6 T a b c -7 T a b c -@TEST-END-FILE - -redef exit_only_after_terminate = T; - -global outfile: file; - -redef InputAscii::empty_field = "EMPTY"; - -module A; - -type Sub: record { - a: string; - aa: string &optional; - b : string; - bb: string &optional; - c: string &optional; - d: string &optional; -}; - -type Val: record { - i: int; - b: bool; - notb: bool &optional; - r: Sub; -}; - -event servers(desc: Input::EventDescription, tpe: Input::Event, item: Val) - { - print outfile, item; - } - -event zeek_init() - { - outfile = open("../out"); - # first read in the old stuff into the table... - Input::add_event([$source="../input.log", $name="input", $fields=Val, $ev=servers]); - } - -event Input::end_of_data(name: string, source: string) - { - Input::remove("input"); - close(outfile); - terminate(); - } diff --git a/testing/btest/core/leaks/input-optional-table.zeek b/testing/btest/core/leaks/input-optional-table.zeek deleted file mode 100644 index e73bd1b234..0000000000 --- a/testing/btest/core/leaks/input-optional-table.zeek +++ /dev/null @@ -1,68 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@TEST-START-FILE input.log -#separator \x09 -#path ssh -#fields i b r.a r.b r.c -#types int bool string string string -1 T a b c -2 T a b c -3 F ba bb bc -4 T bb bd - -5 T a b c -6 F a b c -7 T a b c -@TEST-END-FILE - -redef exit_only_after_terminate = T; - -global outfile: file; - -redef InputAscii::empty_field = "EMPTY"; - -module A; - -type Sub: record { - a: string; - aa: string &optional; - b : string; - bb: string &optional; - c: string &optional; - d: string &optional; -}; - -type Idx: record { - i: int; -}; - -type Val: record { - b: bool; - notb: bool &optional; - r: Sub; -}; - -global servers: table[int] of Val = table(); - -event zeek_init() - { - outfile = open("../out"); - # first read in the old stuff into the table... - Input::add_table([$source="../input.log", $name="input", $idx=Idx, $val=Val, $destination=servers, - $pred(typ: Input::Event, left: Idx, right: Val) = { right$notb = !right$b; return T; } - ]); - } - -event Input::end_of_data(name: string, source: string) - { - print outfile, servers; - Input::remove("input"); - close(outfile); - terminate(); - } diff --git a/testing/btest/core/leaks/input-patterns.zeek b/testing/btest/core/leaks/input-patterns.zeek deleted file mode 100644 index 37b37458d1..0000000000 --- a/testing/btest/core/leaks/input-patterns.zeek +++ /dev/null @@ -1,52 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef exit_only_after_terminate = T; - -@TEST-START-FILE input.log -#separator \x09 -#fields i p -#types count pattern -1 /dog/ -2 /cat/ -3 /foo|bar/ -4 /^oob/ -@TEST-END-FILE - -global outfile: file; - -module A; - -type Idx: record { - i: int; -}; - -type Val: record { - p: pattern; -}; - -global pats: table[int] of Val = table(); - -event zeek_init() - { - outfile = open("../out"); - # first read in the old stuff into the table... - Input::add_table([$source="../input.log", $name="pats", $idx=Idx, $val=Val, $destination=pats]); - } - -event Input::end_of_data(name: string, source:string) - { - print outfile, (pats[3]$p in "foobar"); # T - print outfile, (pats[4]$p in "foobar"); # F - print outfile, (pats[3]$p == "foo"); # T - print outfile, pats; - Input::remove("pats"); - close(outfile); - terminate(); - } diff --git a/testing/btest/core/leaks/input-raw.zeek b/testing/btest/core/leaks/input-raw.zeek deleted file mode 100644 index 5b8e19c733..0000000000 --- a/testing/btest/core/leaks/input-raw.zeek +++ /dev/null @@ -1,72 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: cp input1.log input.log -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: $SCRIPTS/wait-for-file zeek/got2 90 || (btest-bg-wait -k 1 && false) -# @TEST-EXEC: cat input2.log >> input.log -# @TEST-EXEC: $SCRIPTS/wait-for-file zeek/got6 30 || (btest-bg-wait -k 1 && false) -# @TEST-EXEC: cat input3.log >> input.log -# @TEST-EXEC: btest-bg-wait 120 - -redef exit_only_after_terminate = T; - -@TEST-START-FILE input1.log -sdfkh:KH;fdkncv;ISEUp34:Fkdj;YVpIODhfDF -@TEST-END-FILE - -@TEST-START-FILE input2.log -DSF"DFKJ"SDFKLh304yrsdkfj@#(*U$34jfDJup3UF -q3r3057fdf -@TEST-END-FILE - -@TEST-START-FILE input3.log -sdfs\d - -dfsdf -sdf -3rw43wRRERLlL#RWERERERE. -@TEST-END-FILE - - -module A; - -type Val: record { - s: string; -}; - -global try: count; -global outfile: file; - -event line(description: Input::EventDescription, tpe: Input::Event, s: string) - { - print outfile, description$name; - print outfile, tpe; - print outfile, s; - - try = try + 1; - - if ( try == 2 ) - system("touch got2"); - else if ( try == 6 ) - system("touch got6"); - else if ( try == 16 ) - { - print outfile, "done"; - close(outfile); - Input::remove("input"); - Input::remove("tail"); - terminate(); - } - } - -event zeek_init() - { - outfile = open("../out"); - try = 0; - Input::add_event([$source="../input.log", $reader=Input::READER_RAW, $mode=Input::STREAM, $name="input", $fields=Val, $ev=line, $want_record=F]); - Input::add_event([$source="tail -f ../input.log |", $reader=Input::READER_RAW, $mode=Input::STREAM, $name="tail", $fields=Val, $ev=line, $want_record=F]); - } diff --git a/testing/btest/core/leaks/input-reread.zeek b/testing/btest/core/leaks/input-reread.zeek deleted file mode 100644 index dd5dda333d..0000000000 --- a/testing/btest/core/leaks/input-reread.zeek +++ /dev/null @@ -1,164 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: cp input1.log input.log -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: $SCRIPTS/wait-for-file zeek/got2 90 || (btest-bg-wait -k 1 && false) -# @TEST-EXEC: cp input2.log input.log -# @TEST-EXEC: $SCRIPTS/wait-for-file zeek/got4 20 || (btest-bg-wait -k 1 && false) -# @TEST-EXEC: cp input3.log input.log -# @TEST-EXEC: $SCRIPTS/wait-for-file zeek/got6 20 || (btest-bg-wait -k 1 && false) -# @TEST-EXEC: cp input4.log input.log -# @TEST-EXEC: $SCRIPTS/wait-for-file zeek/got8 20 || (btest-bg-wait -k 1 && false) -# @TEST-EXEC: cp input5.log input.log -# @TEST-EXEC: btest-bg-wait 150 - -@TEST-START-FILE input1.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve r.a r.b -#types bool int enum count port subnet addr double time interval string table table table vector vector string string -T -42 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortytwo - -@TEST-END-FILE -@TEST-START-FILE input2.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve r.a r.b -#types bool int enum count port subnet addr double time interval string table table table vector vector string string -T -42 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortytwo - -T -43 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortythree 43 -@TEST-END-FILE -@TEST-START-FILE input3.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve r.a r.b -#types bool int enum count port subnet addr double time interval string table table table vector vector string string -T -42 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortytwo - -F -43 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortythree 43 -@TEST-END-FILE -@TEST-START-FILE input4.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve r.a r.b r.d -#types bool int enum count port subnet addr double time interval string table table table vector vector string string string -T -42 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortytwo - - -F -43 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortythree 43 - -F -44 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fortyfour - - -F -45 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fourtyfive - - -F -46 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fourtysix - - -F -47 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fourtyseven - - -F -48 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fourtyeight 48 f -@TEST-END-FILE -@TEST-START-FILE input5.log -#separator \x09 -#path ssh -#fields b i e c p sn a d t iv s sc ss se vc ve r.a r.b r.d -#types bool int enum count port subnet addr double time interval string table table table vector vector string string string -F -48 SSH::LOG 21 123 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY fourtyeight 48 f -@TEST-END-FILE - -@load base/protocols/ssh - -redef exit_only_after_terminate = T; -redef InputAscii::empty_field = "EMPTY"; - -module A; - -type Sub: record { - a: string; - b: string &optional; - c: string &optional; - d: string &optional; -}; - -type Idx: record { - i: int; -}; - -type Val: record { - b: bool; - e: Log::ID; - c: count; - p: port; - sn: subnet; - a: addr; - d: double; - t: time; - iv: interval; - s: string; - sc: set[count]; - ss: set[string]; - se: set[string]; - vc: vector of int; - ve: vector of int; - r: Sub; -}; - -global servers: table[int] of Val = table(); - -global outfile: file; - -global try: count; - -event servers_ev(description: Input::EventDescription, tpe: Input::Event, item: Val) - { - print outfile, "============EVENT EVENT============"; - print outfile, item; - } - -event line(description: Input::TableDescription, tpe: Input::Event, left: Idx, right: Val) - { - print outfile, "============TABLE EVENT============"; - print outfile, "Left"; - print outfile, left; - print outfile, "Right"; - print outfile, right; - } - -event zeek_init() - { - outfile = open("../out"); - try = 0; - # first read in the old stuff into the table... - Input::add_table([$source="../input.log", $mode=Input::REREAD, $name="ssh", $idx=Idx, $val=Val, $destination=servers, $ev=line, - $pred(typ: Input::Event, left: Idx, right: Val) = { - print outfile, "============PREDICATE============"; - print outfile, left; - print outfile, right; - return T; - } - ]); - Input::add_event([$source="../input.log", $mode=Input::REREAD, $name="sshevent", $fields=Val, $ev=servers_ev]); - } - - -event Input::end_of_data(name: string, source: string) - { - if ( name == "ssh" ) { - print outfile, "==========SERVERS============"; - print outfile, servers; - } else { - print outfile, "==========END OF EVENTS EVENTS==========="; - } - - try = try + 1; - - if ( try == 2 ) - system("touch got2"); - else if ( try == 4 ) - system("touch got4"); - else if ( try == 6 ) - system("touch got6"); - else if ( try == 8 ) - system("touch got8"); - else if ( try == 10 ) - { - print outfile, "done"; - close(outfile); - Input::remove("input"); - terminate(); - } - } diff --git a/testing/btest/core/leaks/input-sqlite.zeek b/testing/btest/core/leaks/input-sqlite.zeek deleted file mode 100644 index 50d9399a88..0000000000 --- a/testing/btest/core/leaks/input-sqlite.zeek +++ /dev/null @@ -1,105 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# @TEST-REQUIRES: which sqlite3 -# -# @TEST-EXEC: cat conn.sql | sqlite3 conn.sqlite -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@TEST-START-FILE conn.sql -PRAGMA foreign_keys=OFF; -BEGIN TRANSACTION; -CREATE TABLE conn ( -'ts' double precision, -'uid' text, -'id.orig_h' text, -'id.orig_p' integer, -'id.resp_h' text, -'id.resp_p' integer, -'proto' text, -'service' text, -'duration' double precision, -'orig_bytes' integer, -'resp_bytes' integer, -'conn_state' text, -'local_orig' boolean, -'local_resp' boolean, -'missed_bytes' integer, -'history' text, -'orig_pkts' integer, -'orig_ip_bytes' integer, -'resp_pkts' integer, -'resp_ip_bytes' integer, -'tunnel_parents' text -); -INSERT INTO "conn" VALUES(1.30047516709653496744e+09,'dnGM1AdIVyh','141.142.220.202',5353,'224.0.0.251',5353,'udp','dns',NULL,NULL,NULL,'S0',NULL,NULL,0,'D',1,73,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516709701204296e+09,'fv9q7WjEgp1','fe80::217:f2ff:fed7:cf65',5353,'ff02::fb',5353,'udp',NULL,NULL,NULL,NULL,'S0',NULL,NULL,0,'D',1,199,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516709981608392e+09,'0Ox0H56yl88','141.142.220.50',5353,'224.0.0.251',5353,'udp',NULL,NULL,NULL,NULL,'S0',NULL,NULL,0,'D',1,179,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885389900212e+09,'rvmSc7rDQub','141.142.220.118',43927,'141.142.2.2',53,'udp','dns',4.351139068603515625e-04,38,89,'SF',NULL,NULL,0,'Dd',1,66,1,117,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885437798497e+09,'ogkztouSArh','141.142.220.118',37676,'141.142.2.2',53,'udp','dns',4.20093536376953125e-04,52,99,'SF',NULL,NULL,0,'Dd',1,80,1,127,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885483694076e+09,'0UIDdXFt7Tb','141.142.220.118',40526,'141.142.2.2',53,'udp','dns',3.9196014404296875e-04,38,183,'SF',NULL,NULL,0,'Dd',1,66,1,211,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885795593258e+09,'WqFYV51UIq7','141.142.220.118',32902,'141.142.2.2',53,'udp','dns',3.17096710205078125e-04,38,89,'SF',NULL,NULL,0,'Dd',1,66,1,117,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885830593104e+09,'ylcqZpbz6K2','141.142.220.118',59816,'141.142.2.2',53,'udp','dns',3.430843353271484375e-04,52,99,'SF',NULL,NULL,0,'Dd',1,80,1,127,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885871291159e+09,'blhldTzA7Y6','141.142.220.118',59714,'141.142.2.2',53,'udp','dns',3.750324249267578125e-04,38,183,'SF',NULL,NULL,0,'Dd',1,66,1,211,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889164400098e+09,'Sc34cGJo3Kg','141.142.220.118',58206,'141.142.2.2',53,'udp','dns',3.39031219482421875e-04,38,89,'SF',NULL,NULL,0,'Dd',1,66,1,117,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889203691487e+09,'RzvFrfXSRfk','141.142.220.118',38911,'141.142.2.2',53,'udp','dns',3.349781036376953125e-04,52,99,'SF',NULL,NULL,0,'Dd',1,80,1,127,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889241409298e+09,'GaaFI58mpbe','141.142.220.118',59746,'141.142.2.2',53,'udp','dns',4.208087921142578125e-04,38,183,'SF',NULL,NULL,0,'Dd',1,66,1,211,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889398789407e+09,'tr7M6tvAIQa','141.142.220.118',45000,'141.142.2.2',53,'udp','dns',3.840923309326171875e-04,38,89,'SF',NULL,NULL,0,'Dd',1,66,1,117,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889442205426e+09,'gV0TcSc2pb4','141.142.220.118',48479,'141.142.2.2',53,'udp','dns',3.168582916259765625e-04,52,99,'SF',NULL,NULL,0,'Dd',1,80,1,127,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889478707315e+09,'MOG0z4PYOhk','141.142.220.118',48128,'141.142.2.2',53,'udp','dns',4.22954559326171875e-04,38,183,'SF',NULL,NULL,0,'Dd',1,66,1,211,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516890174889565e+09,'PlehgEduUyj','141.142.220.118',56056,'141.142.2.2',53,'udp','dns',4.022121429443359375e-04,36,131,'SF',NULL,NULL,0,'Dd',1,64,1,159,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516890219497676e+09,'4eZgk09f2Re','141.142.220.118',55092,'141.142.2.2',53,'udp','dns',3.740787506103515625e-04,36,198,'SF',NULL,NULL,0,'Dd',1,64,1,226,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516989943790432e+09,'3xwJPc7mQ9a','141.142.220.44',5353,'224.0.0.251',5353,'udp','dns',NULL,NULL,NULL,'S0',NULL,NULL,0,'D',1,85,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047517086238408089e+09,'yxTcvvTKWQ4','141.142.220.226',137,'141.142.220.255',137,'udp','dns',2.61301684379577636718e+00,350,0,'S0',NULL,NULL,0,'D',7,546,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047517167537188525e+09,'8bLW3XNfhCj','fe80::3074:17d5:2052:c324',65373,'ff02::1:3',5355,'udp','dns',1.00096225738525390625e-01,66,0,'S0',NULL,NULL,0,'D',2,162,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047517167708110807e+09,'rqjhiiRPjEe','141.142.220.226',55131,'224.0.0.252',5355,'udp','dns',1.00020885467529296875e-01,66,0,'S0',NULL,NULL,0,'D',2,122,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047517311674904827e+09,'hTPyfL3QSGa','fe80::3074:17d5:2052:c324',54213,'ff02::1:3',5355,'udp','dns',9.980106353759765625e-02,66,0,'S0',NULL,NULL,0,'D',2,162,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047517311736202235e+09,'EruUQ9AJRj4','141.142.220.226',55671,'224.0.0.252',5355,'udp','dns',9.98489856719970703125e-02,66,0,'S0',NULL,NULL,0,'D',2,122,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047517315367889406e+09,'sw1bKJOMjuk','141.142.220.238',56641,'141.142.220.255',137,'udp','dns',NULL,NULL,NULL,'S0',NULL,NULL,0,'D',1,78,0,0,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516872400689127e+09,'NPHCuyWykE7','141.142.220.118',48649,'208.80.152.118',80,'tcp','http',1.19904994964599609375e-01,525,232,'S1',NULL,NULL,0,'ShADad',4,741,3,396,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889293599126e+09,'VapPqRhPgJ4','141.142.220.118',50000,'208.80.152.3',80,'tcp','http',2.29603052139282226562e-01,1148,734,'S1',NULL,NULL,0,'ShADad',6,1468,4,950,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885916304588e+09,'3607hh8C3bc','141.142.220.118',49998,'208.80.152.3',80,'tcp','http',2.15893030166625976562e-01,1130,734,'S1',NULL,NULL,0,'ShADad',6,1450,4,950,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516885530495647e+09,'tgYMrIvzDSg','141.142.220.118',49996,'208.80.152.3',80,'tcp','http',2.1850109100341796875e-01,1171,733,'S1',NULL,NULL,0,'ShADad',6,1491,4,949,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516889526700977e+09,'xQsjPwNBrXd','141.142.220.118',50001,'208.80.152.3',80,'tcp','http',2.27283954620361328125e-01,1178,734,'S1',NULL,NULL,0,'ShADad',6,1498,4,950,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516890263509747e+09,'Ap3GzMI1vM9','141.142.220.118',35642,'208.80.152.2',80,'tcp','http',1.200408935546875e-01,534,412,'S1',NULL,NULL,0,'ShADad',4,750,3,576,'(empty)'); -INSERT INTO "conn" VALUES(1300475168.85533,'FTVcgrmNy52','141.142.220.118',49997,'208.80.152.3',80,'tcp','http',2.19720125198364257812e-01,1125,734,'S1',NULL,NULL,0,'ShADad',6,1445,4,950,'(empty)'); -INSERT INTO "conn" VALUES(1.30047516978033089643e+09,'1xFx4PGdeq5','141.142.220.235',6705,'173.192.163.128',80,'tcp',NULL,NULL,NULL,NULL,'OTH',NULL,NULL,0,'h',0,0,1,48,'(empty)'); -INSERT INTO "conn" VALUES(1.3004751686520030498e+09,'WIG1ud65z22','141.142.220.118',35634,'208.80.152.2',80,'tcp',NULL,6.1328887939453125e-02,463,350,'OTH',NULL,NULL,0,'DdA',2,567,1,402,'(empty)'); -INSERT INTO "conn" VALUES(1.3004751688929131031e+09,'o2gAkl4V7sa','141.142.220.118',49999,'208.80.152.3',80,'tcp','http',2.20960855484008789062e-01,1137,733,'S1',NULL,NULL,0,'ShADad',6,1457,4,949,'(empty)'); -COMMIT; -@TEST-END-FILE - -@load base/protocols/conn - -redef exit_only_after_terminate = T; -redef Input::accept_unsupported_types = T; - -global outfile: file; - -module A; - -event line(description: Input::EventDescription, tpe: Input::Event, r: Conn::Info) - { - print outfile, r; - print outfile, |r$tunnel_parents|; # to make sure I got empty right - } - -event zeek_init() - { - local config_strings: table[string] of string = { - ["query"] = "select * from conn;", - }; - - outfile = open("../out"); - Input::add_event([$source="../conn", $name="conn", $fields=Conn::Info, $ev=line, $want_record=T, $reader=Input::READER_SQLITE, $config=config_strings]); - } - -event Input::end_of_data(name: string, source:string) - { - print outfile, "End of data"; - close(outfile); - terminate(); - } diff --git a/testing/btest/core/leaks/input-with-remove.zeek b/testing/btest/core/leaks/input-with-remove.zeek deleted file mode 100644 index e19a4312fc..0000000000 --- a/testing/btest/core/leaks/input-with-remove.zeek +++ /dev/null @@ -1,63 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/frameworks/input - -redef exit_only_after_terminate = T; - -global c: count = 0; - - -type OneLine: record { - s: string; -}; - -event line(description: Input::EventDescription, tpe: Input::Event, s: string) - { - print "1", "Line"; - } - -event InputRaw::process_finished(name: string, source:string, exit_code:count, signal_exit:bool) - { - Input::remove(name); - print "2", name; - } - -function run(): count - { - Input::add_event([$name=unique_id(""), - $source=fmt("%s |", "date"), - $reader=Input::READER_RAW, - $mode=Input::STREAM, - $fields=OneLine, - $ev=line, - $want_record=F]); - - return 1; - } - - -event do() - { - run(); - } - -event do_term() { - terminate(); -} - -event zeek_init() { - schedule 1sec { - do() - }; - schedule 3sec { - do_term() - }; -} - diff --git a/testing/btest/core/leaks/ip-in-ip.test b/testing/btest/core/leaks/ip-in-ip.test deleted file mode 100644 index 96dfadc8a7..0000000000 --- a/testing/btest/core/leaks/ip-in-ip.test +++ /dev/null @@ -1,33 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek1 zeek -m -b -r $TRACES/tunnels/6in6.pcap %INPUT -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek2 zeek -m -b -r $TRACES/tunnels/6in6in6.pcap %INPUT -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek3 zeek -m -b -r $TRACES/tunnels/6in6-tunnel-change.pcap %INPUT -# @TEST-EXEC: btest-bg-wait 120 - -event new_connection(c: connection) - { - if ( c?$tunnel ) - { - print "new_connection: tunnel"; - print fmt(" conn_id: %s", c$id); - print fmt(" encap: %s", c$tunnel); - } - else - { - print "new_connection: no tunnel"; - } - } - -event tunnel_changed(c: connection, e: EncapsulatingConnVector) - { - print "tunnel_changed:"; - print fmt(" conn_id: %s", c$id); - if ( c?$tunnel ) - print fmt(" old: %s", c$tunnel); - print fmt(" new: %s", e); - } diff --git a/testing/btest/core/leaks/ipv6_ext_headers.test b/testing/btest/core/leaks/ipv6_ext_headers.test deleted file mode 100644 index 18e7dcb964..0000000000 --- a/testing/btest/core/leaks/ipv6_ext_headers.test +++ /dev/null @@ -1,37 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/ipv6-hbh-routing0.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -# Just check that the event is raised correctly for a packet containing -# extension headers. -event ipv6_ext_headers(c: connection, p: pkt_hdr) - { - print p; - } - -# Also check the weird for routing type 0 extensions headers -event flow_weird(name: string, src: addr, dst: addr, addl: string) - { - print fmt("weird %s from %s to %s", name, src, dst); - } - -# And the connection for routing type 0 packets with non-zero segments left -# should use the last address in that extension header. -event new_connection(c: connection) - { - print c$id; - } - -event ipv6_ext_headers(c: connection, p: pkt_hdr) - { - for ( h in p$ip6$exts ) - if ( p$ip6$exts[h]$id == IPPROTO_ROUTING ) - if ( p$ip6$exts[h]$routing$rtype == 0 ) - print routing0_data_to_addrs(p$ip6$exts[h]$routing$data); - } - diff --git a/testing/btest/core/leaks/irc.test b/testing/btest/core/leaks/irc.test deleted file mode 100644 index 3dce3a0ad2..0000000000 --- a/testing/btest/core/leaks/irc.test +++ /dev/null @@ -1,13 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/irc-dcc-send.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -event irc_names_info(c: connection, is_orig: bool, c_type: string, channel: string, users: string_set) - { - print channel, users; - } diff --git a/testing/btest/core/leaks/krb-service-name.test b/testing/btest/core/leaks/krb-service-name.test deleted file mode 100644 index 0263df5a60..0000000000 --- a/testing/btest/core/leaks/krb-service-name.test +++ /dev/null @@ -1,8 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/krb/optional-service-name.pcap -# @TEST-EXEC: btest-bg-wait 90 diff --git a/testing/btest/core/leaks/krb.test b/testing/btest/core/leaks/krb.test deleted file mode 100644 index cea492d196..0000000000 --- a/testing/btest/core/leaks/krb.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/krb/kinit.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/krb diff --git a/testing/btest/core/leaks/kv-iteration.zeek b/testing/btest/core/leaks/kv-iteration.zeek deleted file mode 100644 index c349a68d59..0000000000 --- a/testing/btest/core/leaks/kv-iteration.zeek +++ /dev/null @@ -1,22 +0,0 @@ -# @TEST-GROUP: leaks -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -event new_connection(c: connection) - { - local t: table[count] of string = table(); - t[1] = "hello"; - t[55] = "goodbye"; - - for (key, value in t) - print key, value; - - local tkk: table[string, string] of count = table(); - tkk["hello", "world"] = 1; - tkk["goodbye", "world"] = 55; - - for ([k1, k2], val in tkk) - print k1, k2, val; - } diff --git a/testing/btest/core/leaks/mysql.test b/testing/btest/core/leaks/mysql.test deleted file mode 100644 index 12d1ec897f..0000000000 --- a/testing/btest/core/leaks/mysql.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/mysql/mysql.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/mysql diff --git a/testing/btest/core/leaks/paraglob.zeek b/testing/btest/core/leaks/paraglob.zeek deleted file mode 100644 index aac8c87038..0000000000 --- a/testing/btest/core/leaks/paraglob.zeek +++ /dev/null @@ -1,34 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 120 - -event new_connection (c : connection) -{ - local v1 = vector("*", "d?g", "*og", "d?", "d[!wl]g"); - local v2 = vector("once", "!o*", "once"); - local v3 = vector("https://*.google.com/*", "*malware*", "*.gov*"); - - local p1 = paraglob_init(v1); - local p2: opaque of paraglob = paraglob_init(v2); - local p3 = paraglob_init(v3); - local p_eq = paraglob_init(v1); - - # paraglob_init should not modify v1 - print (v1 == vector("*", "d?g", "*og", "d?", "d[!wl]g")); - # p_eq and p1 should be the same paraglobs - print paraglob_equals(p_eq, p1); - - print paraglob_match(p1, "dog"); - - - print paraglob_match(p2, "once"); - print paraglob_match(p3, "www.strange-malware-domain.gov"); - - local large_glob: opaque of paraglob = paraglob_init(v3); - print paraglob_match(large_glob, "www.strange-malware-domain.gov"); -} diff --git a/testing/btest/core/leaks/pattern.zeek b/testing/btest/core/leaks/pattern.zeek deleted file mode 100644 index 1b14c6dd78..0000000000 --- a/testing/btest/core/leaks/pattern.zeek +++ /dev/null @@ -1,67 +0,0 @@ -# @TEST-GROUP: leaks -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -function test_case(msg: string, expect: bool) - { - print fmt("%s (%s)", msg, expect ? "PASS" : "FAIL"); - } - -event new_connection(c: connection) - { - print "new connection"; - - local p1: pattern = /foo|bar/; - local p2: pattern = /oob/; - local p3: pattern = /^oob/; - local p4 = /foo/; - - # Type inference tests - - test_case( "type inference", type_name(p4) == "pattern" ); - - # Operator tests - - test_case( "equality operator", "foo" == p1 ); - test_case( "equality operator (order of operands)", p1 == "foo" ); - test_case( "inequality operator", "foobar" != p1 ); - test_case( "inequality operator (order of operands)", p1 != "foobar" ); - test_case( "in operator", p1 in "foobar" ); - test_case( "in operator", p2 in "foobar" ); - test_case( "!in operator", p3 !in "foobar" ); - test_case( "& operator", p1 & p2 in "baroob" ); - test_case( "& operator", p2 & p1 in "baroob" ); - test_case( "| operator", p1 | p2 in "lazybarlazy" ); - test_case( "| operator", p3 | p4 in "xoob" ); - - test_case( "/i pattern modifier", /fOO/i in "xFoObar" ); - test_case( "/i pattern modifier", /fOO/i == "Foo" ); - - test_case( "/i double-quote escape", /"fOO"/i in "xFoObar" ); - test_case( "/i double-quote escape", /"fOO"/i in "xfOObar" ); - - test_case( "case-sensitive pattern", /fOO/ in "xFoObar" ); - test_case( "case-sensitive pattern", /fOO/ == "Foo" ); - test_case( "case-sensitive pattern", /fOO/ == "fOO" ); - - test_case( "/i pattern disjunction", /bar/i | /bez/ == "bez" ); - test_case( "/i pattern disjunction", /bar/i | /bez/ == "bEz" ); - test_case( "/i pattern disjunction", /bar/i | /bez/ == "bar" ); - test_case( "/i pattern disjunction", /bar/i | /bez/ == "bAr" ); - - test_case( "/i pattern concatenation", /bar/i & /bez/ == "barbez" ); - test_case( "/i pattern concatenation", /bar/i & /bez/ == "barbEz" ); - test_case( "/i pattern concatenation", /BAR/i & /bez/ == "barbEz" ); - test_case( "/i pattern concatenation", /bar/i & /bez/ == "bArbez" ); - test_case( "/i pattern concatenation", /BAR/i & /bez/ == "bArbez" ); - test_case( "/i pattern concatenation", /bar/i & /bez/ == "bArbEz" ); - - test_case( "/i pattern character class", /ba[0a-c99S-Z0]/i & /bEz/ == "bArbEz" ); - test_case( "/i pattern character class", /ba[0a-c99M-S0]/i & /bEz/ == "bArbEz" ); - - test_case( "(?i:...) pattern construct", /foo|(?i:bar)/ in "xBAry" ); - test_case( "(?i:...) pattern construct", /foo|(?i:bar)/ in "xFOoy" ); - test_case( "(?i:...) pattern construct", /foo|(?i:bar)/ | /foo/i in "xFOoy" ); - } diff --git a/testing/btest/core/leaks/pe.test b/testing/btest/core/leaks/pe.test deleted file mode 100644 index baca8b3217..0000000000 --- a/testing/btest/core/leaks/pe.test +++ /dev/null @@ -1,12 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/pe/pe.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/ftp -@load base/files/pe - diff --git a/testing/btest/core/leaks/print-log.zeek b/testing/btest/core/leaks/print-log.zeek deleted file mode 100644 index c37886e2cd..0000000000 --- a/testing/btest/core/leaks/print-log.zeek +++ /dev/null @@ -1,14 +0,0 @@ -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef Log::print_to_log = Log::REDIRECT_ALL; - -event new_connection(c: connection) - { - print "hello world ,"; - print 2,T; - } diff --git a/testing/btest/core/leaks/radius.test b/testing/btest/core/leaks/radius.test deleted file mode 100644 index 3eb5ac7b4e..0000000000 --- a/testing/btest/core/leaks/radius.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/radius/radius.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/radius diff --git a/testing/btest/core/leaks/returnwhen.zeek b/testing/btest/core/leaks/returnwhen.zeek deleted file mode 100644 index 8dc5bb3992..0000000000 --- a/testing/btest/core/leaks/returnwhen.zeek +++ /dev/null @@ -1,84 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: btest-bg-run zeek HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local zeek -m -b %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -redef exit_only_after_terminate = T; - -global my_set: set[string] = set(); -global flag: string = "flag"; -global done: bool = F; - -function dummyfunc(s: string): string - { - return "dummy " + s; - } - -function async_func(s: string): string - { - print dummyfunc("from async_func() " + s); - - return when ( flag in my_set ) - { - return flag + " in my_set"; - } - timeout 3sec - { - return "timeout"; - } - } - -event set_flag() - { - add my_set[flag]; - } - -event do_another() - { - delete my_set[flag]; - - local local_dummy = dummyfunc; - - local anon = function(s: string): string { return s + "!"; }; - - if ( ! done ) - schedule 1sec { set_flag() }; - - when ( local result = async_func("from do_another()") ) - { - print "async_func() return result in do_another()", result; - print local_dummy("from do_another() when block"); - print anon("hi"); - if ( result == "timeout" ) - terminate(); - else - { - done = T; - schedule 10msec { do_another() }; - } - } - } - -event zeek_init() - { - local local_dummy = dummyfunc; - - local anon = function(s: string): string { return s + "!"; }; - - schedule 1sec { set_flag() }; - - when ( local result = async_func("from zeek_init()") ) - { - print "async_func() return result in zeek_init()", result; - print local_dummy("from zeek_init() when block"); - print anon("hi"); - if ( result == "timeout" ) terminate(); - schedule 10msec { do_another() }; - } - } - - diff --git a/testing/btest/core/leaks/set.zeek b/testing/btest/core/leaks/set.zeek deleted file mode 100644 index 9b1c0b8f4a..0000000000 --- a/testing/btest/core/leaks/set.zeek +++ /dev/null @@ -1,194 +0,0 @@ -# @TEST-GROUP: leaks -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -function test_case(msg: string, expect: bool) - { - print fmt("%s (%s)", msg, expect ? "PASS" : "FAIL"); - } - -# Note: only global sets can be initialized with curly braces -global sg1: set[string] = { "curly", "braces" }; -global sg2: set[port, string, bool] = { [10/udp, "curly", F], - [11/udp, "braces", T] }; -global sg3 = { "more", "curly", "braces" }; - -global did_once = F; - -event new_connection(cc: connection) - { - if ( did_once ) - return; - - did_once = T; - - local s1: set[string] = set( "test", "example" ); - local s2: set[string] = set(); - local s3: set[string]; - local s4 = set( "type inference" ); - local s5: set[port, string, bool] = set( [1/tcp, "test", T], - [2/tcp, "example", F] ); - local s6: set[port, string, bool] = set(); - local s7: set[port, string, bool]; - local s8 = set( [8/tcp, "type inference", T] ); - - # Type inference tests - - test_case( "type inference", type_name(s4) == "set[string]" ); - test_case( "type inference", type_name(s8) == "set[port,string,bool]" ); - test_case( "type inference", type_name(sg3) == "set[string]" ); - - # Test the size of each set - - test_case( "cardinality", |s1| == 2 ); - test_case( "cardinality", |s2| == 0 ); - test_case( "cardinality", |s3| == 0 ); - test_case( "cardinality", |s4| == 1 ); - test_case( "cardinality", |s5| == 2 ); - test_case( "cardinality", |s6| == 0 ); - test_case( "cardinality", |s7| == 0 ); - test_case( "cardinality", |s8| == 1 ); - test_case( "cardinality", |sg1| == 2 ); - test_case( "cardinality", |sg2| == 2 ); - test_case( "cardinality", |sg3| == 3 ); - - # Test iterating over each set - - local ct: count; - ct = 0; - for ( c in s1 ) - { - if ( type_name(c) != "string" ) - print "Error: wrong set element type"; - ++ct; - } - test_case( "iterate over set", ct == 2 ); - - ct = 0; - for ( c in s2 ) - { - ++ct; - } - test_case( "iterate over set", ct == 0 ); - - ct = 0; - for ( [c1,c2,c3] in s5 ) - { - ++ct; - } - test_case( "iterate over set", ct == 2 ); - - ct = 0; - for ( [c1,c2,c3] in sg2 ) - { - ++ct; - } - test_case( "iterate over set", ct == 2 ); - - # Test adding elements to each set (Note: cannot add elements to sets - # of multiple types) - - add s1["added"]; - add s1["added"]; # element already exists (nothing happens) - test_case( "add element", |s1| == 3 ); - test_case( "in operator", "added" in s1 ); - - add s2["another"]; - test_case( "add element", |s2| == 1 ); - add s2["test"]; - test_case( "add element", |s2| == 2 ); - test_case( "in operator", "another" in s2 ); - test_case( "in operator", "test" in s2 ); - - add s3["foo"]; - test_case( "add element", |s3| == 1 ); - test_case( "in operator", "foo" in s3 ); - - add s4["local"]; - test_case( "add element", |s4| == 2 ); - test_case( "in operator", "local" in s4 ); - - add sg1["global"]; - test_case( "add element", |sg1| == 3 ); - test_case( "in operator", "global" in sg1 ); - - add sg3["more global"]; - test_case( "add element", |sg3| == 4 ); - test_case( "in operator", "more global" in sg3 ); - - # Test removing elements from each set (Note: cannot remove elements - # from sets of multiple types) - - delete s1["test"]; - delete s1["foobar"]; # element does not exist (nothing happens) - test_case( "remove element", |s1| == 2 ); - test_case( "!in operator", "test" !in s1 ); - - delete s2["test"]; - test_case( "remove element", |s2| == 1 ); - test_case( "!in operator", "test" !in s2 ); - - delete s3["foo"]; - test_case( "remove element", |s3| == 0 ); - test_case( "!in operator", "foo" !in s3 ); - - delete s4["type inference"]; - test_case( "remove element", |s4| == 1 ); - test_case( "!in operator", "type inference" !in s4 ); - - delete sg1["braces"]; - test_case( "remove element", |sg1| == 2 ); - test_case( "!in operator", "braces" !in sg1 ); - - delete sg3["curly"]; - test_case( "remove element", |sg3| == 3 ); - test_case( "!in operator", "curly" !in sg3 ); - - - local a = set(1,5,7,9,8,14); - local b = set(1,7,9,2); - - local a_plus_b = set(1,2,5,7,9,8,14); - local a_also_b = set(1,7,9); - local a_sans_b = set(5,8,14); - local b_sans_a = set(2); - - local a_or_b = a | b; - local a_and_b = a & b; - - test_case( "union", a_or_b == a_plus_b ); - test_case( "intersection", a_and_b == a_plus_b ); - test_case( "difference", a - b == a_sans_b ); - test_case( "difference", b - a == b_sans_a ); - - test_case( "union/inter.", |b & set(1,7,9,2)| == |b | set(1,7,2,9)| ); - test_case( "relational", |b & a_or_b| == |b| && |b| < |a_or_b| ); - test_case( "relational", b < a_or_b && a < a_or_b && a_or_b > a_and_b ); - - test_case( "subset", b < a ); - test_case( "subset", a < b ); - test_case( "subset", b < (a | set(2)) ); - test_case( "superset", b > a ); - test_case( "superset", b > (a | set(2)) ); - test_case( "superset", b | set(8, 14, 5) > (a | set(2)) ); - test_case( "superset", b | set(8, 14, 99, 5) > (a | set(2)) ); - - test_case( "non-ordering", (a <= b) || (a >= b) ); - test_case( "non-ordering", (a <= a_or_b) && (a_or_b >= b) ); - - test_case( "superset", (b | set(14, 5)) > a - set(8) ); - test_case( "superset", (b | set(14)) > a - set(8) ); - test_case( "superset", (b | set(14)) > a - set(8,5) ); - test_case( "superset", b >= a - set(5,8,14) ); - test_case( "superset", b > a - set(5,8,14) ); - test_case( "superset", (b - set(2)) > a - set(5,8,14) ); - test_case( "equality", a == a | set(5) ); - test_case( "equality", a == a | set(5,11) ); - test_case( "non-equality", a != a | set(5,11) ); - test_case( "equality", a == a | set(5,11) ); - - test_case( "magnitude", |a_and_b| == |a_or_b|); - } - diff --git a/testing/btest/core/leaks/sip.test b/testing/btest/core/leaks/sip.test deleted file mode 100644 index 5ce8a29210..0000000000 --- a/testing/btest/core/leaks/sip.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/sip/wireshark.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/sip diff --git a/testing/btest/core/leaks/smtp_attachment.test b/testing/btest/core/leaks/smtp_attachment.test deleted file mode 100644 index 8e11735327..0000000000 --- a/testing/btest/core/leaks/smtp_attachment.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/smtp.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/smtp diff --git a/testing/btest/core/leaks/snmp.test b/testing/btest/core/leaks/snmp.test deleted file mode 100644 index ee678dfc84..0000000000 --- a/testing/btest/core/leaks/snmp.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/snmp/snmpv1_get.pcap -r $TRACES/snmp/snmpv1_get_short.pcap -r $TRACES/snmp/snmpv1_set.pcap -r $TRACES/snmp/snmpv1_trap.pcap -r $TRACES/snmp/snmpv2_get_bulk.pcap -r $TRACES/snmp/snmpv2_get_next.pcap -r $TRACES/snmp/snmpv2_get.pcap -r $TRACES/snmp/snmpv3_get_next.pcap $SCRIPTS/snmp-test.zeek %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/snmp diff --git a/testing/btest/core/leaks/ssh.test b/testing/btest/core/leaks/ssh.test deleted file mode 100644 index 735e8b3e1d..0000000000 --- a/testing/btest/core/leaks/ssh.test +++ /dev/null @@ -1,10 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/ssh/ssh.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/ssh diff --git a/testing/btest/core/leaks/stats.zeek b/testing/btest/core/leaks/stats.zeek deleted file mode 100644 index 11c598ffc8..0000000000 --- a/testing/btest/core/leaks/stats.zeek +++ /dev/null @@ -1,15 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load policy/misc/stats - -event load_sample(samples: load_sample_info, CPU: interval, dmem: int) - { - print CPU; - } diff --git a/testing/btest/core/leaks/string-indexing.zeek b/testing/btest/core/leaks/string-indexing.zeek deleted file mode 100644 index 2f5982e2ec..0000000000 --- a/testing/btest/core/leaks/string-indexing.zeek +++ /dev/null @@ -1,27 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - - -event new_connection(c: connection) - { - local s = "0123456789"; - print s[1]; - print s[1:2]; - print s[1:6]; - print s[0:20]; - print s[-2]; - print s[-3:1]; - print s[-1:10]; - print s[-1:0]; - print s[-1:5]; - print s[20:23]; - print s[-20:23]; - print s[0:5][2]; - print s[0:5][1:3][0]; - } diff --git a/testing/btest/core/leaks/switch-statement.zeek b/testing/btest/core/leaks/switch-statement.zeek deleted file mode 100644 index c55fbe57b4..0000000000 --- a/testing/btest/core/leaks/switch-statement.zeek +++ /dev/null @@ -1,299 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -type MyEnum: enum { - RED, - GREEN, - BLUE, - PINK, -}; - -function switch_bool(v: bool): string - { - switch (v) { - case T: - return "true"; - case F: - return "false"; - } - return "n/a"; - } - -function switch_int(v: int): string - { - switch (v) { - case +1: - return "one"; - case +2: - return "two"; - case -3: - return "minus three"; - } - return "n/a"; - } - -function switch_enum(v: MyEnum): string - { - switch (v) { - case RED: - return "red"; - case GREEN: - return "green"; - case BLUE: - return "blue"; - } - return "n/a"; - } - -function switch_count(v: count): string - { - switch (v) { - case 1: - return "1"; - case 2: - return "2"; - case 3: - return "3"; - } - return "n/a"; - } - -function switch_port(v: port): string - { - switch (v) { - case 22/tcp: - return "ssh"; - case 53/udp: - return "dns"; - case 0/icmp: - return "echo"; - } - return "n/a"; - } - -function switch_double(v: double): string - { - switch (v) { - case 1.1: - return "1.1"; - case 2.2: - return "2.2"; - case 3.3: - return "3.3"; - } - return "n/a"; - } - -function switch_interval(v: interval): string - { - switch (v) { - case 1sec: - return "1sec"; - case 2day: - return "2day"; - case 3min: - return "3min"; - } - return "n/a"; - } - -function switch_string(v: string): string - { - switch (v) { - case "one": - return "first"; - case "two": - return "second"; - case "three": - return "third"; - } - return "n/a"; - } - -function switch_addr(v: addr): string - { - switch (v) { - case 1.2.3.4: - return "ipv4"; - case [fe80::1]: - return "ipv6"; - case 0.0.0.0: - return "unspec"; - } - return "n/a"; - } - -function switch_subnet(v: subnet): string - { - switch (v) { - case 1.2.3.0/24: - return "1.2.3.0/24"; - case [fe80::0]/96: - return "[fe80::0]"; - case 192.168.0.0/16: - return "192.168.0.0/16"; - } - return "n/a"; - } - -function switch_empty(v: count): string - { - switch ( v ) { - } - return "n/a"; - } - -function switch_fallthrough(v: count): string - { - local rval = ""; - switch ( v ) { - case 1: - rval += "test"; - fallthrough; - case 2: - rval += "testing"; - fallthrough; - case 3: - rval += "tested"; - break; - } - return rval + "return"; - } - -function switch_default(v: count): string - { - local rval = ""; - switch ( v ) { - case 1: - rval += "1"; - fallthrough; - case 2: - rval += "2"; - break; - case 3: - rval += "3"; - fallthrough; - default: - rval += "d"; - break; - } - return rval + "r"; - } - -function switch_default_placement(v: count): string - { - local rval = ""; - switch ( v ) { - case 1: - rval += "1"; - fallthrough; - default: - rval += "d"; - fallthrough; - case 2: - rval += "2"; - break; - case 3: - rval += "3"; - break; - } - return rval + "r"; - } - -function switch_case_list(v: count): string - { - switch ( v ) { - case 1, 2: - return "1,2"; - case 3, 4, 5: - return "3,4,5"; - case 6, 7, 8, 9: - return "6,7,8,9"; - } - return "n/a"; - } - -function test_switch(actual: string, expect: string) - { - if ( actual != expect ) - print fmt("%s != %s", actual, expect); - } - -event new_connection(c: connection) - { - test_switch( switch_bool(T) , "true" ); - test_switch( switch_bool(F) , "false" ); - test_switch( switch_int(+1) , "one" ); - test_switch( switch_int(+2) , "two" ); - test_switch( switch_int(-3) , "minus three" ); - test_switch( switch_int(40) , "n/a" ); - test_switch( switch_enum(RED) , "red" ); - test_switch( switch_enum(BLUE) , "blue" ); - test_switch( switch_enum(GREEN) , "green" ); - test_switch( switch_enum(PINK) , "n/a" ); - test_switch( switch_count(1) , "1" ); - test_switch( switch_count(2) , "2" ); - test_switch( switch_count(3) , "3" ); - test_switch( switch_count(100) , "n/a" ); - test_switch( switch_port(22/tcp) , "ssh" ); - test_switch( switch_port(53/udp) , "dns" ); - test_switch( switch_port(0/icmp) , "echo" ); - test_switch( switch_port(1000/tcp) , "n/a" ); - test_switch( switch_double(1.1) , "1.1" ); - test_switch( switch_double(2.2) , "2.2" ); - test_switch( switch_double(3.3) , "3.3" ); - test_switch( switch_interval(1sec) , "1sec" ); - test_switch( switch_interval(2day) , "2day" ); - test_switch( switch_interval(3min) , "3min" ); - test_switch( switch_string("one") , "first" ); - test_switch( switch_string("two") , "second" ); - test_switch( switch_string("three") , "third" ); - test_switch( switch_addr(1.2.3.4) , "ipv4" ); - test_switch( switch_addr([fe80::1]) , "ipv6" ); - test_switch( switch_addr(0.0.0.0) , "unspec" ); - test_switch( switch_subnet(1.2.3.4/24) , "1.2.3.0/24" ); - test_switch( switch_subnet([fe80::1]/96) , "[fe80::0]" ); - test_switch( switch_subnet(192.168.1.100/16) , "192.168.0.0/16" ); - test_switch( switch_empty(2) , "n/a" ); - test_switch( switch_fallthrough(1) , "testtestingtestedreturn" ); - test_switch( switch_fallthrough(2) , "testingtestedreturn" ); - test_switch( switch_fallthrough(3) , "testedreturn" ); - test_switch( switch_default(1) , "12r" ); - test_switch( switch_default(2) , "2r" ); - test_switch( switch_default(3) , "3dr" ); - test_switch( switch_default(4) , "dr" ); - test_switch( switch_default_placement(1) , "1d2r" ); - test_switch( switch_default_placement(2) , "2r" ); - test_switch( switch_default_placement(3) , "3r" ); - test_switch( switch_default_placement(4) , "d2r" ); - - local v = vector(0,1,2,3,4,5,6,7,9,10); - local expect: string; - - for ( i in v ) - { - switch ( v[i] ) { - case 1, 2: - expect = "1,2"; - break; - case 3, 4, 5: - expect = "3,4,5"; - break; - case 6, 7, 8, 9: - expect = "6,7,8,9"; - break; - default: - expect = "n/a"; - break; - } - test_switch( switch_case_list(v[i]) , expect ); - } - - print "done"; - } diff --git a/testing/btest/core/leaks/teredo.zeek b/testing/btest/core/leaks/teredo.zeek deleted file mode 100644 index a2048ffb89..0000000000 --- a/testing/btest/core/leaks/teredo.zeek +++ /dev/null @@ -1,38 +0,0 @@ -# Needs perftools support. -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-GROUP: leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/tunnels/Teredo.pcap %INPUT >output -# @TEST-EXEC: btest-bg-wait 90 - -function print_teredo(name: string, outer: connection, inner: teredo_hdr) - { - print fmt("%s: %s", name, outer$id); - print fmt(" ip6: %s", inner$hdr$ip6); - if ( inner?$auth ) - print fmt(" auth: %s", inner$auth); - if ( inner?$origin ) - print fmt(" origin: %s", inner$origin); - } - -event teredo_packet(outer: connection, inner: teredo_hdr) - { - print_teredo("packet", outer, inner); - } - -event teredo_authentication(outer: connection, inner: teredo_hdr) - { - print_teredo("auth", outer, inner); - } - -event teredo_origin_indication(outer: connection, inner: teredo_hdr) - { - print_teredo("origin", outer, inner); - } - -event teredo_bubble(outer: connection, inner: teredo_hdr) - { - print_teredo("bubble", outer, inner); - } diff --git a/testing/btest/core/leaks/test-all.zeek b/testing/btest/core/leaks/test-all.zeek deleted file mode 100644 index c437c439f0..0000000000 --- a/testing/btest/core/leaks/test-all.zeek +++ /dev/null @@ -1,8 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -r $TRACES/wikipedia.trace test-all-policy -# @TEST-EXEC: btest-bg-wait 90 diff --git a/testing/btest/core/leaks/to_json.zeek b/testing/btest/core/leaks/to_json.zeek deleted file mode 100644 index 69b906a9cd..0000000000 --- a/testing/btest/core/leaks/to_json.zeek +++ /dev/null @@ -1,140 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -type color: enum { Red, White, Blue }; - -type myrec1: record { - c: count &optional; - s: string &log; -}; - -type myrec2: record { - m: myrec1 &log; -}; - -global did_it = F; - -event new_connection(myconn: connection) - { - if ( did_it ) - return; - - did_it = T; - # ##################################### - # Test the basic (non-container) types: - - local b: bool = T; - print to_json(b); - - local c: count = 123; - print to_json(c); - - local i: int = -999; - print to_json(i); - - local d1: double = 3.14; - local d2: double = -1.23456789e308; - local d3: double = 9e-308; - print to_json(d1); - print to_json(d2); - print to_json(d3); - - local t: time = double_to_time(1480788576.868945); - print to_json(t); - - local ti: interval = -12hr; - print to_json(ti); - - local s1: string = "hello"; - local s2: string = ""; - print to_json(s1); - print to_json(s2); - - local p1: port = 65535/tcp; - local p2: port = 1/udp; - local p3: port = 123/icmp; - local p4: port = 0/unknown; - print to_json(p1); - print to_json(p2); - print to_json(p3); - print to_json(p4); - - local a1: addr = 1.2.3.4; - local a2: addr = [ffff:1234::1]; - local a3: addr = [::ffff:123.123.123.123]; - print to_json(a1); - print to_json(a2); - print to_json(a3); - - local su1: subnet = 192.0.0.0/8; - local su2: subnet = [fe80::]/64; - print to_json(su1); - print to_json(su2); - - local e: color = Red; - print to_json(e); - - local p: pattern = /^abcd/; - print to_json(p); - - # ######################### - # Test the container types: - - # Records - local re1 = myrec1($c=100, $s="test"); - local re2 = myrec1($s="test"); - local re3 = myrec2($m=myrec1($c=15, $s="test")); - print to_json(re1); - print to_json(re1, T); - print to_json(re2); - print to_json(re3, T); - - # Vectors - local ve1: vector of count = vector(); - local ve2: vector of count = vector(2, 1); - local ve3: vector of addr = vector(1.2.3.4); - local ve4: vector of set[bool] = vector(set(T, F)); - local ve5: vector of myrec1 = vector(myrec1($s="test", $c=2)); - local ve6: vector of count; - ve6[0] = 0; - ve6[2] = 2; - print to_json(ve1); - print to_json(ve2); - print to_json(ve3); - print to_json(ve4); - print to_json(ve5, T); - print to_json(ve6); - - # Sets - local st1: set[count] = set(); - local st2: set[count] = set(2, 1); - local st3: set[addr] = set(1.2.3.4); - local st4: set[myrec1] = set(myrec1($s="test")); - local st5: set[myrec1] = set(myrec1($s="test", $c=2)); - local st6: set[string, count] = { ["one", 1], ["two", 2], ["three", 3] }; - print to_json(st1); - print to_json(st2); - print to_json(st3); - print to_json(st4); - print to_json(st5, T); - print to_json(st6); - - # Tables - local ta1: table[count] of addr = table(); - local ta2: table[count] of addr = {[1] = 10.1.1.1, [2] = 10.2.2.2}; - local ta3: table[addr] of table[string] of count = {[10.1.1.1] = table(["a"] = 1), [10.2.2.2] = table(["b"] = 2)}; - local ta4: table[addr] of vector of count = {[10.1.1.1] = vector(1, 2), [10.2.2.2] = vector(3, 5)}; - local ta5: table[count] of myrec1 = {[1] = myrec1($s="test", $c=2)}; - print to_json(ta1); - print to_json(ta2); - print to_json(ta3); - print to_json(ta4); - print to_json(ta5, T); - } - diff --git a/testing/btest/core/leaks/vector-indexing.zeek b/testing/btest/core/leaks/vector-indexing.zeek deleted file mode 100644 index 0488abf607..0000000000 --- a/testing/btest/core/leaks/vector-indexing.zeek +++ /dev/null @@ -1,30 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/wikipedia.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -global did_it = F; - -event new_connection(c: connection) - { - if ( did_it ) - return; - - did_it = T; - - # Slicing tests. - local v17 = vector( 1, 2, 3, 4, 5 ); - print v17[0:2]; - print v17[-3:-1]; - print v17[:2]; - print v17[2:]; - print v17[:]; - v17[0:1] = vector(6); - v17[2:4] = vector(7, 8); - v17[2:4] = vector(9, 10, 11); - v17[2:5] = vector(9); - } diff --git a/testing/btest/core/leaks/vector-val-bifs.test b/testing/btest/core/leaks/vector-val-bifs.test deleted file mode 100644 index b4519263d1..0000000000 --- a/testing/btest/core/leaks/vector-val-bifs.test +++ /dev/null @@ -1,28 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# The BIFS used in this test originally didn't call the VectorVal() ctor right, -# assuming that it didn't automatically Ref the VectorType argument and thus -# leaked that memeory. -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/ftp/ipv4.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -function myfunc(aa: interval, bb: interval): int - { - if ( aa < bb ) - return -1; - else - return 1; - } - -event new_connection(c: connection) - { - local a = vector( 5, 2, 8, 3 ); - print order(a); - str_split("this is a test string", a); - print addr_to_counts(c$id$orig_h); - } diff --git a/testing/btest/core/leaks/while.zeek b/testing/btest/core/leaks/while.zeek deleted file mode 100644 index 35241b8f6a..0000000000 --- a/testing/btest/core/leaks/while.zeek +++ /dev/null @@ -1,80 +0,0 @@ -# @TEST-GROUP: leaks -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks - -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -m -b -r $TRACES/http/get.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -function test_noop() - { - while ( F ) - print "noooooooooo"; - } - -function test_it() - { - local i = 0; - - while ( i < 10 ) - ++i; - - print i; - } - -function test_break() - { - local s = ""; - - while ( T ) - { - s += "s"; - print s; - - if ( s == "sss" ) - break; - } - } - -function test_next() - { - local s: set[count]; - local i = 0; - - while ( 9 !in s ) - { - ++i; - - if ( i % 2 == 0 ) - next; - - add s[i]; - } - - print s; - } - -function test_return(): vector of string - { - local i = 0; - local rval: vector of string; - - while ( T ) - { - rval[i] = fmt("number %d", i); - ++i; - - if ( i == 13 ) - return rval; - } - - rval[0] = "noooo"; - return rval; - } - -event new_connection(c: connection) - { - test_noop(); - test_it(); - test_break(); - test_next(); - print test_return(); - } diff --git a/testing/btest/core/leaks/x509_ocsp_verify.zeek b/testing/btest/core/leaks/x509_ocsp_verify.zeek deleted file mode 100644 index 2b12fc6cd8..0000000000 --- a/testing/btest/core/leaks/x509_ocsp_verify.zeek +++ /dev/null @@ -1,19 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/tls/ocsp-stapling.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/ssl - -event ssl_stapled_ocsp(c: connection, is_orig: bool, response: string) - { - local chain: vector of opaque of x509 = vector(); - for ( i in c$ssl$cert_chain ) - chain[i] = c$ssl$cert_chain[i]$x509$handle; - - print x509_ocsp_verify(chain, response, SSL::root_certs); - } diff --git a/testing/btest/core/leaks/x509_verify.zeek b/testing/btest/core/leaks/x509_verify.zeek deleted file mode 100644 index 0dbf8ed08c..0000000000 --- a/testing/btest/core/leaks/x509_verify.zeek +++ /dev/null @@ -1,33 +0,0 @@ -# Needs perftools support. -# -# @TEST-GROUP: leaks -# -# @TEST-REQUIRES: zeek --help 2>&1 | grep -q mem-leaks -# -# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run zeek zeek -b -m -r $TRACES/tls/tls-expired-cert.trace %INPUT -# @TEST-EXEC: btest-bg-wait 90 - -@load base/protocols/ssl - -event ssl_established(c: connection) &priority=3 - { - local chain: vector of opaque of x509 = vector(); - for ( i in c$ssl$cert_chain ) - { - chain[i] = c$ssl$cert_chain[i]$x509$handle; - } - - local result = x509_verify(chain, SSL::root_certs); - print fmt("Validation result: %s", result$result_string); - if ( result$result != 0 ) # not ok - return; - - print "Resulting chain:"; - for ( i in result$chain_certs ) - { - local cert = result$chain_certs[i]; - local certinfo = x509_parse(cert); - local sha1 = sha1_hash(x509_get_certificate_string(cert)); - print fmt("Fingerprint: %s, Subject: %s", sha1, certinfo$subject); - } - } diff --git a/testing/btest/scripts/base/protocols/irc/basic.test b/testing/btest/scripts/base/protocols/irc/basic.test index bf3141896b..0941e34532 100644 --- a/testing/btest/scripts/base/protocols/irc/basic.test +++ b/testing/btest/scripts/base/protocols/irc/basic.test @@ -1,9 +1,10 @@ # This tests that basic IRC commands (NICK, USER, JOIN, DCC SEND) # are logged for a client. -# @TEST-EXEC: zeek -r $TRACES/irc-dcc-send.trace %INPUT +# @TEST-EXEC: zeek -r $TRACES/irc-dcc-send.trace %INPUT >out # @TEST-EXEC: btest-diff irc.log # @TEST-EXEC: btest-diff conn.log +# @TEST-EXEC: btest-diff out # dcc mime types are irrelevant to this test, so filter it out event zeek_init() @@ -11,3 +12,8 @@ event zeek_init() Log::remove_default_filter(IRC::LOG); Log::add_filter(IRC::LOG, [$name="remove-mime", $exclude=set("dcc_mime_type")]); } + +event irc_names_info(c: connection, is_orig: bool, c_type: string, channel: string, users: string_set) + { + print "irc_names_info", channel, users; + } diff --git a/testing/btest/scripts/base/protocols/krb/krb-service-name.test b/testing/btest/scripts/base/protocols/krb/krb-service-name.test new file mode 100644 index 0000000000..8eceedef14 --- /dev/null +++ b/testing/btest/scripts/base/protocols/krb/krb-service-name.test @@ -0,0 +1,3 @@ +# @TEST-EXEC: zeek -r $TRACES/krb/optional-service-name.pcap +# @TEST-EXEC: btest-diff conn.log +# @TEST-EXEC: btest-diff kerberos.log diff --git a/testing/btest/scripts/policy/misc/stats.zeek b/testing/btest/scripts/policy/misc/stats.zeek new file mode 100644 index 0000000000..3af977ffcd --- /dev/null +++ b/testing/btest/scripts/policy/misc/stats.zeek @@ -0,0 +1,10 @@ +# @TEST-EXEC: zeek -r $TRACES/wikipedia.trace %INPUT + +@load policy/misc/stats + +event load_sample(samples: load_sample_info, CPU: interval, dmem: int) + { + # This output not part of baseline as it varies, but guess this test + # should still exist to cover potential memory leaks. + print CPU; + } diff --git a/testing/external/commit-hash.zeek-testing b/testing/external/commit-hash.zeek-testing index 48383d67d4..e67b5cc8d5 100644 --- a/testing/external/commit-hash.zeek-testing +++ b/testing/external/commit-hash.zeek-testing @@ -1 +1 @@ -8be265e13e9ddb2dda704bf1574b1307fc17eea9 +a1ef7ec7b6ad7f43a09dc31166ae3aba6267ecb9 diff --git a/testing/external/commit-hash.zeek-testing-private b/testing/external/commit-hash.zeek-testing-private index 93818c8b57..7dfbdabe2e 100644 --- a/testing/external/commit-hash.zeek-testing-private +++ b/testing/external/commit-hash.zeek-testing-private @@ -1 +1 @@ -0df146fde4f878b4b2219d96dc3a9a69f81b8ee1 +b6a220488de8a53a10a30cd2e8390bdff1627761 From 38505589e12d739588c5eea4c91f8b43aa482733 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 2 Jan 2020 13:16:25 -0800 Subject: [PATCH 27/28] Switch CI scripts to use ASAN/LSAN instead of gperftools Using AddressSanitizer/LeakSanitizer is better. It covers the full unit/baseline test suite by default without requiring one to write specific memory leak tests. It also covers other types of memory errors besides just leaks. --- .cirrus.yml | 13 ++++----- ci/test.sh | 56 +++----------------------------------- ci/travis-job | 42 ++++++++++------------------ ci/ubuntu-18.04/Dockerfile | 3 -- 4 files changed, 23 insertions(+), 91 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 1625a120b6..b14fcd08c1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -3,7 +3,7 @@ btest_jobs: &BTEST_JOBS 8 memory: &MEMORY 8GB config: &CONFIG --build-type=release --enable-cpp-tests -leak_config: &LEAK_CONFIG --build-type=debug --enable-perftools-debug +memcheck_config: &MEMCHECK_CONFIG --build-type=debug --enable-cpp-tests --sanitizers=address resources_template: &RESOURCES_TEMPLATE cpu: *CPUS @@ -16,8 +16,7 @@ ci_template: &CI_TEMPLATE $CIRRUS_BRANCH =~ 'release/.*' # Default timeout is 60 minutes, Cirrus hard limit is 120 minutes for free - # tasks. This leakcheck one can tend to run long, but see no downside - # to universally asking for the maximum. + # tasks, so may as well ask for full time. timeout_in: 120m sync_submodules_script: git submodule update --recursive --init @@ -114,13 +113,11 @@ freebsd_task: prepare_script: ./ci/freebsd/prepare.sh << : *CI_TEMPLATE -leakcheck_task: +memcheck_task: container: - # Just uses a recent/common distro to run leak checks. + # Just uses a recent/common distro to run memory error/leak checks. dockerfile: ci/ubuntu-18.04/Dockerfile << : *RESOURCES_TEMPLATE << : *CI_TEMPLATE env: - ZEEK_CI_LEAK_CHECK: true - ZEEK_CI_CONFIGURE_FLAGS: *LEAK_CONFIG - ZEEK_CI_BTEST_JOBS: 7 + ZEEK_CI_CONFIGURE_FLAGS: *MEMCHECK_CONFIG diff --git a/ci/test.sh b/ci/test.sh index d7c1e71ab7..264e3d7454 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -2,8 +2,7 @@ # It's possible to use this script locally from the zeek repo's root dir. # The parallelism level when running tests locally is $1 if provided, else -# the value of `nproc` if available, otherwise just a single core. Run with -# ZEEK_CI_LEAK_CHECK set to do just the leak checks. +# the value of `nproc` if available, otherwise just a single core. result=0 BTEST=$(pwd)/aux/btest/btest @@ -102,57 +101,10 @@ function run_external_btests fi } -function run_leak_tests - { - local zeek_testing_pid="" - local zeek_testing_pid_private="" - banner "Running memory leak tests: zeek" - - pushd testing/btest - ${BTEST} -d -b -x btest-results.xml -j ${ZEEK_CI_BTEST_JOBS} -g leaks || result=1 - prep_artifacts - popd - - pushd testing/external/zeek-testing - ${BTEST} -d -b -x btest-results.xml -j ${ZEEK_CI_BTEST_JOBS} -g leaks >btest.out 2>&1 & - zeek_testing_pid=$! - popd - - if [[ -d testing/external/zeek-testing-private ]]; then - pushd testing/external/zeek-testing-private - # Note that we don't use btest's "-d" flag or generate/upload any - # artifacts to prevent leaking information about the private pcaps. - ${BTEST} -b -j ${ZEEK_CI_BTEST_JOBS} -g leaks >btest.out 2>&1 & - zeek_testing_private_pid=$! - popd - fi - - banner "Running memory leak tests: external/zeek-testing" - wait ${zeek_testing_pid} || result=1 - pushd testing/external/zeek-testing - cat btest.out - prep_artifacts - popd - - if [[ -n "${zeek_testing_private_pid}" ]]; then - banner "Running memory leak tests: external/zeek-testing-private" - wait ${zeek_testing_private_pid} || result=1 - cat testing/external/zeek-testing-private/btest.out - else - banner "Skipping private tests (not available for PRs)" - fi - - return 0 - } - banner "Start tests: ${ZEEK_CI_CPUS} cpus, ${ZEEK_CI_BTEST_JOBS} btest jobs" -if [[ -n "${ZEEK_CI_LEAK_CHECK}" ]]; then - run_leak_tests -else - run_unit_tests - run_btests - run_external_btests -fi +run_unit_tests +run_btests +run_external_btests exit ${result} diff --git a/ci/travis-job b/ci/travis-job index 66df4eda4b..7da51117a2 100755 --- a/ci/travis-job +++ b/ci/travis-job @@ -100,7 +100,7 @@ install_in_docker() { distro_cmds="apt-get update; apt-get -y install wget xz-utils gdb cmake make gcc g++ flex bison python3 libpcap-dev libssl-dev zlib1g-dev libkrb5-dev git sqlite3 curl bsdmainutils; ln -s /usr/bin/python3 /usr/local/bin/python" ;; ${LEAK_TEST_DISTRO}) - distro_cmds="apt-get update; apt-get -y install gdb cmake make gcc g++ flex bison python3 libpcap-dev libssl-dev zlib1g-dev libkrb5-dev git sqlite3 curl bsdmainutils google-perftools libgoogle-perftools4 libgoogle-perftools-dev; ln -s /usr/bin/python3 /usr/local/bin/python" + distro_cmds="apt-get update; apt-get -y install gdb cmake make gcc g++ flex bison python3 libpcap-dev libssl-dev zlib1g-dev libkrb5-dev git sqlite3 curl bsdmainutils; ln -s /usr/bin/python3 /usr/local/bin/python" local_distro="ubuntu_18.04" ;; *) @@ -168,7 +168,7 @@ build() { ./configure --build-type=Release --disable-broker-tests --enable-cpp-tests --disable-python --disable-zeekctl && make -j 2 else echo "Configuring zeek to build for leak testing" - ./configure --build-type=Debug --disable-broker-tests --disable-python --disable-zeekctl --enable-perftools --enable-perftools-debug && make -j 2 + ./configure --build-type=Debug --disable-broker-tests --enable-cpp-tests --disable-python --disable-zeekctl --sanitizers=address && make -j 2 fi } @@ -209,21 +209,19 @@ run() { ulimit -a ret=0 - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - echo - echo "Running unit tests ##################################################" - echo + echo + echo "Running unit tests ##################################################" + echo - set +e - ( cd build && . ./zeek-path-dev.sh && zeek --test ) + set +e + ( cd build && . ./zeek-path-dev.sh && zeek --test ) - if [ $? -ne 0 ]; then - ret=1 - fi - - set -e + if [ $? -ne 0 ]; then + ret=1 fi + set -e + echo echo "Running baseline tests ##############################################" echo @@ -231,11 +229,7 @@ run() { set +e # Must specify a value for "-j" option, otherwise Travis uses a huge value. - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - ../../aux/btest/btest -j 4 -d - else - ../../aux/btest/btest -j 4 -d -g leaks - fi + ../../aux/btest/btest -j 4 -d if [ $? -ne 0 ]; then ret=1 @@ -278,11 +272,7 @@ run() { if [ -d zeek-testing ]; then cd zeek-testing - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - make - else - make leaks - fi + make if [ $? -ne 0 ]; then showdiag @@ -294,11 +284,7 @@ run() { if [ -d zeek-testing-private ]; then cd zeek-testing-private - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - make - else - make leaks - fi + make if [ $? -ne 0 ]; then showdiag diff --git a/ci/ubuntu-18.04/Dockerfile b/ci/ubuntu-18.04/Dockerfile index 67b711814e..64b84692d2 100644 --- a/ci/ubuntu-18.04/Dockerfile +++ b/ci/ubuntu-18.04/Dockerfile @@ -20,9 +20,6 @@ RUN apt-get update && apt-get -y install \ sqlite3 \ curl \ wget \ - google-perftools \ - libgoogle-perftools4 \ - libgoogle-perftools-dev \ && rm -rf /var/lib/apt/lists/* # Many distros adhere to PEP 394's recommendation for `python` = `python2` so From a1377e1d42a74f9fad902731f157f721fb1cc906 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 2 Jan 2020 18:24:16 -0800 Subject: [PATCH 28/28] Increase timeout for a btest May be more timing-sensitive with slower ASAN/LSAN configuration in addition to already-slower CI environment. --- testing/btest/scripts/policy/misc/weird-stats.zeek | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/btest/scripts/policy/misc/weird-stats.zeek b/testing/btest/scripts/policy/misc/weird-stats.zeek index 0caeb960fe..8fc7f626f2 100644 --- a/testing/btest/scripts/policy/misc/weird-stats.zeek +++ b/testing/btest/scripts/policy/misc/weird-stats.zeek @@ -1,5 +1,5 @@ # @TEST-EXEC: btest-bg-run zeek zeek %INPUT -# @TEST-EXEC: btest-bg-wait 20 +# @TEST-EXEC: btest-bg-wait 40 # @TEST-EXEC: btest-diff zeek/weird_stats.log @load misc/weird-stats