Commit graph

334 commits

Author SHA1 Message Date
Tim Wojtulewicz
a1d121e5aa Use std::string/string_view versions of starts_with/ends_with where appropriate
The util:: versions of these methods remain as a thin wrapper around them so
they can be used with const char* arguments. Otherwise callers have to manually
make string_view objects from the input.
s Please enter the commit message for your changes. Lines starting
2025-07-17 09:08:54 -07:00
Tim Wojtulewicz
770bc0491e Remove ghc::filesystem submodule, switch to std::filesystem 2025-07-14 11:23:54 -07:00
Benjamin Bannier
627c3ad726 Fix clang-tidy readability-isolate-declaration warnings
I missed one of these in review so a machine is probably better at
catching them.

I fixed the existing instances which where largely in code which look
dated. Where possible I slightly reorganized the code so we do not have
to leave values uninitialized, but did not touch up anything else.
2025-06-30 14:19:06 -07:00
Tim Wojtulewicz
6aa5145782 Deprecate BRO_PLUGIN_INSTALL_PATH constant 2025-06-23 08:35:25 -07:00
Tim Wojtulewicz
9928403b0b Move type definitions/aliases from util.h to a separate file 2025-06-11 11:11:54 -07:00
Tim Wojtulewicz
ee319fc1c5 Fix clang-tidy modernize-use-nullptr findings 2025-06-06 11:43:06 -07:00
Tim Wojtulewicz
f3588657bf Fix clang-tidy modernize-loop-convert findings 2025-06-06 11:43:06 -07:00
Tim Wojtulewicz
02589c349a Fix clang-tidy bugprone-string-literal-with-embedded-nul warnings 2025-05-27 11:58:27 -07:00
Tim Wojtulewicz
1d315a3847 Fix clang-tidy bugprone-incorrect-roundings warnings 2025-05-27 11:58:27 -07:00
Tim Wojtulewicz
bdb0fad6d5 Remove noexcept from util::tokenize_string
One instance of this method is noexcept and one isn't. The version
that is noexcept uses std::vector::emplace_back, which may throw
exceptions. Instead of adding a try/catch block, opt for just making
the two functions able to throw exceptions.

This fixes a clang-tidy bugprone-exception-escape warning.
2025-05-27 11:58:27 -07:00
Tim Wojtulewicz
dbecfb5a2a Fix clang-tidy bugprone-branch-clone warnings 2025-05-27 11:58:27 -07:00
Tim Wojtulewicz
92854e95d3 Fix clang-tidy bugprone-assignment-in-if-condition warnings 2025-05-27 11:58:27 -07:00
Tim Wojtulewicz
896e41c794 Remove unnecessary #includes in base files in repo 2025-05-19 09:50:23 -07:00
Arne Welzel
679575d6b2 util: Fix terminate_processing() called from non-main thread
The current raise(SIGTERM) sends a signal to the calling thread. If
terminate_processing() is called from a non-main thread and that thread
was created at InitPostScript() time when SIGTERM is blocked, or has
blocked SIGTERM manually, terminate_processing() has no effect.

Switching to kill(getpid(), SIGTERM) guarantees that a thread that doesn't
block the signal (minimally the main thread) will run the handler.
2025-03-09 13:51:00 +01:00
Johanna Amann
a7cf057a63 util/init_random_seed: write_file implies deterministic
This makes Zeek run in deterministic mode with --save-seeds usage
and reworks all the extra indirections used in init_random_seed()
to make it easier to follow the control flow.

Fixes #4209
2025-02-04 11:57:51 +01:00
Arne Welzel
0f1c1cb754 clang-format: Sort doctest header at the bottom 2024-11-15 17:00:00 +01:00
Arne Welzel
54d28a2179 RunState.h: Deprecate misleadingly named current_packet_timestamp()
This returns current_pseudo, naming it current_packet_timestamp()
is actively misleading.
2024-11-12 10:46:55 +01:00
Tim Wojtulewicz
6b11252b8f Fix potential endless loop in util::strreplace 2024-09-11 11:21:25 +02:00
Benjamin Bannier
db42b2cfe5 Bump clang-format
This patch contains a bump of the configured clang-format version from
17.0.3 to 18.1.8 and automatically generated C++ source updates. The
main difference we are seeing from this is fixes for previously
incomplete reformats.
2024-09-02 16:46:59 +02:00
Vern Paxson
4cafacf90b fix ZAM "cat" of doubles/times to include trailing ".0" per normal BiF behavior 2024-03-28 16:43:06 -07:00
Vern Paxson
f88862f6ce avoid potentially expensive mallinfo() call if result won't be used 2024-03-19 10:59:49 -07:00
Dominik Charousset
cebb85b1e8 Fix unsafe and inefficient uses of copy_string
Add a new overload to `copy_string` that takes the input characters plus
size. The new overload avoids inefficient scanning of the input for the
null terminator in cases where we know the size beforehand. Furthermore,
this overload *must* be used when dealing with input character sequences
that may have no null terminator, e.g., when the input is from a
`std::string_view` object.
2023-11-03 15:25:38 +01:00
Benjamin Bannier
f5a76c1aed Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
2023-10-30 09:40:55 +01:00
Arne Welzel
c161b1c4b1 util/setvbuf: Respect buf argument 2023-10-10 09:29:21 +02:00
Christian Kreibich
6108b18a3b Normalize file paths in find_file_in_path()
This renders script file names more nicely, for example when printed by the
reporter. It also avoids redundant prefixing of "./" to local scripts. I'm not
adding unit tests since normalize_path() already has them. A btest follows in
the next commit.
2023-10-03 22:14:40 -07:00
Tim Wojtulewicz
de13bb6361 Avoid unnecessary type names in return statements 2023-07-07 09:17:05 -07:00
Arne Welzel
bc8b5f5830 Rename util-config.h to zeek-config-paths.h and install it
The util-config.h has never been installed previously. Skimming the history,
it was only meant for inclusion from util.cc, hence the name. Now that it's
included from some other headers, rename it to align with what it
contains and install it, too.
2023-05-17 15:01:57 +02:00
Arne Welzel
b2d934226f Introduce ZEEK_SEED_VALUES environment variable
For "individually different but deterministic" runs specifying Zeek's
seed as an environment variable eases setups as one can avoid creating
extra seed files for each of the individual processes.

It is an error to specify the new ZEEK_SEED_VALUES variable together
with the existing ZEEK_SEED_FILE and -G. ZEEK_SEED takes precedence over
deterministic mode (-D) like ZEEK_SEED_FILE does today already.
2023-05-12 19:50:37 +02:00
Tim Wojtulewicz
f2a3e23dfa Add ifdef'd implementation of setvbuf to zeek::util 2023-05-02 10:28:50 -07:00
Tim Wojtulewicz
35ee96c4cb A bunch of other minor issues reported by PVS-Studio 2023-01-27 13:03:52 -07:00
Tim Wojtulewicz
c1e5389929 Merge remote-tracking branch 'dop/topic/dopheide/vfmt-buf_len'
* dop/topic/dopheide/vfmt-buf_len:
  Fix logic error in vfmt() when growing the buffer
2022-11-21 09:10:37 -07:00
Michael Dopheide
e47b055769 Fix logic error in vfmt() when growing the buffer 2022-11-18 17:46:03 +00:00
Tim Wojtulewicz
ca8f82a574 Fix the strcasestr unit test 2022-11-17 11:21:40 -07:00
Tim Wojtulewicz
51cdbbd59d Re-enable strcasestr on Windows, fix linking error 2022-11-14 09:13:31 -07:00
Tim Wojtulewicz
a8fc63e182 Merge remote-tracking branch 'microsoft/master'
* microsoft/master: (71 commits)
  Clang formatting
  Mask ports before inserting them into the map
  Fix compiler warning from applied patch
  Remove statistics plugin in favor of stats bif
  Add EventHandler version of stats plugin
  Mark a few EventHandler methods const
  Changed implementation from std::map to std::unordered_map of Val.cc
  Removed const, Windows build is now working
  Added fixes suggested in PR
  Update src/packet_analysis/protocol/ip/IP.cc
  Apply suggestions from code review
  Clang format again but now with v13.0.1
  Rewrote usages of define(_MSC_VER) to ifdef _MSC_VER
  Clang format it all
  Fixed initial CR comments
  Add NEWS entry about Windows port
  Add a couple of extra unistd.h includes to fix a build failure
  Use std::chrono instead of gettimeofday
  Update libkqueue submodule [nomail]
  Don't call tokenize_string if the input string is empty
  ...
2022-11-11 15:23:21 -07:00
Tomer Lev
e2be5ddc0c Added fixes suggested in PR 2022-11-10 19:01:29 +02:00
Tomer Lev
73e749a162 Clang format again but now with v13.0.1 2022-11-09 18:56:00 +02:00
Tomer Lev
a105ea9d80 Rewrote usages of define(_MSC_VER) to ifdef _MSC_VER 2022-11-09 18:56:00 +02:00
Tomer Lev
5cdc6e150e Clang format it all 2022-11-09 18:55:51 +02:00
Tim Wojtulewicz
2e457eb3ea Fix a few compiler warnings from MSVC 2022-11-09 18:17:07 +02:00
Tim Wojtulewicz
6bf469b7a8 Remove extra <filesystem> include from util.cc 2022-11-09 18:16:13 +02:00
Tim Wojtulewicz
baee0d8026 Replace uses of std::filesystem with zeek::filesystem 2022-11-09 18:16:13 +02:00
Tim Wojtulewicz
5494e4e6fd Fix relative path checking in get_exe_path, plus a signed comparison 2022-11-09 18:16:13 +02:00
Tim Wojtulewicz
bf06cc9c2f Turn on unit tests by default, and ifdef out a few of them 2022-11-09 18:16:13 +02:00
Tim Wojtulewicz
78fb845f63 Rework change to util::vfmt to fix strings getting truncated 2022-11-09 18:16:13 +02:00
Tim Wojtulewicz
77c555a3a8 Fixing some issues from rebasing 2022-11-09 18:16:13 +02:00
Elad Solomon
dfd6cbe6b4 Fixed usages of path_list_separator 2022-11-09 18:15:34 +02:00
Tomer Lev
d7734ca783 Return the actual error code instead of a message when compiling to windows 2022-11-09 18:15:34 +02:00
Tomer Lev
d2f625c115 Replaced weakly_canonical with lexically_normal in normalize_path func.
Replaced weakly_canonical with lexically_normal in normalize_path func. Normalizing the path now does not access the filesystem.
2022-11-09 18:15:34 +02:00
Elad Solomon
3f349b8a37 Optimize initial memory consumption 2022-11-09 18:15:34 +02:00