Commit graph

9661 commits

Author SHA1 Message Date
Max Kellermann
e2bf12d54a Val: pass IntrusivePtr<> to TableVal::ExpandAndInit()
Clarifies ownership and fixes memory leaks.

Closes https://github.com/zeek/zeek/issues/811
2020-02-24 15:55:52 +01:00
Jon Siwek
48fba11c51 GH-808: Add ZEEK_VERSION_NUMBER definition to zeek-config.h
This is the result of (major * 10000 + minor * 100 + patch), for example
3.1.2 becomes 30102.  This definition may be helpful for external code
that requires conditional compilation to support multiple Zeek
versions with differing APIs.
2020-02-23 09:55:20 +00:00
Jon Siwek
bf212b2d3c Updating submodule(s).
[nomail]
2020-02-22 11:55:34 -08:00
Jon Siwek
e7252ab57c Fix CI to checkout right commit of zeek-testing-private 2020-02-21 22:57:53 -08:00
Jon Siwek
43ade7ea4a Update a URL in CI README 2020-02-21 21:24:31 -08:00
Jon Siwek
f0c713046c Merge branch 'refactor_obj' of https://github.com/MaxKellermann/zeek
Minor formatting/style changes in merge.

* 'refactor_obj' of https://github.com/MaxKellermann/zeek:
  Val: use C++ initializers
  Val: add BroValUnion constructors
  Val: reduce duplicate code by using delegating constructors
  Val: remove unused default constructors and `friend` declarations
  Val: remove the unnecessary BroValUnion typedef
  Type: remove unnecessary enum typedefs
  Type: use C++ initializers
  Type: move code from BroType::BroType() to constexpr functions
  Type: remove useless BroType destructor
  Obj: disallow copying BroObj
  Obj: use C++ initializers
  Obj: make `no_location` constexpr
2020-02-21 20:06:09 -08:00
Jon Siwek
3996a54302 Merge branch 'noreturn' of https://github.com/MaxKellermann/zeek
Minor formatting change in merge so [[noreturn]] is consistently
on same line as function declarations.

* 'noreturn' of https://github.com/MaxKellermann/zeek:
  threading/MsgThread: add [[noreturn]] to InternalError()
  Flare: add [[noreturn]] to bad_pipe_op()
  Obj: add [[noreturn]] attributes to Internal(),  bad_ref()
  Reporter: add [[noreturn]] attribute to several methods
2020-02-21 15:37:33 -08:00
Max Kellermann
ccfafde17e threading/MsgThread: add [[noreturn]] to InternalError() 2020-02-21 20:45:09 +01:00
Max Kellermann
3d44864c79 Flare: add [[noreturn]] to bad_pipe_op() 2020-02-21 20:45:09 +01:00
Max Kellermann
c9af57aff8 Obj: add [[noreturn]] attributes to Internal(), bad_ref() 2020-02-21 20:45:09 +01:00
Max Kellermann
a4cfd86f47 Reporter: add [[noreturn]] attribute to several methods
Fixes this compiler warning:

 src/digest.cc: In function ‘EVP_MD_CTX* hash_init(HashAlgorithm)’:
 src/digest.cc:44:26: warning: ‘md’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  if ( ! EVP_DigestInit_ex(c, md, NULL) )
         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
2020-02-21 20:43:09 +01:00
Jon Siwek
38b25cf38d Merge branch 'smart_ptr' of https://github.com/MaxKellermann/zeek
Minor whitespace fixes during merge.

* 'smart_ptr' of https://github.com/MaxKellermann/zeek:
  OpaqueVal: remove misplaced `virtual` keywords
  CompHash: use class IntrusivePtr for the `type` field
  IntrusivePtr: replace the "add_ref" parameter with tag structs
  IntrusivePtr: remove reset(), nobody uses it
  IntrusivePtr: remove ordering operators
  IntrusivePtr: rename detach() to release()
  IntrusivePtr: move nullptr initializer to field declaration
2020-02-21 10:15:24 -08:00
Jon Siwek
e88516c748 Updating submodule(s).
[nomail]
2020-02-20 17:21:58 -08:00
Jon Siwek
678115803b Merge branch 'expr_missing_ref' of https://github.com/MaxKellermann/zeek
Updated the Ref() to happen inline with Assign() call for clarity.

* 'expr_missing_ref' of https://github.com/MaxKellermann/zeek:
  Expr: add missing reference in AssignExpr::InitVal()
2020-02-20 14:59:04 -08:00
Max Kellermann
c0164c42d5 OpaqueVal: remove misplaced virtual keywords
These methods are not meant to be overridden.
2020-02-20 15:57:57 +01:00
Max Kellermann
53f49e0057 CompHash: use class IntrusivePtr for the type field 2020-02-20 15:57:39 +01:00
Max Kellermann
31b3a56740 IntrusivePtr: replace the "add_ref" parameter with tag structs
Using a runtime parameter is obscure and error-prone.  Avoiding
error-prone code and getting reference counting right is the whole
point of this class.
2020-02-20 15:56:50 +01:00
Max Kellermann
7c0863dccf IntrusivePtr: remove reset(), nobody uses it
This method mimicks std::unique_ptr::reset(), but adds an obscure
"add_ref" parameter which is error prone.  Since nobody uses this
method, and this method is all about dealing with raw pointers which
we shouldn't be doing, let's remove it.
2020-02-20 15:56:48 +01:00
Max Kellermann
98b27a2ae8 IntrusivePtr: remove ordering operators
These violate the C++ standard because comparing pointers to unrelated
objects is undefined behavior.
2020-02-20 15:56:32 +01:00
Max Kellermann
35d97a24f0 Expr: add missing reference in AssignExpr::InitVal()
The one reference returned by `op2->InitVal()` is given to
`aggr_r->Assign()` and returned to the caller, which may result in a
use-after-free crash bug.  This patch adds the missing reference.

Closes https://github.com/zeek/zeek/issues/805
2020-02-20 09:27:06 +01:00
Max Kellermann
08128b244f IntrusivePtr: rename detach() to release()
Follow the C++ standard library conventions (here: `std::unique_ptr`).
2020-02-20 08:58:21 +01:00
Max Kellermann
edb93d1733 IntrusivePtr: move nullptr initializer to field declaration
This allows "defaulting" the default constructor, and guarantees that
all constructors really initialize the field to a legal value.
2020-02-20 08:58:21 +01:00
Jon Siwek
a20dd12117 Merge branch 'memleaks' of https://github.com/MaxKellermann/zeek
The merge commit fixes reference counting issues introduced with the
changes to ListExpr::Assign() and IndexExpr::Assign(), but then also
several other pre-existing reference counting confusions in other
Assign() implementations/calls, some which were now directly observable
via new crashing behavior, others just from a cursory code audit.

* 'memleaks' of https://github.com/MaxKellermann/zeek:
  input/Manager: fix memory leak in UnrollRecordType()
  OpaqueVal: fix two memory leaks in BloomFilterVal::Merge()
  DbgBreakpoint: fix memory leak
  DebugCmds: fix memory leak
  scan.l: fix crash bug in do_atif()
  Expr: fix memory leak in RecordConstructorExpr::InitVal()
  Expr: fix memory leaks in AssignExpr::EvalIntoAggregate()
  Expr: fix memory leaks in CondExpr::Eval()
  Expr: fix several memory leaks in BoolExpr::Eval()
  Expr: fix various memory leaks in Assign()
  Expr: fix memory leaks in BinaryExpr::Eval()
  analyzer/protocol/http: fix potential memory leak
2020-02-19 18:59:04 -08:00
Jon Siwek
0a9251ae51 Updating submodule(s).
[nomail]
2020-02-19 10:33:17 -08:00
Max Kellermann
51970c256b input/Manager: fix memory leak in UnrollRecordType()
The `Val*` return by Expr::Eval() is never freed.  Note that it must
be freed after the `Field` object has been created, because the
`secondary` variable points to data inside the `Val*`.
2020-02-19 15:12:28 +01:00
Max Kellermann
3612713115 OpaqueVal: fix two memory leaks in BloomFilterVal::Merge() 2020-02-19 15:12:28 +01:00
Max Kellermann
19fd51a35b DbgBreakpoint: fix memory leak 2020-02-19 15:12:28 +01:00
Max Kellermann
37e7e914dc DebugCmds: fix memory leak 2020-02-19 15:12:28 +01:00
Max Kellermann
bb1390caaa scan.l: fix crash bug in do_atif()
This is really a memory leak because the Unref() call is missing.  But
since this usually returns a "stock" object (`ValManager::b_true` or
`ValManager::b_false`), nothing really leaks.  But eventually, the
reference counter will overflow to `INT_MAX`, leading to a crash in
bad_ref().
2020-02-19 15:12:28 +01:00
Max Kellermann
0a0884edb4 Expr: fix memory leak in RecordConstructorExpr::InitVal() 2020-02-19 15:12:28 +01:00
Max Kellermann
5468fae8e0 Expr: fix memory leaks in AssignExpr::EvalIntoAggregate() 2020-02-19 15:12:28 +01:00
Max Kellermann
65c4f34385 Expr: fix memory leaks in CondExpr::Eval()
No code path had any cleanup code, leaking all the local references.

More weird was however the result building code: it took elements from
one of the existing vectors without referencing them, and passed them
to VectorVal::Assign() which assumes that the caller-owned reference
is now owned by that VectorVal.

Even in the successful code path, no references were freed.

Everything was wrong with this method!
2020-02-19 15:12:28 +01:00
Max Kellermann
862f48da45 Expr: fix several memory leaks in BoolExpr::Eval() 2020-02-19 15:12:28 +01:00
Max Kellermann
6ce1081b38 Expr: fix various memory leaks in Assign() 2020-02-19 15:12:28 +01:00
Max Kellermann
593ebc1d62 Expr: fix memory leaks in BinaryExpr::Eval() 2020-02-19 15:12:28 +01:00
Max Kellermann
36d4b25ac0 analyzer/protocol/http: fix potential memory leak
This isn't really a memory leak because ParseRequest() never fails,
but if it one day "learns" to fail, the `request_method` allocation
will leak.
2020-02-19 15:12:28 +01:00
Jon Siwek
2b932128a4 Updating submodule(s).
[nomail]
2020-02-18 15:21:38 -08:00
Jon Siwek
e447ca5eb6 Updating submodule(s).
[nomail]
2020-02-18 14:50:05 -08:00
Jon Siwek
b8497c8245 Merge branch 'dns_memleak' of https://github.com/MaxKellermann/zeek
* 'dns_memleak' of https://github.com/MaxKellermann/zeek:
  analyzer/protocol/dns: fix NSEC3 memory leak
  analyzer/protocol/dns: change runtime check to assert()
  analyzer/protocol/dns: fix memory leak
2020-02-18 12:21:17 -08:00
Jon Siwek
eafcea86d5 Updating submodule(s).
[nomail]
2020-02-18 10:19:51 -08:00
Max Kellermann
957e7d3245 analyzer/protocol/dns: fix NSEC3 memory leak 2020-02-18 09:24:31 +01:00
Max Kellermann
59b5e6b7dc Val: use C++ initializers 2020-02-16 19:23:40 +01:00
Max Kellermann
4a5473c572 Val: add BroValUnion constructors
Allows using C++ initializers.
2020-02-16 19:23:37 +01:00
Max Kellermann
5d58dbbd2e Val: reduce duplicate code by using delegating constructors 2020-02-16 19:23:34 +01:00
Max Kellermann
74f93091e6 Val: remove unused default constructors and friend declarations 2020-02-16 19:23:28 +01:00
Max Kellermann
99f1804c62 Val: remove the unnecessary BroValUnion typedef 2020-02-16 19:22:35 +01:00
Max Kellermann
e3c0da2e15 Type: remove unnecessary enum typedefs 2020-02-16 19:22:35 +01:00
Max Kellermann
b1fe483b05 Type: use C++ initializers 2020-02-16 19:22:35 +01:00
Max Kellermann
5b8bd26c72 Type: move code from BroType::BroType() to constexpr functions
Prepare to inline the constructor, which will one day be `constexpr`
(requires moving the `std::string name` field somewhere else).
2020-02-16 19:22:35 +01:00
Max Kellermann
411d048d24 Type: remove useless BroType destructor 2020-02-16 19:22:35 +01:00