Commit graph

9997 commits

Author SHA1 Message Date
Tim Wojtulewicz
33aa192cec Expr: use fmt instead of sprintf 2020-02-27 14:21:18 -07:00
Tim Wojtulewicz
c466e63493 Expr: other minor initialization cleanup 2020-02-27 14:21:18 -07:00
Tim Wojtulewicz
8e27cc0a0d Expr: use List::empty() 2020-02-27 14:21:18 -07:00
Tim Wojtulewicz
1d9968d393 Expr: Convert a bunch of methods returning ints to return bools 2020-02-27 14:21:17 -07:00
Tim Wojtulewicz
e3ecaa1297 IPAddr: minor cleanup
- Mark empty constructors/destructors as default
- Initialization cleanup
- Remove unnecessary elses from before returns
2020-02-27 12:49:21 -07:00
Tim Wojtulewicz
8424b68d77 PriorityQueue: initialization cleanup 2020-02-27 12:36:24 -07:00
Tim Wojtulewicz
a312851d6e IP: Cleanup initialization, make a few functions consistent with others 2020-02-27 12:36:17 -07:00
Max Kellermann
46397de5c0 Stmt: use class IntrusivePtr 2020-02-27 14:08:00 +01:00
Max Kellermann
50ae129c57 Stmt: remove unused default constructors and friend declarations 2020-02-27 14:08:00 +01:00
Max Kellermann
837c8f759b Val: remove unimplemented prototype recover_val()
In the initial commit 10 years ago
(61757ac78b), the implementation was
gone already.
2020-02-27 14:08:00 +01:00
Max Kellermann
3331abb4f2 Val: cast_value_to_type() returns IntrusivePtr 2020-02-27 14:08:00 +01:00
Max Kellermann
96951c1300 Val: use IntrusivePtr in check_and_promote() 2020-02-27 14:08:00 +01:00
Max Kellermann
3d999b53fe Val: use nullptr instead of 0 2020-02-27 14:08:00 +01:00
Max Kellermann
95e2d66fb0 zeekygen: use class IntrusivePtr 2020-02-27 14:08:00 +01:00
Max Kellermann
edde591748 ID: use class IntrusivePtr 2020-02-27 14:08:00 +01:00
Max Kellermann
c3ea246237 Expr: use class IntrusivePtr
As a side effect, this fixes lots of memory leaks in
`*Expr::InitVal()` because in most implementations, the `aggr`
parameter leaks.
2020-02-27 12:06:34 +01:00
Max Kellermann
7be3641f1d Var: copy Location to stack, to fix use-after-free crash bug
The AssignExpr constructor may free the "init" pointer via
AssignExpr::TypeCheck(), resulting in a crash due to use-after-free.
To fix the crash bug, this patch copies the `Location` to the stack
instead of using a potentially-dangling pointer.
2020-02-27 12:06:34 +01:00
Max Kellermann
528cf11a5c Scope: lookup_ID() and install_ID() return IntrusivePtr<ID>
This fixes several memory leaks and double free bugs.
2020-02-27 12:02:55 +01:00
Max Kellermann
cbb6f09726 Scope: delete duplicate locals 2020-02-27 12:02:55 +01:00
Max Kellermann
783f833d5f EventRegistry: automatically delete EventHandlers
Fixes memory leak.
2020-02-27 12:02:55 +01:00
Max Kellermann
56e8a5f116 main: destroy event_registry after iosource_mgr
Fixes use-after-free bugs because PcapSource::Close() queues an event.
2020-02-27 12:02:55 +01:00
Max Kellermann
b60cccc637 zeekygen/IdentifierInfo: delete duplicate fields
Fixes memory leak.
2020-02-27 12:02:55 +01:00
Max Kellermann
b654a68c86 main: free the global scope in terminate_bro()
Make valgrind a bit happier.
2020-02-27 12:02:55 +01:00
Max Kellermann
875bfc09a2 Scope: pop_scope() returns IntrusivePtr<>
Make sure unused scopes are freed to fix memory leaks.

The comment inside pop_scope() is now obsolete and I deleted it,
because this commit implements the real solution.

Note that this requires us to add a reference to the
push_existing_scope() call in dbg_eval_expr(), because it never owned
the reference.
2020-02-27 12:02:55 +01:00
Max Kellermann
8ea1d89529 Scope: unref all inits in destructor
Fixes memory leak.

Proof that the Scope class is responsible for freeing those objects
can be found infunction_ingredients::~function_ingredients().
2020-02-27 12:02:55 +01:00
Max Kellermann
2c0ece7376 Var: pass IntrusivePtr to add_global(), add_local() etc.
Those functions don't have a well-defined reference passing API, and
we had lots of memory leaks here.  By using IntrusivePtr, reference
ownership is well-defined.
2020-02-27 11:59:37 +01:00
Max Kellermann
17a2f1a3ab plugin/ComponentManager: hold a reference to the EnumType
Use class IntrusivePtr<>.

This reference is necessary because add_type() may discard the
reference and hold only a reference to a clone of our EnumType.
2020-02-27 11:59:37 +01:00
Max Kellermann
db4f449382 Type: fix use-after-free bug in VectorType::ShallowClone()
The new VectorType instance needs a new reference to the `yield_type`.
2020-02-27 11:59:37 +01:00
Max Kellermann
7c80b577f1 Var: fix crash when redeclaring a function with different args
The following source code:

 function foo(foo: int) {}
 function foo() {}

... first produces this error:

 error in crash.zeek, line 1 and crash.zeek, line 2: incompatible types (function(foo:int;) : void and function() : void)

... and then crashes:

 Thread 1 "zeek" received signal SIGSEGV, Segmentation fault.
 0x000055555617d970 in RecordType::FieldDecl (this=0x555557cbdd80, field=0) at ../src/Type.cc:735
 735		return (*types)[field];
 (gdb) bt
 #0  0x000055555617d970 in RecordType::FieldDecl (this=0x555557cbdd80, field=0) at ../src/Type.cc:735
 #1  0x000055555619c0e2 in transfer_arg_defaults (args=0x555557cbf270, recv=0x555557cbdd80) at ../src/Var.cc:315
 #2  0x000055555619c40c in begin_func (id=0x555557cbf070, module_name=0x5555579dd4a0 "GLOBAL", flavor=FUNC_FLAVOR_FUNCTION, is_redef=0, t=0x555557cbde00,
     attrs=0x0) at ../src/Var.cc:371
 #3  0x0000555555f5723b in yyparse () at parse.y:1174
 #4  0x0000555556038bf6 in main (argc=5, argv=0x7fffffffe658) at ../src/main.cc:646

This is because `begin_func()` checks if the old and new functions
have the same type via same_type(), but continues anyway, and then
transfer_arg_defaults() crashes because both `Args()` have different
lengths.
2020-02-27 11:50:25 +01:00
Jon Siwek
36557f3086 Merge remote-tracking branch 'origin/topic/johanna/global_frame_stack'
Additionally changed to pop call_stack which tracks related data.

* origin/topic/johanna/global_frame_stack:
  Pop global frame stack on exception.
2020-02-26 19:56:52 -08:00
Johanna Amann
9ff6584953 Pop global frame stack on exception.
When changing this code for 3.0.0, the code-flow changed significantly.
One of the changes lead to exception being re-thrown from Call - which
leads to the function cleanup not always being run. While the Unref of
the framepointer was (correctly) moved into the catch block, the global
frame stack was not cleaned up - and contains an invalid pointer after
encountering an interpreter exception.

This small commit pops the stack and removes the framepointer that was
pushed onto it before re-throwing the exception.

I also think that this change (re-throwing the exception) breaks the
Zeek debugger in significant ways (you cannot debug a script that causes
a Runtime error anymore).
2020-02-26 15:58:49 -08:00
Jon Siwek
597407a708 Merge branch 'refactor' of https://github.com/MaxKellermann/zeek
- Minor code style/format tweaks in merge

* 'refactor' of https://github.com/MaxKellermann/zeek:
  IntrusivePtr: overload std::swap()
  IntrusivePtr: eliminate setPtr()
  IntrusivePtr: optimize release() using std::exchange()
  Expr: remove unused default constructors and `friend` declarations
  Expr: remove useless override
  Type: don't pass reference to pointer to MatchesIndex()
  Expr: don't pass reference to pointer to check_and_promote*()
  ID: remove unused default constructor
  Scope: simplify PList access, use pop_back() and back()
  List: add method empty()
2020-02-26 10:07:31 -08:00
Jon Siwek
502a0db96b Merge branch 'double_free' of https://github.com/MaxKellermann/zeek
* 'double_free' of https://github.com/MaxKellermann/zeek:
  Type: fix double free bug in SetType::ShallowClone()
2020-02-26 09:40:37 -08:00
Max Kellermann
ae2bd7928c Type: fix double free bug in SetType::ShallowClone()
The type declaration `addr_set` happens to result in a `SetType` with
`elements`, but no `indices`, and so ShallowClone() does not increment
any reference counter.  However, the `SetType` constructor passed
ownership of a non-existing reference to `TableType`, resulting in a
double free bug (and Zeek crash).

At first, I tried to fix this by obeying the code comment in
SetType::ShallowClone() and pass `indices=nullptr`, but that led to a
crash inside IndexType::IsSubNetIndex().  So this patch attempts to
make the symptom go away by pretending the code comment is simply
wrong, and only corrects the reference counters.
2020-02-26 05:34:40 +01:00
Jon Siwek
84e3e6c619 Merge remote-tracking branch 'origin/topic/timw/faster-hashing'
- Minor cleanups in siphash24.h (code style, header include)
- Updated COPYING.3rdparty with new license info

* origin/topic/timw/faster-hashing:
  Add a faster siphash24 implementation than the reference one
2020-02-25 19:56:17 -08:00
Jon Siwek
5a6799dd34 Update submodules 2020-02-25 19:29:06 -08:00
Jon Siwek
9b259019d9 Merge remote-tracking branch 'origin/topic/jsiwek/broker-submodule-build-merge'
* origin/topic/jsiwek/broker-submodule-build-merge:
  Update cmake submodule
  Update broker/cmake modules
2020-02-25 19:22:34 -08:00
Jon Siwek
b3d668e08f Update cmake submodule 2020-02-25 18:38:02 -08:00
Jon Siwek
2654ed2777 Update broker/cmake modules 2020-02-25 18:01:54 -08:00
Jon Siwek
9a75d04af5 Updating submodule(s).
[nomail]
2020-02-25 17:11:40 -08:00
Max Kellermann
5ed69edb7e IntrusivePtr: overload std::swap() 2020-02-25 21:05:59 +01:00
Max Kellermann
4dbc224e21 IntrusivePtr: eliminate setPtr()
There are only two call sites, and those hard-code the `add_ref`
parameter.
2020-02-25 21:05:53 +01:00
Max Kellermann
6f3e9d2c4c IntrusivePtr: optimize release() using std::exchange() 2020-02-25 21:05:42 +01:00
Max Kellermann
3bc33fe7f6 Expr: remove unused default constructors and friend declarations 2020-02-25 21:05:14 +01:00
Max Kellermann
138868747c Expr: remove useless override
All it does is call the base class.
2020-02-25 21:05:03 +01:00
Max Kellermann
8f3a712f74 Type: don't pass reference to pointer to MatchesIndex()
No implementation modifies the pointer value.  To guard against this,
this commit changes `&` to `const`.
2020-02-25 21:04:29 +01:00
Max Kellermann
0520d715c3 Expr: don't pass reference to pointer to check_and_promote*()
The function never modifies the pointer value.

check_and_promote_expr() is left untouched because it really does
modify the pointer.
2020-02-25 21:04:20 +01:00
Max Kellermann
3ccda03a54 ID: remove unused default constructor 2020-02-25 21:03:53 +01:00
Max Kellermann
ee21f29173 Scope: simplify PList access, use pop_back() and back() 2020-02-25 21:03:27 +01:00
Max Kellermann
cdf4362c7d List: add method empty() 2020-02-25 21:03:07 +01:00