Commit graph

151 commits

Author SHA1 Message Date
Tim Wojtulewicz
b9b4fcb78b binpac: Require C++20 for builds 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
bb382fc0c0 binpac: Fix clang-tidy readability-isolate-declaration finding in generated code 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
ef962376bc binpac: Add 'override' to virtual methods in generated code 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
28cc9ca3ec binpac: Add NOLINT for clang-tidy performance-enum-size to generated headers 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
09936133a6 binpac: Reorder the fields in pac_type.h for better packing 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
45d07641e4 binpac: Make 'nullptr' a keyword, allow values to be set to it and compared against it
This helps fix 'modernize-use-nullptr' findings in generated code.
2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
3cf68302a2 binpac: Make 'bool' a discrete type and handle it differently when generating code
This fixes clang-tidy modernize-use-bool-literals findings in the generated code
2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
54a0e01805 binpac: Wrap generated switch statements in NOLINTs for bugprone-branch-clone
Binpac generates a lot of switch statements with repeated blocks in
them (typically empty blocks). Running clang-tidy on the generated code
with bugprone-branch-clone generates a lot of warnings. Instead of
doing a ton of analysis in binpac to avoid generating the duplicates,
just mark any switch generated with an annotation to avoid reporting
them.
2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
670c4dcbcf binpac: Add missing .cmake-format.json, reformat with pre-commit 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
dacfe747b9 binpac: Format output closer to what clang-format would output 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
964817f9bf binpac: Add cmake-format and typos pre-commit configs 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
3297de477b binpac: Reformat C++ code in Spicy style 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
716bf016a1 binpac: Remove usage of FindRequiredPackage 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
a4bc3fdf32 binpac: Add /J flag on Windows to force unsigned char 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
874de5d25b binpac: Force -std=c++17 mode for cmake targets, remove use of RequireCXX17.cmake 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
b7cc5afa78 binpac: Require CMake 3.15.0 to build, similar to the recent changes to zeek and broker 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
d39df6b243 binpac: Remove vendored CMake files from repo 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
4d0a29a725 binpac: Don't output comment for &let/&withinput if no such fields exist 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
ba7a7c2201 binpac: Include stdint.h early to prevent redefinition of int type macros 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
e05a0b8748 binpac: Remove argument from BINPAC_LSAN_DISABLE macro to fix warning on Windows 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
5264b957f1 binpac: Generate range-based for loops for array cleanup 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
65da8cf5de binpac: Avoid initializing array length variables twice in generated code 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
299f39e8e2 binpac: Mark overridden methods with 'override' 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
45ef19049c binpac: Add final keyword to class definitions 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
613ffef4a2 binpac: Use nullptr in generated code 2025-08-20 08:52:24 -07:00
Tim Wojtulewicz
9f3750d0cc binpac: Apply clang-tidy's modernize-use-nullptr check 2025-08-20 08:52:24 -07:00
Vern Paxson
49a96f5216 binpac: address linter warnings about use of sprintf() 2025-08-20 08:52:23 -07:00
Tomer Lev
d5f2c9c3a8 binpac: Only adding subdir if running standalone 2025-08-20 08:52:23 -07:00
Tomer Lev
9a4e01e634 binpac: Additional Windows fixes. Fixed wrong MSVC macro definition and std::filesystem invocation. Linking to libunistd library 2025-08-20 08:52:23 -07:00
Arne Welzel
60265b8ce7 binpac: pac_scan: Exit with failure for include errors
Elsewhere (zeek/zeek#2482), it was observed that when binpac encounters
include failures, it still exits with 0 indicating success. Subsequent
compilation of the produced .h and .cc files likely fails.

Exit with 1 on include errors to make pin pointing issues easier by
having make/ninja stop earlier.
2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
d21f99ef2b binpac: Wrap native dirname() call in ifdef, call std::filesystem on Windows 2025-08-20 08:52:23 -07:00
Elad Solomon
faa1b7abbf binpac: Adapted binpac to compile with MSVC for Windows environment. 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
dd3737b5c8 binpac: Apply bits of nadi-bittorrent patch that aren't applied 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
090325df40 binpac: Add pre-commit hooks and run clang-format on everything 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
090ac0a6e0 binpac: Remove already-applied binpac-* patches 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
6034744a0c binpac: Rename files in patches to match current directory structure 2025-08-20 08:52:23 -07:00
Seth Hall
c010152340 binpac: CMAKE_CFG_INTDIR is no longer necessary.
CMake documentation says that CMAKE_CFG_INTDIR is no longer necessary to
find the right binary for the configuration and is in fact deprecated in
recent versions of CMake.
2025-08-20 08:52:23 -07:00
Seth Hall
024b4ff8f3 binpac: Updates for building Zeek as a submodule 2025-08-20 08:52:23 -07:00
Jon Siwek
508e78ebe9 binpac: Prevent use of LeakSanitizer on FreeBSD 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
f365c253a7 binpac: Fix LGTM findings 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
5d75f8ed6c binpac: Remove usage of ZEEK_FORWARD_DECLARE_NAMESPACED macro 2025-08-20 08:52:23 -07:00
Jon Siwek
b1101e6e16 binpac: Fix #include of RE.h to use zeek/RE.h 2025-08-20 08:52:23 -07:00
Jon Siwek
c5fe0eaa17 binpac: GH-14: Use larger temporary storage for evaluating case-expressions
For example:

    inum: uint32 = case (ed & 0x0f) of {
        0x00    -> n_8;  # n_8 is a uint8
        0x01    -> n_16; # n_16 is a uint16
        0x02    -> n_32; # n_32 is a uint32
        default -> 0;
    };

Previously, the temporary storage used for evaluating the
case-expression was based on whatever type the first case yields, which
is a uint8 in the above example.  That behavior can lead to a narrowing
conversion whenever the 0x01 or 0x02 cases occur.

The new behavior is to base the temporary storage's type on the largest
numeric type that the case-expression can yield, which is uint32 in the
above example.
2025-08-20 08:52:23 -07:00
Jon Siwek
11b6feb18b binpac: Update minimum required CMake to 3.5 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
f1d7d0c80d binpac: Move RE_Matcher to zeek namespace 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
cd7a2e9783 binpac: Squash two rules into one with a wildcard 2025-08-20 08:52:23 -07:00
Tim Wojtulewicz
a7f14ed423 binpac: Allow namespaced names as typenames for function return values 2025-08-20 08:52:23 -07:00
Jon Siwek
9de6212dda binpac: Remove use of Variable-Length-Arrays
Related to https://github.com/zeek/zeek/issues/895
2025-08-20 08:52:23 -07:00
Jon Siwek
db7c3d7c5c binpac: Fix incorrect boundary checks in flowbuffer frame length parsing
Incremental flowbuffer parsing sought to first parse the "minimum header
length" required to get the full frame length, possibly from a record
field, but generating the logic to parse that field could greedily
bundle in additional boundary-checks for all subsequent fields of
known-size.

E.g. for flowunit parsing of this:

    type HDR = record {
        version:    uint8;
        reserved:   uint8;
        len:        uint16;
    } &byteorder=bigendian;

    type FOO_PDU(is_orig: bool) = record {
        hdr:        HDR;
        plen:       uint8;
        ptype:      uint8;
        something:  bytestring &restofdata;
    } &byteorder=bigendian, &length=hdr.len;

The flowbuffer was correctly seeking to buffer 4 bytes and parse the
"hdr.len" field, but the generated parsing logic for "hdr.len" included
a boundary check all the way up to include "plen" and "ptype".

This causes out-of-bounds exceptions to be thrown for inputs that should
actually be possible to incrementally parse via flowbuffer.
2025-08-20 08:52:23 -07:00
Jon Siwek
3aad9c74c3 binpac: Disable LeakSanitizer
https://github.com/zeek/zeek/issues/699
2025-08-20 08:52:23 -07:00