Commit graph

283 commits

Author SHA1 Message Date
Luca Deri
679f31085f Various JSON/CSV serialization/.deserialization fixes 2026-11-03 14:08:31 +01:00
Ivan Nardi
fbada8eac5 fuzz: add fuzz_alg_asn1_ber fuzzer for the ASN.1 BER helpers
Fuzz the public `ndpi_asn1_ber_decode_*()` functions, walking all the
(nested) TLVs and checking some basic invariants on the decoded values.

The initial corpus has real messages extracted from the test pcaps
(SNMP, Kerberos, LDAP), a X.509 certificate and some hand-crafted
edge cases (length/tag encodings, integers, deep nesting).

Update .gitignore with some missing fuzzing artifacts.
2026-11-02 09:10:29 +01:00
Copilot
91c58be4ea
Include fuzz_deserialization corpus in dist tarball (#3295)
* Initial plan

* Apply remaining changes

Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>
2026-10-23 21:37:48 +02:00
Ivan Nardi
b6611bf9ba
build,CI: fix some minor issues (#3281)
- fuzz/Makefile.am: remove stray 'cpp' token from fuzz_alg_anomalymodel_SOURCES
- CI: install libpcre2-dev (not libpcre3-dev) when testing --with-pcre2
- CI: replace bare 'make -j' / 'make -j all' with 'make -j $(nproc)'
2026-10-16 12:27:25 +02:00
Ivan Nardi
86435da5b8
Serializer: zero the deserializer in ndpi_init_deserializer_buf() (#3279)
ndpi_private_deserializer shares its layout with ndpi_private_serializer, and
ndpi_init_deserializer_buf() set only buffer.data/size/fmt before calling
ndpi_reset_serializer(). When the (attacker-controlled) format byte selects a
non-TLV format, reset_serializer() takes its JSON/CSV path and reads
serializer-only fields (multiline_json_array, inner_json) that a deserializer
never initializes. On a caller-provided, uninitialized deserializer this is a
use-of-uninitialized-value.

Found by OSS-Fuzz (MemorySanitizer)
2026-10-16 11:59:53 +02:00
Ivan Nardi
da1995058f
Merge commit from fork
The TLV deserializer (`ndpi_serializer.c`) could be driven into out-of-bounds
reads, an adjacent-heap info leak, a NULL-pointer crash and an infinite loop
by a malformed/truncated byte stream. These paths are reachable whenever an
embedder deserializes untrusted input (e.g. a collector reading nDPI TLV
records off a socket); nDPI itself only serializes, so no in-tree packet path
is affected.

Reported issues (GHSA-mmp7-3vgp-v8mg):
  1. `ndpi_deserialize_get_single_size()`: return type widened u_int16_t -> int
     so the -2 truncation sentinel survives for string/block/list types.
  2. `ndpi_deserialize_get_single_size()`: bounds-check each fixed-width numeric
     field (uint8..double) against the bytes remaining before returning a size.
  3. `ndpi_deserialize_get_single_string_size()`: guard `offset > buffer.size`
     before computing buff_diff, so it can no longer underflow.
  4. 'expected' accumulators widened u_int16_t -> u_int32_t across the
     deserialize paths, so two field sizes can no longer wrap mod 2^16.
  5. `ndpi_deserialize_clone_item()`: re-check the source holds 'expected' bytes
     before the memcpy, closing the heap over-read / info leak.

Additional issues found while fuzzing the fixed code (new `fuzz_deserialization`
target, see below), all in `ndpi_deserialize_clone_all()` on untrusted input:
  6. Infinite-loop DoS: the return value of `ndpi_deserialize_next()` was
     ignored, so a record that cannot advance the cursor looped forever.
     `clone_all()` now validates the whole record is present before reading it
     and breaks when `next()` reports an error.
  7. NULL / out-of-bounds string reads: `ndpi_deserialize_single_string()` now
     bounds the on-wire length to the buffer (returns {NULL,0} otherwise), and
     `ndpi_deserialize_key_string()` verifies the key subtype is a string before
     reading it (the guard `ndpi_deserialize_value_string()` already had).
  8. `atoi(NULL)` crash: ndpi_is_number() now treats NULL/empty as "not a
     number", so a NULL key can no longer reach `atoi()`.
  9. `atoi()` over-read on a numeric key: the `ndpi_serialize_binary_*()` helpers
      called `atoi()` on a counted, non-NUL-terminated key, reading past its
      length when the buffer continued with more digits. A bounded `ndpi_atoi_n()`
      now converts exactly key_len digits.

A new libFuzzer harness (`fuzz/fuzz_deserialization.cpp`) feeds untrusted bytes
directly to ndpi_init_deserializer_buf() + the clone/iterate APIs, with a seed
corpus reproducing every issue above.

Original report by Mike Myers (Apple).
2026-10-16 10:59:50 +02:00
Luca Deri
f9daaf170d
Dynamic host_server_name and add JA5 implementation(#3257) 2026-09-14 10:34:33 +02:00
Ivan Nardi
95fe8521ee fuzz: fix compilation 2026-09-07 08:10:43 +02:00
Luca Deri
61337dad12
Reworked code to split flow definition in core and metadata 2026-09-05 15:48:02 +02:00
Raja Muhammad Awais
4cae778e7e
fix: avoid unaligned reads in DNS and serializers (#3231)
fix: avoid unaligned reads in DNS and serializers

---------

Co-authored-by: RajaMuhammadAwais <1.19938988e+08+RajaMuhammadAwais@users.noreply.github.com>
2026-08-31 11:56:33 +02:00
Ivan Nardi
3eb6e65fbc fuzz: fix compilation 2026-08-25 18:08:07 +02:00
Luca Deri
d7c97ba097 Improved dual-license wording 2026-08-25 16:58:08 +02:00
Ivan Nardi
cd0f0c7c50
DNS: add (optional) detection over any port (on UDP) (#3236) 2026-08-25 11:04:14 +02:00
Raja Muhammad Awais
43b3731ea8
Detect DGA-like patterns in HTTP URL paths (fixes #2089) (#3228)
Some malware families (e.g. Emotet) encode DGA-generated tokens directly in
the HTTP URL path instead of the hostname, bypassing the existing hostname-
based DGA checks. This commit adds ndpi_check_dga_url_path(), which applies a
refined version of the DGA heuristic to URL path segments:

- Segments are stripped of file extensions, split into sub-tokens by
  '_', '-' and '.', and empty sub-tokens are ignored.
- Structured identifiers are excluded: hex hashes/numeric IDs, short
  alphanumeric resource IDs (alpha prefix followed by hex body), short
  tokens (at most two non-hex letters plus digits, a single letter group
  after up to four leading digits, and ASIN-style digit pairs followed by
  letters), and purely letter-based names.
- Remaining segments are flagged as DGA-like when they contain at least
  eight alphabetic characters with at most two vowels, or an identical-
  character run of eight or more, consistent with the hostname checks in
  ndpi_check_dga_name().

The check is invoked from the HTTP dissector when validating URLs and
emits the NDPI_SUSPICIOUS_DGA_DOMAIN risk with a descriptive info string.

Add a new fuzzer about it.

Close: #2089

Co-authored-by: RajaMuhammadAwais <1.19938988e+08+RajaMuhammadAwais@users.noreply.github.com>
Co-authored-by: Ivan Nardi <nardi.ivan@gmail.com>
2026-08-23 11:37:33 +02:00
Ivan Nardi
1f2606902c
License: non-commercial vs commercial applications (#3220)
* WIP

* Fix compilation of fuzzing

* Fix fuzzing compilation

* Cleaned up old quic contributed code (#3222)

Recode commits 713cdd0, 26df140

* QUIC: refactoring

* WIP

* WIP

* Revert "QUIC: refactoring"

This reverts commit 50afd07f28.

* QUIC: refactoring original Wireshark code (#3224)

* Added ability to specify in protocol definition, when a (partial) protocol
can change. This can be queries using a new APi call
named ndpi_can_partial_proto_classification_change()

* TLS: minor changes and remove same stale comments

* Fix out-of-bounds read of TLS certificate dates (#3225)

notBefore and notAfter are u_int32_t, but ndpi_tls2json() passed their
address to ndpi_gmtime_r() as a time_t *. Wherever time_t is 8 bytes this
reads 4 bytes past the field, picking up the adjacent member, so the value
handed to gmtime_r() is notBefore | (notAfter << 32) on little-endian.

gmtime_r() then fails on that out-of-range value and returns NULL, leaving
before/after NULL, so the "notbefore" and "notafter" fields are silently
dropped from the JSON output. On architectures that require aligned access
the 8-byte load traps instead of merely being wrong.

Convert to a real time_t instead of casting the address. The temporaries
are named not_before/not_after because notBefore/notAfter are already
char[32] buffers in the same function.

* WIP

* fuzz: fix compilation

---------

Co-authored-by: Luca Deri <lucaderi@users.noreply.github.com>
Co-authored-by: Luca Deri <deri@ntop.org>
Co-authored-by: shalseth <33956011+shalseth@users.noreply.github.com>
2026-08-22 17:57:28 +02:00
Ivan Nardi
0b9c2a2568
fuzz: improve coverage and add fuzzers for anomaly model and isolation forest algs (#3186) 2026-05-29 14:52:32 +02:00
Ivan Nardi
f404523791 fuzz: fix corpus name 2026-05-05 11:28:08 +02:00
Ivan Nardi
da372c59cc SSH: fix metadata extraction
```
==57403==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x5020000fc031 at pc 0x59c71d94f6c7 bp 0x7ffff45f54f0 sp 0x7ffff45f4ca8
WRITE of size 4294967295 at 0x5020000fc031 thread T0
    #0 0x59c71d94f6c6 in strncpy (/mnt/11a40362-265c-4ec3-8d95-2c65dbe1df34/builds/nDPI/build-fuzz/fuzz/fuzz_ndpi_reader_pl7m_simplest+0x94a6c6) (BuildId: 02db45bde4aa162f8fd4ed895ebf91307bbb6f4a)
    #1 0x59c71de540d8 in concat_hash_string /home/ivan/svnrepos/nDPI/src/lib/protocols/ssh.c:515:9
    #2 0x59c71de4a571 in ndpi_search_ssh_tcp /home/ivan/svnrepos/nDPI/src/lib/protocols/ssh.c:660:12
    #3 0x59c71de54df7 in search_ssh_again /home/ivan/svnrepos/nDPI/src/lib/protocols/ssh.c:219:3
    #4 0x59c71db95c84 in process_extra_packet /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:9752:9
    #5 0x59c71db4572c in ndpi_internal_detection_process_packet /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:10559:5
    #6 0x59c71db4486f in ndpi_detection_process_packet /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:10773:3
```
Found by oss-fuzz
2026-04-29 09:54:10 +00:00
Ivan Nardi
1eea474e90 fuzz: fixfuzz_http_parse fuzzers and add some basic corpora 2026-04-29 09:54:10 +00:00
Luca Deri
915ba442ee
Recoded some legaci nDPI code (#3170)
* Removed zattoo protocol

* Removed unused ndpi_bytestream_to_*** functions
Rewritten ndpi_handle_ipv6_extension_headers and ndpi_detection_get_l4_internal

* Uodared test results

* Recoded ndpi_init_packet()

* Cleaned up and recoded ndpi_parse_packet_line_info()

* Recoded and optimized dhcp and dhcp6 code

* Removed legacy code (zattoo) no longer used

* Fix fuzzing compilation and updtae unit tests results

* Zattoo: remove some leftovers

---------

Co-authored-by: Ivan Nardi <nardi.ivan@gmail.com>
2026-04-21 21:20:52 +02:00
parasol-aser
315a70591a
fuzz: harden ndpi_hex_decode and add targeted parser harnesses (#3163)
Closes #3159

Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
2026-04-20 16:21:30 +02:00
Ivan Nardi
836eefc083 fuzz: update dictionary 2026-04-20 13:52:48 +02:00
Ze Sheng
e3801f4d14
fuzz: reset flow state and populate headers in fuzz_is_stun (#3128)
Fix three issues in the STUN fuzzer that reduce fuzzing effectiveness:

1. ndpi_flow is static and never reset between calls, causing stale
   state from previous inputs to affect subsequent ones. This makes
   fuzzing results non-reproducible and prevents proper per-input
   isolation. Fix: memset flow to zero at the start of each call and
   call ndpi_free_flow_data() at the end for cleanup.

2. iph (IP header) is all zeros, meaning version=0, ihl=0, protocol=0.
   This is not a valid IPv4 header and causes is_stun() to skip
   protocol-specific code paths. Fix: set version=4, ihl=5, and
   protocol=17 (UDP) or 6 (TCP) depending on the build variant.

3. udph/tcph (transport headers) are all zeros, meaning port=0.
   STUN-related code paths check for specific ports. Fix: set source
   and destination ports to 3478 (STUN default).

Since fuzz_is_stun_tcp.c is a symlink to fuzz_is_stun.c, this fix
applies to both UDP and TCP variants via the existing STUN_TCP ifdef.
2026-03-09 11:12:58 +01:00
Ivan Nardi
31c3610ea7 ndpiReader: better memory statistics: malloc vs realloc 2026-03-04 18:27:58 +01:00
Luca Deri
11807612e2
Extended ja4 protocol rule with the ability to specify tls blocks (#3125) 2026-02-20 23:15:02 +01:00
Ivan Nardi
ec2e9db2e5 fuzz: fix a warning
```
../../fuzz/fuzz_alg_crc32_md5.c:61:7: error: assigning to 'char *' from 'u_char *' (aka 'unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Werror,-Wpointer-sign]
   61 |   enc = ndpi_hex_encode(data, size);
      |       ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

```
2026-02-18 13:33:25 +01:00
Ivan Nardi
1052c6ecf1 fuzz: fuzz_dga: set a reasonable limit on entries size 2026-02-17 10:06:42 +01:00
Ivan Nardi
411b3ad202 fuzz: add a new fuzzer to test ndpi_match_custom_category() 2026-02-10 13:38:33 +00:00
Ivan Nardi
22b4c43f26 fuzz: allow allocation failures in fuzz_tls_certificate 2026-02-10 13:38:33 +00:00
Ivan Nardi
97392d9122 fuzz: fix configuration loading in fuzz_init_detection_module()
See c37937a21
2026-02-10 13:38:33 +00:00
Ivan Nardi
350d553299
fuzz: fuzz_config: restore custom logic for memory allocation failure (#3105)
It seems nalloc doesn't work with `FuzzedDataProvider.h`; see
https://github.com/catenacyber/nallocfuzz/issues/4.
Partial revert of f67293e9f
2026-01-27 16:59:49 +01:00
Ivan Nardi
349f4568a7
fuzz: make fuzzing of config parameters more generic (#3102)
That means that we need to somehow export the parameters list
2026-01-26 12:36:44 +01:00
Ivan Nardi
f67293e9fc
fuzz: test *alloc/read/write/recv/send failures via nallocfuzz (#3082)
See: https://github.com/catenacyber/nallocfuzz

Add a new fuzzer for testing "data-path" code; reuse existing
`fuzz_config` for testing initialization phase
2026-01-14 15:44:38 +01:00
Ivan Nardi
575a2b238a
Fix fuzzer dependencies to rebuild when library changes (#3078)
Five fuzzers (fuzz_process_packet, fuzz_ndpi_reader, fuzz_ndpi_reader_alloc_fail,
fuzz_ndpi_reader_payload_analyzer, and fuzz_tls_certificate) were not rebuilding
when libndpi.a changed because their explicit DEPENDENCIES declarations only
included dictionary files.

In Automake, when prog_DEPENDENCIES is explicitly set, it overrides the automatic
dependency generation from LDADD. This caused these fuzzers to miss the library
dependency that the other 55 fuzzers correctly inherited.

This commit adds $(top_builddir)/src/lib/libndpi.a to the DEPENDENCIES for all
5 affected fuzzers, ensuring they rebuild whenever the library changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 17:10:05 +01:00
Luca Deri
04ee0bb48b nDPI fingerprint calculation
- Added the ability to exclude TCP fingerprint via metadata.ndpi_fingerprint_ignore_tcp_fp configuration
- TLS blocks not include the block lenght only for Client and Server hello, ignored for all other blocks
2026-01-09 12:00:10 +01:00
Luca Deri
d3206230bb TLS blocks timing is not hidden by default.
Use --cfg "tls,tls_blocks_show_timing,1" to show it
2026-01-09 09:24:35 +01:00
Luca Deri
901e317422
Added --cfg "tls,max_num_blocks_to_analyze,X" for dynamically setting TLS blocks number (#3073)
* Added --cfg "tls,max_num_blocks_to_analyze,X" where if X > 0 TLS blocks are analyzed

Example --cfg "tls,max_num_blocks_to_analyze,8"

* TLS blocks now include a time-delta (msec) with respect to the previous TLS block.
The format is @<msec delta>. Example:

 "tls_blocks": [
         "22:1=232@191",
         "22:2=-122@5,20=-1@5,21=-23@5,21=-905@5,21=-281@5",
         "21=-53@0",
         "20=1@3,21=53@3",
         "21=-218@119,21=-218@119",
 ]
2026-01-08 23:36:13 +01:00
Luca Deri
8aaff75ede
Fixes protocol inconsistencies (#3069)
* Added code to address inconsistencies
* Added check for discarding dig errors
* Temporarily disabled whatsapp script: an update is required. See https://developers.facebook.com/docs/whatsapp/on-premises/sunset
2025-12-31 20:54:35 +01:00
Ivan Nardi
87440c59bb
fuzz: extend fuzzing coverage and fix loading of TCP fingerprints from file (#3059) 2025-12-09 14:03:46 +01:00
Ivan Nardi
11be5b31c0
Fix fuzzing instrumentation broken by e49e93cc (#3054)
Commit e49e93cc17 broke coverage
instrumentation for fuzzing targets due to two issues with how
AM_LDFLAGS and target-specific CFLAGS/CXXFLAGS interact.

Problems:
---------
1. Missing AM_LDFLAGS in link command:
   The commit changed LIB_FUZZING_ENGINE from being added to LDFLAGS
   to being added to AM_LDFLAGS (line 26):
     Before: `LDFLAGS += $(LIB_FUZZING_ENGINE)`
     After:  `AM_LDFLAGS += $(LIB_FUZZING_ENGINE)`

   However, FUZZ_LINK_COMMAND (line 34) was not updated to include
   `$(AM_LDFLAGS)`, so `-fsanitize=fuzzer` was missing from link commands.

2. Target-specific CFLAGS/CXXFLAGS override AM_CFLAGS/AM_CXXFLAGS:
   When automake sees target-specific CFLAGS (like fuzz_ndpi_reader_CFLAGS),
   it COMPLETELY REPLACES AM_CFLAGS instead of adding to it. Even empty
   assignments like `fuzz_process_packet_CFLAGS =` mean "use nothing"
   rather than "use AM_CFLAGS". This means `-fsanitize=fuzzer` from
   AM_CFLAGS was not being used during compilation.

   Example:
     `AM_CFLAGS = @NDPI_CFLAGS@ -fsanitize=fuzzer`
     `fuzz_ndpi_reader_CFLAGS = -I$(top_srcdir)/example/`

   Result: Only `-I$(top_srcdir)/example/` is used, AM_CFLAGS is ignored!

Without `-fsanitize=fuzzer` during both compilation and linking:
- No coverage instrumentation is generated
- LibFuzzer cannot collect coverage information
- Fuzzer warns: "WARNING: no interesting inputs were found so far.
  Is the code instrumented for coverage?"

Solutions:
----------
1. Add `$(AM_LDFLAGS)` to FUZZ_LINK_COMMAND (line 34) before
   `$(LDFLAGS)`
   This ensures LIB_FUZZING_ENGINE is included during linking.

2. For targets with non-empty CFLAGS/CXXFLAGS, prefix with `$(AM_CFLAGS)/$(AM_CXXFLAGS)`:
   Changed: `fuzz_*_CFLAGS = -DFOO`
   To:      `fuzz_*_CFLAGS = $(AM_CFLAGS) -DFOO`

3. For targets with empty CFLAGS/CXXFLAGS, remove the assignments entirely:
   Removed: `fuzz_*_CFLAGS =`

   This allows automake to automatically use AM_CFLAGS/AM_CXXFLAGS.

The flag ordering (package flags before user flags) is maintained.

Testing:
--------
Before fix:
  $ ./fuzz_ndpi_reader -runs=10
  INFO: Seed: 437565050
  WARNING: no interesting inputs were found so far. Is the code instrumented for coverage?

After fix:
  $ ./fuzz_ndpi_reader -runs=10
  INFO: Loaded 1 modules   (4802 inline 8-bit counters)
  INFO: Loaded 1 PC tables (4802 PCs)
  #2  INITED cov: 4 ft: 5 corp: 1/1b exec/s: 0 rss: 81Mb
  #10 DONE   cov: 4 ft: 5 corp: 1/1b lim: 4 exec/s: 0 rss: 81Mb

  $ ./fuzz_process_packet -runs=10
  INFO: Loaded 1 modules   (25 inline 8-bit counters)
  INFO: Loaded 1 PC tables (25 PCs)
  #2  INITED cov: 2 ft: 2 corp: 1/1b exec/s: 0 rss: 65Mb
  #10 DONE   cov: 2 ft: 2 corp: 1/1b lim: 4 exec/s: 0 rss: 65Mb

Verified with:
  CC=clang CXX=clang++ ./configure --enable-fuzztargets --with-sanitizer
  make -j4
  ./fuzz/fuzz_ndpi_reader -runs=10
  ./fuzz/fuzz_process_packet -runs=10

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 22:31:59 +01:00
Ivan Nardi
5cae544a40
s7comm: small fixes and extend tests (#3046) 2025-11-30 15:52:22 +01:00
Ivan Nardi
44ed6f8e91
Build system: Fix out-of-tree builds for fuzz targets (#3042)
Replace relative path references (../) with $(top_srcdir) in
fuzz/Makefile.am to properly support out-of-tree builds (VPATH builds).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-24 21:10:36 +01:00
Ivan Nardi
b2357c29c3
Build system: Standardize and improve clean/distclean targets (#3039)
This commit improves the nDPI build system by standardizing cleanup
targets, improving portability, and ensuring complete removal of
generated files during `make distclean`.

Changes:

1. Standardize clean targets (replace /bin/rm with portable $(RM))

2. Add distclean-local targets for complete cleanup

3. Add missing clean/distclean targets

4. Remove obsolete commented-out curl detection code

5. fuzz/Makefile.am: Fix out-of-tree build compatibility by replacing hardcoded
   relative paths (../example/fuzz_*.o) with proper $(top_builddir) variables.
   Add distclean-local target.
2025-11-24 18:42:03 +01:00
Ivan Nardi
e49e93cc17
Build system: Respect user CFLAGS and LDFLAGS, remove hardcoded -g (#3034)
Fix improper handling of CFLAGS and LDFLAGS throughout the build system.
Also remove hardcoded debug flags that prevented production builds
without symbols.

Problems:
---------
1. CFLAGS/LDFLAGS handling:
   The build system was using `CFLAGS +=` and `LDFLAGS +=` to append
   package-specific flags, which modifies the user's environment variables
   instead of keeping package and user flags separate. This caused:
   - User-specified optimization levels being overridden by package defaults
   - Inability to properly override flags at configure or make time
   - Problems with cross-compilation and embedded toolchains

2. Hardcoded -g flags:
   Debug symbols (-g) were hardcoded in several Makefiles, forcing debug
   symbols in all builds including production. This caused:
   - Larger binary sizes (library and tools)
   - No way to build without debug symbols
   - Conflicts with user's debug level preferences (-g1, -g2, -g3)
   - Redundancy with configure options (--enable-debug-build)

Solutions:
----------
1. Implement proper CFLAGS/LDFLAGS separation using AM_CFLAGS/AM_LDFLAGS:
   - Added `CFLAGS = @CFLAGS@` to preserve configure-time flags
   - Added `LDFLAGS = @LDFLAGS@` to preserve configure-time flags
   - Changed `CFLAGS +=` to `AM_CFLAGS =` and `AM_CFLAGS +=`
   - Changed `LDFLAGS +=` to `AM_LDFLAGS =` and `AM_LDFLAGS +=`
   - Updated compilation rules: $(CC) $(AM_CFLAGS) $(CFLAGS) ...
   - Updated linking rules: $(CC) ... $(AM_LDFLAGS) $(LDFLAGS) ...

2. Remove all hardcoded -g flags from Makefiles:
   - Debug symbols now controlled via configure (--enable-debug-build)
     or user CFLAGS (e.g., CFLAGS="-g3")

Flag ordering ensures:
- Package flags come first (e.g., -O2, -fPIC)
- User flags come after and can override (e.g., -O3)
- Last flag wins for conflicting options

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-20 12:43:11 +01:00
Ivan Nardi
9587059598 Build system: Improve portability, parallelization, and VPATH builds
This commit implements comprehensive improvements to the nDPI build system
to enhance portability, enable parallel testing, and ensure reliable
out-of-tree (VPATH) builds across all platforms.

Changes:

1. Optimize library linking order (configure.ac, all Makefiles)
   - Reorder ADDITIONAL_LIBS to follow proper dependency hierarchy
   - Move low-level libraries (libm) to end of link line
   - Ensures compatibility with --as-needed linker flag
   - Improves LTO and static linking support

2. Fix VPATH build dependencies (all Makefiles)
   - Add explicit dependencies on generated headers (ndpi_config.h, ndpi_define.h)
   - Prevents race conditions in parallel builds (make -j)
   - Ensures headers exist before compilation starts

3. Replace mkdir -p with portable $(MKDIR_P) macro

4. Enable parallel test execution (configure.ac)
   - Add 'parallel-tests' option to AM_INIT_AUTOMAKE
   - Allows test suites to run concurrently during 'make check'

5. Add defensive .NOTPARALLEL directive (Makefile.am)
   - Prevents race conditions if 'make -j clean distclean' is run

6. Fix clean target completeness (src/lib/Makefile.in)
   - Remove all .so symlinks (libndpi.so, libndpi.so.N)
   - Add cleanup for Windows DLL files (*.dll)
   - Explicitly remove versioned shared libraries

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Ivan Nardi <nardi.ivan@gmail.com>
2025-11-18 21:08:53 +01:00
Ivan Nardi
6bb0585a27
fuzz: minor improvements. Be sure the right configuration is always loaded (#3031) 2025-11-18 14:11:16 +01:00
Ivan Nardi
334cc23a8e
Build system improvements and fixes (#3026)
- Fixed some typos and inconsistent option names in error messages
- Improved Git Detection in configure script
- Added informative warnings when optional dependencies are missing
- Improve error handling on autogen.sh script
- Simplify fuzzing Makefile, creating common FUZZ_LINK_COMMAND template for all fuzz targets
- Added *_DEPENDENCIES declarations for fuzz targets with dictionaries
- Implemented incremental corpus building to avoid unnecessary rebuilds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-18 10:32:04 +01:00
Ivan Nardi
1b6db29080 fuzz: fix 2025-11-13 14:14:33 +01:00
Ivan Nardi
173f718f5a
fuzz: another attempt to fix introspector builds (#3025) 2025-11-12 19:57:14 +01:00
Ivan Nardi
e7737bb578
fuzz: add fuzzer to test ranking algorithm (#3024) 2025-11-09 16:49:35 +01:00