Skip to content

Commit 977a1e4

Browse files
fix stale-check signed overflow; add adversarial admission tests
Fix undefined behavior in rx_session_solve_admission(): the expression `ts > (last_admission_ts + timeout)` overflows int64_t when last_admission_ts == BIG_BANG (INT64_MIN). Rearranged to the equivalent `(ts - timeout) > last_admission_ts` which is safe for non-negative ts and timeout. Add test_intrusive_rx_admission.c: 14 test cases covering the admission state machine exhaustively — truth table, fresh/stale boundary conditions, continuation frames, preemption scenarios (including the documented TID-rollover edge case), record_admission masking, and integration sequences (TID progression, duplicate rejection, interface failover, zero timeout, duplicate-after-preemption limitation). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d52e640 commit 977a1e4

File tree

3 files changed

+557
-1
lines changed

3 files changed

+557
-1
lines changed

libcanard/canard.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ static bool rx_session_solve_admission(const rx_session_t* const ses,
14041404
const bool fresh = (transfer_id != ses->last_admitted_transfer_id) || // always accept if transfer-ID is different
14051405
(priority != ses->last_admitted_priority); // or we switched the priority level
14061406
const bool affine = ses->iface_index == iface_index;
1407-
const bool stale = ts > (ses->last_admission_ts + ses->owner->transfer_id_timeout);
1407+
const bool stale = (ts - ses->owner->transfer_id_timeout) > ses->last_admission_ts;
14081408
return (fresh && affine) || (affine && stale) || (stale && fresh);
14091409
}
14101410

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ 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")
102102
gen_test_matrix(test_intrusive_rx "src/test_intrusive_rx.c")
103+
gen_test_matrix(test_intrusive_rx_admission "src/test_intrusive_rx_admission.c")
103104
# API tests.
104105
gen_test_single(test_api_tx "${library_dir}/canard.c;src/test_api_tx.cpp")
105106

0 commit comments

Comments
 (0)