From bdb1415d1419ddf0ec3be02fd049e0605dce8420 Mon Sep 17 00:00:00 2001 From: Erik Auerswald Date: Sat, 30 Nov 2024 19:12:28 +0100 Subject: [PATCH] stricter response type checking When sending an ICMP Echo message, accept only an Echo Reply message as a normal response. When sending an ICMP Timestamp message, accept only an ICMP Timestamp message as a normal response. This could matter when multiple fping processes are running in parallel, some using Echo, others Timestamp messages. --- src/fping.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fping.c b/src/fping.c index 029341f..1f57aa1 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2218,7 +2218,8 @@ int decode_icmp_ipv4( icp = (struct icmp *)(reply_buf + hlen); - if (icp->icmp_type != ICMP_ECHOREPLY && icp->icmp_type != ICMP_TSTAMPREPLY) { + if ((icmp_request_typ == 0 && icp->icmp_type != ICMP_ECHOREPLY) || + (icmp_request_typ == 13 && icp->icmp_type != ICMP_TSTAMPREPLY)) { /* Handle other ICMP packets */ struct icmp *sent_icmp; SEQMAP_VALUE *seqmap_value; @@ -2233,7 +2234,9 @@ int decode_icmp_ipv4( sent_icmp = (struct icmp *)(reply_buf + hlen + ICMP_MINLEN + sizeof(struct ip)); - if ((sent_icmp->icmp_type != ICMP_ECHO && sent_icmp->icmp_type != ICMP_TSTAMP) || sent_icmp->icmp_id != ident4) { + if ((icmp_request_typ == 0 && sent_icmp->icmp_type != ICMP_ECHO) || + (icmp_request_typ == 13 && sent_icmp->icmp_type != ICMP_TSTAMP) || + sent_icmp->icmp_id != ident4) { /* not caused by us */ return -1; } -- 2.43.0