Skip to content

Commit 7b1279b

Browse files
adversarial rx_parse tests; fix output-zeroing on empty payload
Add test_intrusive_rx.c with 16 golden adversarial tests for rx_parse, covering all three protocol versions (v0.1, v1.0, v1.1), version detection, tail-byte parsing, bit-field boundary checks, cross-version ambiguity, and rejection paths. Fix: move memset of output structs before the early-return size check so that outputs are always zeroed regardless of payload size. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b790e6f commit 7b1279b

File tree

3 files changed

+639
-2
lines changed

3 files changed

+639
-2
lines changed

libcanard/canard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,12 @@ static byte_t rx_parse(const uint32_t can_id,
10831083
CANARD_ASSERT(can_id < (UINT32_C(1) << 29U));
10841084
CANARD_ASSERT(out_v0 != NULL);
10851085
CANARD_ASSERT(out_v1 != NULL);
1086+
memset(out_v0, 0, sizeof(*out_v0));
1087+
memset(out_v1, 0, sizeof(*out_v1));
10861088
if (payload.size < 1) {
10871089
return 0;
10881090
}
10891091
CANARD_ASSERT(payload.data != NULL);
1090-
memset(out_v0, 0, sizeof(*out_v0));
1091-
memset(out_v1, 0, sizeof(*out_v1));
10921092

10931093
// Common items.
10941094
const canard_prio_t priority = (canard_prio_t)(can_id >> PRIO_SHIFT);

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ add_compile_options(-Wno-unused-function)
9999
gen_test_matrix(test_helpers "src/test_helpers.c")
100100
gen_test_matrix(test_intrusive_util "src/test_intrusive_util.c")
101101
gen_test_matrix(test_intrusive_tx "src/test_intrusive_tx.c")
102+
gen_test_matrix(test_intrusive_rx "src/test_intrusive_rx.c")
102103
# API tests.
103104
gen_test_single(test_api_tx "${library_dir}/canard.c;src/test_api_tx.cpp")
104105

0 commit comments

Comments
 (0)