Commit graph

64 commits

Author SHA1 Message Date
Seth Hall
a9d294528d binpac: Fixed compiler complaining about recursive function. 2025-08-20 08:52:23 -07:00
Robin Sommer
e3e4453dac binpac: Adding missing include. 2025-08-20 08:52:23 -07:00
Jon Siwek
ae20042943 binpac: BIT-1343: fix %include to work with relative paths 2025-08-20 08:52:23 -07:00
Jon Siwek
ded5abb01e binpac: BIT-1361: Improve boundary checks of records that use &length
Specifying &length on a record no longer skips generating boundary
checks for individual fields.  E.g. a record field that specifies a
&length that extends beyond the &length of the record containing it
should throw binpac::ExceptionOutOfBound, the usual way of handling
out-of-bounds conditions.
2025-08-20 08:52:23 -07:00
Jon Siwek
8648820497 binpac: Fix potential out-of-bounds memory reads in generated code.
Field lengths derived from other data in the input could potentially
lead to reading from outside the bounds of the input buffer.

Reported by John Villamil and Chris Rohlf - Yahoo Paranoids
2025-08-20 08:52:23 -07:00
Jon Siwek
db1c70b32e binpac: Separate declaration of binpac::init from definition.
When friend'ing a global function via qualified-id, Clang complains if
it's not been previously declared.
2025-08-20 08:52:23 -07:00
Robin Sommer
434f147932 binpac: Adding a new binpac::init() function that must be called by the host
before anything else.

Internally, this function compiles all regular expressions, avoiding
to that inside the regexp constructore. The code is a bit hackish due
to the way the regexp code depends on the Bro header.
2025-08-20 08:52:23 -07:00
Jon Siwek
498a5314ed binpac: Request format macros from inttypes.h explicitly.
This helps ensure the availability of PRI* macros from .pac files,
which cannot create this definition themselves since the inclusion
of binpac.h is hardcoded to be placed very early in the generated
code and already includes inttypes.h itself.
2025-08-20 08:52:23 -07:00
Jon Siwek
a5fb8e3787 binpac: Fix uninitialized (or unused) fields. 2025-08-20 08:52:23 -07:00
Jon Siwek
81bf65e148 binpac: Generate initialization code for external types.
Numeric/pointer types can be initialized to 0.
2025-08-20 08:52:23 -07:00
Jon Siwek
201b43f3be binpac: Optimize negative string length check.
Strings with a constant &length expression can be checked for negative
length values while generating the parser instead of in the parser
itself (which likely just ends up being dead code).
2025-08-20 08:52:23 -07:00
Jon Siwek
13e14768da binpac: Add virtual dtor to RefCount base class.
The code generated for types w/ &refcount will subclass RefCount and
Unref definitely deletes via a pointer to that base class so it needs a
virtual dtor.
2025-08-20 08:52:23 -07:00
Jon Siwek
4d7de63ef0 binpac: Add missing break to switch statement case. 2025-08-20 08:52:23 -07:00
Jon Siwek
8136abafef binpac: Remove unreachable code. 2025-08-20 08:52:23 -07:00
Jon Siwek
5e0f604418 binpac: Add missing va_end()'s to match va_start()'s.
Probably not an issue on most implementations, but undefined behavior
is scary and it's easy to fix.
2025-08-20 08:52:23 -07:00
Jon Siwek
cb524c2fde binpac: Fix two use-after-free bugs. 2025-08-20 08:52:23 -07:00
Jon Siwek
871541e636 binpac: Fix double-free.
The field is deleted by a base class dtor.
2025-08-20 08:52:23 -07:00
Robin Sommer
61cc83affa binpac: Adding an interface to manually control the buffering for generated
parsers.

This consists of two parts:

    1. The generated Flow classes expose their flow buffers via a new
       method flow_buffer().

    2. Flow buffers get two new methods:

        // Interface for delayed parsing. Sometimes BinPAC doesn't get the
        // buffering right and then one can use these to feed parts
        // individually and assemble them internally. After calling
        // FinishBuffer(), one can send the uppper-layer flow an FlowEOF()
        // to trigger parsing.
        void BufferData(const_byteptr data, const_byteptr end);
        void FinishBuffer();
2025-08-20 08:52:23 -07:00
Jon Siwek
ce2b56751b binpac: Fix an exception slicing issue in binpac generated cleanup code.
Switch to using a no-argument throw to preserve the dynamic type of
the binpac exception.  Otherwise, the exception is "sliced" and can only
be subsequently handled as binpac::Exception and not a derived type.
2025-08-20 08:52:23 -07:00
Jon Siwek
14e3d5a1a3 binpac: Add scoping to usages of binpac::Exception classes in generated code.
This allows analyzers to define their own types of the same name
without mistakingly overshadowing the usages of binpac::Exception
and its derived types in the generated parser code.
2025-08-20 08:52:23 -07:00
Robin Sommer
6c70f7851b binpac: Silence warning for generated code when compiling with clang. 2025-08-20 08:52:23 -07:00
Jon Siwek
8cf0be6d0f binpac: Change binpac.h integral typedefs and reimplement 64-bit pac_swap().
Integer types now use <inttypes.h>, and the 64-bit byte-swapping
function uses a union approach instead of masking/bit-shifting.

Addresses #761.
2025-08-20 08:52:23 -07:00
Jon Siwek
bf2184bb0f binpac: Raise minimum required CMake version to 2.6.3 2025-08-20 08:52:23 -07:00
Robin Sommer
fccf3a7340 binpac: Distribution cleanup. 2025-08-20 08:52:23 -07:00
Robin Sommer
092d049f8e binpac: Arrays now suport the &transient attribute.
If set, parsed elements won't actually be added to the array, and read
access to the array aren't permitted. This is helpful to save memory
in the case of large arrays for which elements don't need (or can't)
be buffered.
2025-08-20 08:52:23 -07:00
Jon Siwek
5db7ba4050 binpac: Update to use cmake submodule 2025-08-20 08:52:23 -07:00
Jon Siwek
969998d148 binpac: Remove $Id$ tags 2025-08-20 08:52:23 -07:00
Jon Siwek
3841c68d87 binpac: Install binaries with an RPATH 2025-08-20 08:52:23 -07:00
Jon Siwek
a4f05185d6 binpac: Workaround for FreeBSD CMake port missing debug flags 2025-08-20 08:52:23 -07:00
Robin Sommer
77e4315a57 binpac: Fixing compiler warning 2025-08-20 08:52:23 -07:00
Seth Hall
1d6cea8c52 binpac: Adding int64 and uint64 types to binpac. 2025-08-20 08:52:23 -07:00
Jon Siwek
50f5a913c3 binpac: Adding files to CMake build targets so they show up in generated IDE projects.
This addresses #413.
2025-08-20 08:52:23 -07:00
Robin Sommer
d41a2def5a binpac: Fixing crash with undefined case expressions.
Found by Emmanuele Zambon.
2025-08-20 08:52:23 -07:00
Jon Siwek
e7e2ee38e7 binpac: Add explicit CMake check for compiler 2025-08-20 08:52:23 -07:00
Seth Hall
1a15b968e6 binpac: Added an option to quiet the status output from binpac.
This adds the -q command line flag to quiet the output.
It also fixes a small compiler warning.
2025-08-20 08:52:23 -07:00
Jon Siwek
c2dbefab17 binpac: MacPorts & Fink paths now prepended to default search prefixes 2025-08-20 08:52:23 -07:00
Jon Siwek
2260d6c60e binpac: Add warning when building and installing are done by different users 2025-08-20 08:52:22 -07:00
Jon Siwek
4dd640d0f7 binpac: CMake 2.6 compatibility changes 2025-08-20 08:52:22 -07:00
Robin Sommer
71cc7e9d5b binpac: Cleaning up. 2025-08-20 08:52:22 -07:00
Jon Siwek
67e5bc7198 binpac: Made uninstall target cooperate with other projects 2025-08-20 08:52:22 -07:00
Jon Siwek
aacc6ee043 binpac: Added uninstall target 2025-08-20 08:52:22 -07:00
Jon Siwek
ed7e697d35 binpac: Changed default CMAKE_BUILD_TYPE to RelWithDebInfo
The --enable-debug option of the configure wrapper changes it to Debug.
Removed --enable-release option of the configure wrapper.
2025-08-20 08:52:22 -07:00
Jon Siwek
32423cf27b binpac: Customizable error messages for missing prereqs.
Adds the FindRequiredPackage() macro that wraps the functionality
of the standard find_package() macro.
2025-08-20 08:52:22 -07:00
Jon Siwek
173c3784ab binpac: Prepend build dir to search path.
This avoids inclusion of conflicting superproject config.h.
2025-08-20 08:52:22 -07:00
Jon Siwek
6b1b6b178a binpac: configure now writes directly to CMakeCache.txt
The intermediate BuildOptions.cmake file is no longer needed.
2025-08-20 08:52:22 -07:00
Jon Siwek
8366dd6bcb binpac: Minor style changes. 2025-08-20 08:52:22 -07:00
Jon Siwek
32db4e4447 binpac: CMake module path adjustment.
To allow inclusion from a superproject.
2025-08-20 08:52:22 -07:00
Jon Siwek
a05eb8b150 binpac: Added configure script to wrap cmake functionality 2025-08-20 08:52:22 -07:00
Jon Siwek
92f936fdb8 binpac: Added headers to install target.
Also set some convenience variables that mimic what a FindBinPAC
module would set.  These could be used by a superproject that
wants to decide whether to use an existing BinPAC installation
or (re)build from source.
2025-08-20 08:52:22 -07:00
Jon Siwek
47c64d7fed binpac: Changes to add an install target. 2025-08-20 08:52:22 -07:00