Commit graph

609 commits

Author SHA1 Message Date
Tim Wojtulewicz
822567b3f9 Merge remote-tracking branch 'origin/topic/jsiwek/32bit-compat'
* origin/topic/jsiwek/32bit-compat:
  Improve formatting of doubles that are close to integers
  Improve HTTP version number comparisons
  Add a 32-bit task to Cirrus CI config
  Replace va_list fmt() overload with vfmt()
  Format tables indexed by patterns consistently across 32-bit/64-bit
  Format interval values consistently across 32-bit/64-bit platforms
2020-02-24 18:49:33 -07:00
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
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
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
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
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
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
Jon Siwek
a8e137a879 Format interval values consistently across 32-bit/64-bit platforms 2020-02-14 21:40:01 -08:00
Max Kellermann
c6ffec02fc broker: include cleanup 2020-02-13 10:12:03 +01:00
Max Kellermann
e98cf0a4a0 Val: eliminate the "BroString.h" include 2020-02-13 09:13:59 +01:00
Max Kellermann
728184ea93 Val: eliminate the "CompHash.h" include 2020-02-13 09:13:59 +01:00
Max Kellermann
4aac78cf29 Val: forward-declare class PDict, reduce includes 2020-02-12 10:10:26 +01:00
Max Kellermann
dfac4572e7 Val: eliminate the "Scope.h" include 2020-02-12 10:10:26 +01:00
Tim Wojtulewicz
eda1b4a23e Use const references over copying variables (performance-unnecessary-copy-initialization, performance-for-range-copy) 2020-02-11 11:02:08 -08:00
Johanna Amann
d6d2bbe878 &on_change: incooperate feedback of Jon. 2020-02-06 14:40:38 -08:00
Johanna Amann
b1040f88c9 &on_change wrapup: documentation, tests, whitespacing
Adds documentation, fixes a whitespace issues, fixes compiler warning on
some Linux system, extends test.
2020-02-05 14:15:14 -08:00
Johanna Amann
b6a244f784 Merge remote-tracking branch 'origin/master' into topic/johanna/table-on-change 2020-02-05 12:41:19 -08:00
Johanna Amann
18ab7838a9 Table expiry now raises &on_change handlers
Expiry is remprted as ELEMENT_EXPIRED (which was newly introduced), to
allow distinction from table deletion.
2020-02-05 12:37:52 -08:00
Johanna Amann
7f9f66fce9 Prevent recursion of &on_change handlers.
This change prevents &on_change handlers for a table from running if an
&on_change handler for the same table is already running.
2020-02-05 11:45:16 -08:00
Max Kellermann
6a815b4b06 UID, ..: un-inline methods to reduce header dependencies
Only 1% build time speedup, but still, it declutters the headers a bit.

Before this patch:

 2565.17user 141.83system 2:25.46elapsed 1860%CPU (0avgtext+0avgdata 1489076maxresident)k
 72576inputs+9130920outputs (1667major+49400430minor)pagefaults 0swaps

After this patch:

 2537.19user 142.94system 2:26.90elapsed 1824%CPU (0avgtext+0avgdata 1434268maxresident)k
 16240inputs+8887152outputs (1931major+48728888minor)pagefaults 0swaps
2020-02-04 20:51:02 +01:00
Max Kellermann
0db61f3094 include cleanup
The Zeek code base has very inconsistent #includes.  Many sources
included a few headers, and those headers included other headers, and
in the end, nearly everything is included everywhere, so missing
#includes were never noticed.  Another side effect was a lot of header
bloat which slows down the build.

First step to fix it: in each source file, its own header should be
included first to verify that each header's includes are correct, and
none is missing.

After adding the missing #includes, I replaced lots of #includes
inside headers with class forward declarations.  In most headers,
object pointers are never referenced, so declaring the function
prototypes with forward-declared classes is just fine.

This patch speeds up the build by 19%, because each compilation unit
gets smaller.  Here are the "time" numbers for a fresh build (with a
warm page cache but without ccache):

Before this patch:

 3144.94user 161.63system 3:02.87elapsed 1808%CPU (0avgtext+0avgdata 2168608maxresident)k
 760inputs+12008400outputs (1511major+57747204minor)pagefaults 0swaps

After this patch:

 2565.17user 141.83system 2:25.46elapsed 1860%CPU (0avgtext+0avgdata 1489076maxresident)k
 72576inputs+9130920outputs (1667major+49400430minor)pagefaults 0swaps
2020-02-04 20:51:02 +01:00
Johanna Amann
745829dbe1 Merge remote-tracking branch 'origin/master' into topic/johanna/table-changes 2020-01-31 10:07:38 -08:00
Johanna Amann
7166cb7373 Merge remote-tracking branch 'origin/master' into topic/johanna/table-on-change 2020-01-31 10:06:52 -08:00
Robin Sommer
d0b206fa36 Remove APIs that were explicitly deprecated to be removed in 3.1.
Special handling for bro_{init,done,script_loaded} events: if still
used, they cause Zeek to abort at startup.
2020-01-29 12:08:09 +00:00
Johanna Amann
68f0fe9e8c Automatic bro table->brokerstore insert operations
We now have an &broker_store attribute which automatically sends
inserts/deletes into a set/table to broker.

This might work - I actually did not test if the data ends up in the
broker store in the end. A limitation is that the table/set currently
only can have a one-element type since Broker doesn't support the list
type.
2020-01-23 13:13:10 -08:00
Johanna Amann
98ad95d00b Merge remote-tracking branch 'origin/master' into topic/johanna/table-changes 2020-01-22 16:02:12 -08:00
Robin Sommer
8170baabef Merge remote-tracking branch 'origin/topic/timw/595-rapidjson'
Tweaks:
    - Small change to the logic for removing quotes around strings.
    - Updated NEWS & COPYING.3rdparty
    - Use of intrusive_ptr for stack-allocated StringVals
    - Little bit of refactoring (I would love to merge the two BuildJSON() functions, too, but that's a larger task)

* origin/topic/timw/595-rapidjson:
  Use the list of files from clang-tidy when searching for unit tests
  Optimize json_escape_utf8 a bit by removing repeated calls to string methods
  Expand unit test for json_escape_utf8 to include all of the strings from the ascii-json-utf8 btest
  GHI-595: Convert from nlohmann/json to rapidjson for performance reasons
  Convert type-checking macros to actual functions
2020-01-18 10:49:15 +00:00
Tim Wojtulewicz
46e7308422 GHI-595: Convert from nlohmann/json to rapidjson for performance reasons 2020-01-14 15:43:25 -07:00
Johanna Amann
382c4ddc2f &on_change: add insertion/change notifications.
Also - work with sets in addition to tables.
2020-01-13 19:39:40 -08:00
Johanna Amann
b343cf9bb7 &on_change working for removals from tables.
Insertions and changes are still noops.
2020-01-13 15:28:56 -08:00
Johanna Amann
96329e2172 Merge remote-tracking branch 'origin/master' into topic/johanna/table-changes 2020-01-09 12:48:20 -05:00
Johanna Amann
bf31587c2c Beginning implementation of &on_change for tables. 2020-01-09 12:47:16 -05:00
Tim Wojtulewicz
65a4e36a92 Merge remote-tracking branch 'origin/topic/jsiwek/asan'
* origin/topic/jsiwek/asan: (28 commits)
  Increase timeout for a btest
  Switch CI scripts to use ASAN/LSAN instead of gperftools
  Remove redundant memory leak btests
  Fix reference counting issues related to lambdas/closures
  Disable LeakSanitizer for btests that have known leaks
  Rewrite the btest for when-statement timeouts
  Fix memory leak when a logging plugin hook prevents a write
  Fix memory leaks in various input framework error-handling cases
  Fix memory leak in Reporter::get_weird_sampling_whitelist() BIF
  Fix reference counting of Log::Filter "config" field
  Fix memory leak in system_env() BIF
  Clean up triggers awaiting global state modification at shutdown
  Fix memory leak in initializing log writers with no local backend
  Fix packet filter memory leaks
  Skip sending thread heartbeat if it alread asked to be finished
  Fix memory leak of sqlite input reader prepared statement
  Prevent duplicate "finish" threading messages
  Fix memory leak when table-based input stream overwrites old entries
  Fix scripting error in a DHCP btest
  Fix memory leaks in Kerberos ticket decryption
  ...
2020-01-06 11:20:47 -07:00
Jon Siwek
44d922c4b5 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.
2020-01-02 23:04:22 -08:00
Tim Wojtulewicz
67fcc9b5af Mark safe_snprintf and safe_vsnprintf as deprecated, remove uses of them
safe_snprintf and safe_vsnprintf just exist to ensure that the resulting strings are always null-terminated. The documentation for snprintf/vsnprintf states that the output of those methods are always null-terminated, thus making the safe versions obsolete.
2020-01-02 15:36:39 -07:00
Jon Siwek
c0d6eb9efb 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.
2020-01-01 12:47:39 -08:00
Tim Wojtulewicz
98d1aadb9e GHI-599: avoid memory leak with default pattern matching and json formatting 2019-12-13 10:07:51 -07:00
Johanna Amann
b86a8acc2b Merge remote-tracking branch 'origin/topic/jsiwek/improve-record-fields-bif'
* origin/topic/jsiwek/improve-record-fields-bif:
  Allow record_fields() string arguments that name a record type
2019-11-07 13:49:14 -08:00
Jon Siwek
63fe835acf Allow record_fields() string arguments that name a record type 2019-11-01 12:46:17 -07:00
Dominik Charousset
72e15fe4d4 Integrate review feedback 2019-10-29 21:24:56 +01:00
Dominik Charousset
0f41b063b2 Add and use new IntrusivePt type in Zeek
Manual memory management via Ref/Unref is verbose and prone to error. An
intrusive smart pointer automates the reference counting, makes code
more robust (in particular w.r.t. to exceptions) and reduces boilerplate
code. A big benefit of the intrusive smart pointers for Zeek is that
they can co-exist with the manual memory management. Rather than having
to port the entire code base at once, we can migrate components
one-by-one. In this first step, we add the new template
`IntrusivePtr<T>` and start using it in the Broker Manager. This makes
the previous `unref_guard` obsolete.
2019-10-29 16:49:27 +01:00
Johanna Amann
ff612876c5 Revert "Fix compilation on OS-X."
This reverts commit cde28074a1.

We now have a c++14 compiler.

Fixes GH-626
2019-10-29 11:42:45 +01:00
Johanna Amann
cde28074a1 Fix compilation on OS-X.
OS X complains about std::pair not having a constexpr constructor. Which
seems to be the case for C++11. Hence, let's make it static const for
the moment.

This commit should be reverted when we move to C++17.
2019-10-07 18:52:11 -07:00
Johanna Amann
e615d1f4a8 Merge remote-tracking branch 'origin/topic/jsiwek/gh-589-sub-microsecond-printing'
* origin/topic/jsiwek/gh-589-sub-microsecond-printing:
  GH-589: improve printing of sub-microsecond intervals
2019-10-07 10:51:40 -07:00
Jon Siwek
a5d71ed2d2 Merge remote-tracking branch 'origin/topic/timw/595-json-perf'
* origin/topic/timw/595-json-perf:
  Update COPYING.3rdparty
  Use json::emplace to avoid some extra calls to operator[]
  Use tessil/unordered-map instead of nlohmann/fifo-map to mitigate performance issues when logging JSON
2019-10-01 16:42:59 -07:00
Jon Siwek
a34ade4876 Improve RecordVal JSON formatting
No need to create a record introspection table each time when all
the required information can be obtained directly in the RecordVal
and RecordType objects.  Besides the additional overhead, using such
a table will re-order the fields arbitrarily instead of using the
order in which they're defined.
2019-09-30 19:04:55 -07:00
Jon Siwek
d258ebe5ca Fix memory leak in RecordVal JSON formatting 2019-09-30 19:02:33 -07:00