Commit ce0fede
authored
fix(vdm): prevent crash on multi-fragment sentences and modernize CMake test [CVE-2026-56770] (#264)
Guards `VdmStream::AddLine` against malformed multi-fragment AIS messages with missing or out-of-bounds sequence numbers, resolving assertion failures and out-of-bounds array access vulnerabilities. Additionally, modernizes the CMake build system to support automated C++ unit testing and AddressSanitizer (ASan) instrumentation.
**VDM Stream & Vulnerability Fixes (`libais/vdm.cpp`, `test/vdm_test.cpp`)**
- Added boundary validation in `VdmStream::AddLine` to reject sentences with total sentence count exceeding `kMaxSentences` (10).
- Added validation for multi-fragment messages (`tot > 1`) to reject out-of-bounds sequence numbers (`seq >= kNumSequenceChannels` / `kNoSequenceNumber`), preventing buffer overflows when indexing `incoming_sentences_[seq]`.
- Fixed `assert(tot == 1 || seq < kNumSequenceChannels)` so that single-line messages (which default to `kNoSequenceNumber` / 999999) do not trigger assertion failures in Debug and ASan builds.
- Added unit test coverage in `TEST_F(VdmTest, OverRangeSequence)` to verify that multi-fragment NMEA strings with empty sequence IDs (e.g., `!AIVDM,2,1,,A,177KQ@,0*4E`) are rejected cleanly.
**CMake Build & Test Suite Modernization (`CMakeLists.txt`, `src/CMakeLists.txt`, `src/test/CMakeLists.txt`)**
- Added `set(CMAKE_POLICY_VERSION_MINIMUM "3.5")` to ensure compatibility between CMake 4.x and embedded GoogleTest/GoogleMock rules in `third_party/`.
- Corrected C++ standard feature detection flags to check `-std=c++17` and `-std=c++20` properly.
- Added `ENABLE_ASAN` option to compile and link with AddressSanitizer (`-fsanitize=address -g -fno-omit-frame-pointer`).
- Integrated CTest and created `src/test/CMakeLists.txt` to automatically build all 30 C++ unit tests linked against `gmock_main` with `-Wno-deprecated-copy` silenced for third-party headers.
**AIS 7/13 Stream Formatting (`src/libais/ais7_13.cpp`)**
- Added `operator<<` formatting for `Ais7_13` to output message ID and MMSI.
Fixes this existing CI build failure that produced the following assertion abort:
```
[----------] 7 tests from VdmTest
[ RUN ] VdmTest.IgnoreNonAisMessages
vdm_test: vdm.cpp:325: bool libais::VdmStream::AddLine(const std::string&): Assertion `seq < kNumSequenceChannels' failed.
[ OK ] VdmTest.IgnoreNonAisMessages (0 ms)
[ RUN ] VdmTest.SingleLineAisMessage
[ OK ] VdmTest.SingleLineAisMessage (0 ms)
[ RUN ] VdmTest.QueueClean
Aborted (core dumped)
```
Based on the proposed fix by Google Jules in schwehr/libais-jules#20.
* Fixes #263
* Fixes https://nvd.nist.gov/vuln/detail/CVE-2026-567701 parent d108602 commit ce0fede
6 files changed
Lines changed: 52 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
30 | 43 | | |
31 | 44 | | |
32 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
325 | | - | |
326 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
330 | 334 | | |
331 | 335 | | |
332 | 336 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
470 | | - | |
| 470 | + | |
471 | 471 | | |
472 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
473 | 478 | | |
474 | 479 | | |
475 | 480 | | |
| |||
0 commit comments