Commit graph

483 commits

Author SHA1 Message Date
Jon Siwek
8bc65f09ec Cleanup/improve PList usage and Event API
Majority of PLists are now created as automatic/stack objects,
rather than on heap and initialized either with the known-capacity
reserved upfront or directly from an initializer_list (so there's no
wasted slack in the memory that gets allocated for lists containing
a fixed/known number of elements).

Added versions of the ConnectionEvent/QueueEvent methods that take
a val_list by value.

Added a move ctor/assign-operator to Plists to allow passing them
around without having to copy the underlying array of pointers.
2019-04-11 20:30:25 -07:00
Jon Siwek
628a46d8fd GH-219: revert previous change to |x| operator for interval/time
The result of the |x| operator for interval and time types historically
returned a value of type double.  This was changed as part of
3256ac7c49 to return interval/time, but
this now reverts to returning a double again to avoid introducing a
change that may break user code.

Fixes GH-219
2019-03-06 15:36:31 -08:00
Jon Siwek
67484a90fa GH-211: improve consistency of how scripting errors are handled
Scripting errors/mistakes now consistently generate a runtime error
which have the behavior of unwinding the call stack all the way out of
the current event handler.

Before, such errors were not treated consistently and either aborted
the process entirely or emitted a message while continuing to execute
subsequent statements without well-defined behavior (possibly causing
a cascade of errors).

The previous behavior also would only unwind out of the current
function (if within a function body), not out the current event
handler, which is especially problematic for functions that return
a value: the caller is essentially left a mess with no way to deal
with it.

This also changes the behavior of the startup/initialization process
to abort if there's errors during bro_init() rather than continue one
to the main run loop.  The `allow_init_errors` option may change this
new, default behavior.
2019-01-30 11:20:09 -06:00
Jon Siwek
3256ac7c49 GH-219: fix |x| operator int overflow / floating point type inconsistency
When 'x' is an integral arithmetic expression, it's now coerced to
yield a signed integer before taking the absolute value of it to
prevent the common issue of unsigned integer overflow/wraparound for
values below zero.

Using a time or interval value/expression for 'x' now also yields a
time or interval, respective, from the |x| operation instead of
a double.
2019-01-22 16:42:40 -06:00
Johanna Amann
d4f7dae768 Merge remote-tracking branch 'origin/topic/jsiwek/val_mgr'
* origin/topic/jsiwek/val_mgr:
  Pre-allocate and re-use Vals for bool, int, count, enum and empty string
  Preallocate booleans and small counts

I added a tiny change to CompHash to make sure that nothing messes this
up in the future.
2019-01-18 15:17:34 -08:00
Jon Siwek
399660c9eb GH-162: fix segfault when &expire_func is missing a return value
Fixes GH-162
2019-01-14 14:21:17 -06:00
Justin Azoff
665d8b01d2 Fix variable reuse in table expiration
While expiring a table, DoExpire checks at the end to see if NextEntry
returned nothing to determine if it should sleep for the short
table_expire_delay or the long table_expire_interval.

However, the check to see if the expire_func deleted the entry
re-assigns the same variable.  This means that:

  If you have a large table that is behind on expiring values
& The table defines an expire_func
& That expire_func deletes the item
& It so happens that the last item checked in the batch of
table_incremental_step size had expired

then DoExpire will reset the cookie and sleep for table_expire_interval
2019-01-12 16:36:56 -05:00
Jon Siwek
2982765128 Pre-allocate and re-use Vals for bool, int, count, enum and empty string 2019-01-09 18:29:23 -06:00
Justin Azoff
dcbef9cbe3 Preallocate booleans and small counts
Like PortManager, preallocate Vals for booleans and counts < 4096
2019-01-07 13:40:17 -06:00
Jon Siwek
1f450c0510 Improve introspection of Record and TypeType values
* TypeType values are now printable and yield the type name/alias
* Fix record_fields BIF to return correct type name for fields
* Allow TypeType values that point to a RecordType to be used with
  record_fields BIF
2018-10-18 15:10:02 -05:00
Jon Siwek
8792f5545c Fix crash when modifying a table from within its &expire_func 2018-10-12 08:35:25 -04:00
Jon Siwek
bd24421734 BIT-466: add redef += support to vectors 2018-08-17 15:16:15 -05:00
Jon Siwek
f336c8c710 Fix seg fault on trying to type-cast invalid/nil Broker::Data
This situation now throws a runtime expression exception instead of
crashing on null pointer access.
2018-08-15 11:02:52 -05:00
Jon Siwek
06c6e1188a Merge remote-tracking branch 'origin/topic/vern/set-ops2'
* origin/topic/vern/set-ops2:
  documentation, test suite update
  implemented set relationals
  bug fix for set intersection
  set intersection implemented
  mirroring previous topic/vern/set-ops to get branch up to date, since I'm a n00b

Fixed a couple memory leaks and added a leak test
2018-08-02 10:43:41 -05:00
Vern Paxson
2a8ea87c9f implemented set relationals 2018-07-06 16:22:06 -07:00
Vern Paxson
e416d34f1f bug fix for set intersection 2018-07-06 13:46:06 -07:00
Jon Siwek
fb5c32062b Merge remote-tracking branch 'origin/topic/vern/deprecations'
* origin/topic/vern/deprecations:
  deprecate merge_patterns()
  deprecate boolean scalar+vector operations
  bug fix (and typo fix) for vector+scalar boolean operations
  deprecate mixing scalars and vectors
  deprecate && / || operators for patterns
  fixed typos in NEWS
2018-06-26 17:03:49 -05:00
Jon Siwek
0ae022205e Reduce proliferation of including broker header files
This change should roughly halve compilation time
2018-06-25 16:35:25 -05:00
Vern Paxson
072a25df0f set intersection implemented 2018-06-24 10:43:58 -07:00
Vern Paxson
6449b0ab9e mirroring previous topic/vern/set-ops to get branch up to date, since I'm a n00b 2018-06-23 14:46:47 -07:00
Vern Paxson
b811a8e7a6 bug fix (and typo fix) for vector+scalar boolean operations 2018-06-22 13:40:53 -07:00
Robin Sommer
fe7e1ee7f0 Merge topic/actor-system throug a squashed commit. 2018-05-18 22:39:23 +00:00
Robin Sommer
8df77aee09 Merge remote-tracking branch 'origin/topic/jsiwek/bit-1909'
I've moved the resizing loop into a static method of RecordVal.

* origin/topic/jsiwek/bit-1909:
  BIT-1909: fix invalid redef'd record field accesses
2018-04-27 10:35:37 -07:00
Jon Siwek
8152508330 BIT-1909: fix invalid redef'd record field accesses 2018-04-11 16:23:26 -05:00
Johanna Amann
6d612ced3d Mark one-parameter constructors as explicit & use override where possible
This commit marks (hopefully) ever one-parameter constructor as explicit.

It also uses override in (hopefully) all circumstances where a virtual
method is overridden.

There are a very few other minor changes - most of them were necessary
to get everything to compile (like one additional constructor). In one
case I changed an implicit operation to an explicit string conversion -
I think the automatically chosen conversion was much more convoluted.

This took longer than I want to admit but not as long as I feared :)
2018-03-27 07:17:32 -07:00
Jon Siwek
d6d7f33f5c Clean up PortManager class, mark PortVal ctors deprecated.
Moved PortVal ctors back to public API, but deprecated, just in
case it helps give any external code a chance to adapt.
2017-12-12 11:35:55 -06:00
Jon Siwek
1e4964de77 Preallocate all possible PortVals.
The performance benefit is small (maybe ~1% at most), however, it's a
trivial change without downsides.
2017-12-11 15:29:28 -06:00
Robin Sommer
3adad5e19a Fix some Coverity warnings. 2016-08-02 11:38:29 -07:00
Robin Sommer
b698cfc2ce Fixing memory leak in changed table expiration code. 2016-06-15 09:09:27 -07:00
Robin Sommer
9da02ecae4 Merge branch 'topic/jgras/expire-redef' of https://github.com/J-Gras/bro
Extended error handling a bit, and increased serialization
data format version.
2016-06-14 17:22:25 -07:00
Jan Grashoefer
8a87055fcc Fixed table expiration evaluation.
The expiration attribute expression is now evaluated for every use. Thus
later adjustments of the value (e.g. by redefining a const) will now
take effect. Values less than 0 will disable expiration.
2016-06-13 21:01:46 +02:00
Robin Sommer
35686fb93a Fixing Coverity warning.
Addresses CID 1356116.
2016-05-29 11:02:39 -07:00
Robin Sommer
4f9cb6912a Fix for a table refering to a expire function that's not defined.
I was hoping to report this right at startup through a static check
but turns out we don't have the right machinery in place for that.
That would need to be done after the AST has been finalized, but our
AST traversal code can't iterate over types. So instead I've changed
this so that it's still being reported at runtime but at least
doesn't crash Bro anymore.

Closes BIT-1597.
2016-05-23 12:48:34 -07:00
Robin Sommer
50945a6359 Fixing a few Coverity warnings. 2016-05-23 08:25:11 -07:00
Johanna Amann
0ac1a81388 Merge branch 'topic/johanna/filter_subnet_table' of https://github.com/J-Gras/bro into topic/johanna/filter_subnet_table
* 'topic/johanna/filter_subnet_table' of https://github.com/J-Gras/bro:
  Fixed &read_expire for subnet-indexed tables
  Added &read_expire testcase for subnet tables

Includes a bit of refactoring of commit code & code related to the
feature.
2016-03-17 21:26:57 -07:00
Jan Grashoefer
d5034ccc19 Fixed &read_expire for subnet-indexed tables 2016-03-17 19:56:25 +01:00
Johanna Amann
a6cb85d86a Add filter_subnet_table bif
This bif works similar to the matching_subnet bif. The difference is
that, instead of returning a vector of the subnets that match, we return
a filtered view of the original set/table only containing the changed
subnets.

This commit also fixes a small bug in TableVal::UpdateTimestamp
(ReadOperation only has to be called when LoggingAccess() is true).
2016-03-16 15:50:13 -07:00
Robin Sommer
3957091e1b Renaming config.h to bro-config.h.
A couple times now I had this conflicting with files of the same name
in other projects.
2015-07-28 11:57:04 -07:00
Jon Siwek
bb15754427 BIT-1373: fix vector index assignment ref count bug. 2015-04-21 10:05:38 -05:00
Jon Siwek
ff61737212 Simplify a conditional with equivalent branches. 2014-09-02 16:29:52 -05:00
Jon Siwek
bfaa082aee Fix a reference counting bug in ListVal ctor. 2014-06-25 10:44:57 -05:00
Robin Sommer
ba229f798d Merge remote-tracking branch 'origin/fastpath'
* origin/fastpath:
  Fix use-after-free in some cases of reassigning a table index.
2014-06-10 18:17:04 -07:00
Jon Siwek
e616554ab8 Fix use-after-free in some cases of reassigning a table index.
Specifically observed when redef'ing the same index of a table that uses
subnets as indices, though the bug seems like it applies more generally
to anytime TableVal::Assign is provided with just the HashKey parameter
and not the index Val.

Addresses BIT-1202.
2014-06-10 13:38:32 -05:00
Jon Siwek
782615e9dd Remove unused Val::attribs member. 2014-04-23 10:44:47 -05:00
Robin Sommer
806851a21e Don't include locations into serialization when cloning values.
This should save some memory, see BIT-1161.
2014-03-30 20:20:06 +02:00
Jon Siwek
70131b5c84 Refactor SerializationFormat::EndWrite and ChunkedIO::Chunk mem mgmt.
SerializationFormat::EndWrite now transfers ownership of the buffer
to the caller instead of doing a memcpy.

ChunkedIO::Chunk is no longer a POD type, hopefully the ctor/dtor
make it easier to manage its associated memory.  It also now
tracks how to deallocate its buffer (i.e. delete vs. free).
2014-03-18 14:42:38 -05:00
Robin Sommer
7774af7518 Merge remote-tracking branch 'origin/topic/bernhard/ticket-1144'
* origin/topic/bernhard/ticket-1144:
  Allow iterating over bif functions with result type vector of any.

BIT-1144 #merged
2014-03-03 16:35:00 -08:00
Bernhard Amann
b3bd509b3f Allow iterating over bif functions with result type vector of any.
This changes the internal type that is used to signal that a vector
is unspecified from any to void.

I tried to verify that the behavior of Bro is still the same. After
a lot of playing around, I think everything still should worl as before.

However, it might be good for someone to take a look at this.

addresses BIT-1144
2014-02-25 15:30:29 -08:00
Bernhard Amann
09c2491896 Remove unused and potentially unsafe function ListVal::IncludedInString 2014-02-24 08:14:34 -08:00
Jon Siwek
54ebe98458 Fix table &default reference counting for record ctor expressions. 2013-12-05 14:23:32 -06:00