Skip to content

Commit 7eec386

Browse files
committed
Guard ICMP RX state on fifo push failure
F/1779
1 parent 297e7c3 commit 7eec386

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/test/unit/unit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ Suite *wolf_suite(void)
663663
tcase_add_test(tc_proto, test_icmp_try_recv_mismatch_local_ip);
664664
tcase_add_test(tc_proto, test_icmp_try_recv_mismatch_src_port);
665665
tcase_add_test(tc_proto, test_icmp_try_recv_mismatch_remote_ip);
666+
tcase_add_test(tc_proto, test_icmp_try_recv_full_fifo_does_not_signal_readable);
666667
tcase_add_test(tc_proto, test_wolfip_recv_on_not_for_us);
667668
tcase_add_test(tc_proto, test_wolfip_recv_on_filter_drop_eth);
668669
#if WOLFIP_ENABLE_FORWARDING

src/test/unit/unit_tests_tcp_ack.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,53 @@ START_TEST(test_icmp_try_recv_mismatch_remote_ip)
27042704
}
27052705
END_TEST
27062706

2707+
START_TEST(test_icmp_try_recv_full_fifo_does_not_signal_readable)
2708+
{
2709+
struct wolfIP s;
2710+
struct tsocket *ts;
2711+
struct wolfIP_icmp_packet icmp;
2712+
uint32_t frame_len;
2713+
uint32_t fifo_used;
2714+
int ret;
2715+
2716+
wolfIP_init(&s);
2717+
mock_link_init(&s);
2718+
2719+
ts = icmp_new_socket(&s);
2720+
ck_assert_ptr_nonnull(ts);
2721+
ts->local_ip = 0x0A000001U;
2722+
ts->remote_ip = 0x0A000002U;
2723+
ts->src_port = 0x1234U;
2724+
ts->last_pkt_ttl = 77U;
2725+
ts->events = 0U;
2726+
2727+
memset(&icmp, 0, sizeof(icmp));
2728+
icmp.ip.len = ee16(IP_HEADER_LEN + ICMP_HEADER_LEN);
2729+
icmp.ip.src = ee32(ts->remote_ip);
2730+
icmp.ip.dst = ee32(ts->local_ip);
2731+
icmp.ip.ttl = 29U;
2732+
icmp.type = ICMP_ECHO_REPLY;
2733+
icmp_set_echo_id(&icmp, ts->src_port);
2734+
frame_len = (uint32_t)(ETH_HEADER_LEN + IP_HEADER_LEN + ICMP_HEADER_LEN);
2735+
2736+
while (fifo_can_push_len(&ts->sock.udp.rxbuf, frame_len)) {
2737+
ret = fifo_push(&ts->sock.udp.rxbuf, &icmp, frame_len);
2738+
ck_assert_int_eq(ret, 0);
2739+
}
2740+
2741+
fifo_used = fifo_len(&ts->sock.udp.rxbuf);
2742+
ck_assert_uint_gt(fifo_used, 0U);
2743+
ck_assert_int_eq(fifo_can_push_len(&ts->sock.udp.rxbuf, frame_len), 0);
2744+
2745+
icmp.ip.ttl = 42U;
2746+
icmp_try_recv(&s, TEST_PRIMARY_IF, &icmp, frame_len);
2747+
2748+
ck_assert_uint_eq(fifo_len(&ts->sock.udp.rxbuf), fifo_used);
2749+
ck_assert_uint_eq(ts->last_pkt_ttl, 77U);
2750+
ck_assert_uint_eq(ts->events & CB_EVENT_READABLE, 0U);
2751+
}
2752+
END_TEST
2753+
27072754
START_TEST(test_wolfip_recv_on_not_for_us)
27082755
{
27092756
struct wolfIP s;

src/wolfip.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,9 +1975,10 @@ static void icmp_try_recv(struct wolfIP *s, unsigned int if_idx,
19751975
continue;
19761976
if ((int)frame_len < ee16(icmp->ip.len) + ETH_HEADER_LEN)
19771977
continue;
1978-
fifo_push(&t->sock.udp.rxbuf, icmp, frame_len);
1979-
t->last_pkt_ttl = icmp->ip.ttl;
1980-
t->events |= CB_EVENT_READABLE;
1978+
if (fifo_push(&t->sock.udp.rxbuf, icmp, frame_len) == 0) {
1979+
t->last_pkt_ttl = icmp->ip.ttl;
1980+
t->events |= CB_EVENT_READABLE;
1981+
}
19811982
}
19821983
}
19831984

0 commit comments

Comments
 (0)