From cad275ddcee054d54672b62da2cc085afa46bf9a Mon Sep 17 00:00:00 2001 From: evgeny Date: Fri, 23 Oct 2026 16:40:52 +0200 Subject: [PATCH] Check ACK receiver point diagnostics at buffer boundaries --- src/transport_layer/etcp_debug.c | 2 +- tests/test_etcp_session.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/transport_layer/etcp_debug.c b/src/transport_layer/etcp_debug.c index 543946ed6..8dc11337c 100644 --- a/src/transport_layer/etcp_debug.c +++ b/src/transport_layer/etcp_debug.c @@ -53,7 +53,7 @@ void etcp_dump_pkt_sections(struct ETCP_DGRAM* pkt, struct ETCP_LINK* link, int ack_count, len-offset, section_len); offset = len; break; } - if (ack_count) { + if (ack_count && pos < (int)sizeof(buf) - 1) { const uint8_t* point = data + offset + ETCP_ACK_BASE_SIZE + ack_count * ETCP_ACK_ENTRY_SIZE; uint64_t bytes = 0, time = 0; for (unsigned i = 0; i < 8; i++) { bytes |= (uint64_t)point[i] << (8*i); time |= (uint64_t)point[i+8] << (8*i); } diff --git a/tests/test_etcp_session.c b/tests/test_etcp_session.c index f0d51b1a8..41d17e4fc 100644 --- a/tests/test_etcp_session.c +++ b/tests/test_etcp_session.c @@ -95,6 +95,31 @@ static void debug_sequence_boundaries(void) { else CHECK(dump_count == 0 && dump_warnings == 0); } } + // Положительный ACK: footer полностью проверяется до чтения, следующая секция не теряется. + u_free(pkt); + unsigned ack_size = etcp_ack_section_size(1); + pkt = u_calloc(1, sizeof(*pkt) + 10 * ack_size); CHECK(pkt); + pkt->data[0] = ETCP_SECTION_ACK; pkt->data[1] = 1; + memset(pkt->data + ETCP_ACK_BASE_SIZE + ETCP_ACK_ENTRY_SIZE, 255, ETCP_ACK_RX_POINT_SIZE); + debug_set_category_level(DEBUG_CATEGORY_DUMP, DEBUG_LEVEL_DEBUG); + for (unsigned len = ETCP_ACK_BASE_SIZE; len < ack_size; len++) { + pkt->data_len = len; dump_count = dump_warnings = 0; dump_message[0] = 0; + etcp_dump_pkt_sections(pkt, NULL, 0); + CHECK(dump_count == 1 && dump_warnings == 1 && !strstr(dump_message, " rx=")); + } + pkt->data[ack_size] = ETCP_SECTION_TIMESTAMP; + pkt->data[ack_size+5] = ETCP_SECTION_PAYLOAD; + pkt->data[ack_size+6] = 42; pkt->data[ack_size+10] = 99; + pkt->data_len = ack_size + 5 + ETCP_PAYLOAD_HEADER_SIZE + 1; + dump_count = dump_warnings = 0; dump_message[0] = 0; + etcp_dump_pkt_sections(pkt, NULL, 0); + CHECK(dump_count == 1 && !dump_warnings && strstr(dump_message, " rx=18446744073709551615/18446744073709551615us")); + CHECK(strstr(dump_message, " ch_ts=0/0") && strstr(dump_message, " payload=1(seq=42 attempt=99)")); + for (unsigned i = 1; i < 10; i++) memcpy(pkt->data + i*ack_size, pkt->data, ack_size); + pkt->data_len = 10 * ack_size; + dump_count = dump_warnings = 0; dump_message[0] = 0; + etcp_dump_pkt_sections(pkt, NULL, 1); + CHECK(dump_count == 1 && dump_warnings == 1 && strstr(dump_message, " [truncated]")); debug_set_log_hook(NULL); debug_enable_console(console); debug_set_category_level(DEBUG_CATEGORY_DUMP, saved);