From nobody Thu Oct 22 00:45:41 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4j96rj6Qdbz6wqfb for ; Thu, 22 Oct 2026 00:45:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4j96rj5wtLz3Ld6 for ; Thu, 22 Oct 2026 00:45:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792629941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wYbdKrZr9uci1Y3lk5UEhJUkkjORrdCT1CF9JYbUJKY=; b=xc1XdCICYpVPCIFEgVRxsPOgAtcqkDTwZ51ea9svc1vmXnyGHaG0LIsWRhihJBuwTRbh4K aJZ7LoD5bOmOpkBOTYcvooSvEY8bVWklWfVe6mP8pTZkAh70PP6RKSFoflqACYtbjuT4QX r8rqSVNuCqhz8BHIyoHv8crwzPGzhBB1Dccr8oYmlFrN9HfIVGNyUbD+BfCW/N3k6/xtLG JwlDN5A83Hx/a2CsZoq0ZDRiIgqCHNnwebXVD8BolHWLcmV0VTz6sytpnP1JGGrM6NYlRy RllDAI8YR8ErnbWz0ah1SzipWb4NyBlDK6LLZdr/2OSWJYBgF1dOnMoaB2GchQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792629941; b=Zbe2CJ4v21MSmY9WAtDLQ7WFg45rndfq7xVdfuaBtfZqe7LujAI4PKG+0FdIU2ckxUDeOA yzsqpk4kvx+GjZODyhDszZi1ZIos+BHApSuuilpie94cEVarq7GWKvh6SuBHsawJSpHPDU VmW7iW76f26rJViD4uUP7qpMTXs8AsRB8zooJkPsdDrO47b+LPFnLSwW4uaC0aiiGrAEUl aQzcBrGPlzvPWWMMqHkBxjPqFhv3bTfAgaiwyzBs/qjIxcHZuGYh/uEnDZdI7ElxiYanwG M9LuFfv9rngpJtusVjHtJ7hjw+nQn6v+1X7+j/k2kuyGzkrnoxmuxfM8nEy2mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792629941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wYbdKrZr9uci1Y3lk5UEhJUkkjORrdCT1CF9JYbUJKY=; b=SJnEYmf6wI14WB1Xxs1OhjPPSQuSPXVQA9kRCSQlrJcrRRK2cPMkF0zky2SZohqMXTqfzt 9Z45x1q+J+bqRP/ZQkSb3HuAMM7nbeSX+RIh6Ewb3Jjij1/xqRziZooGIQkvUN0Ph/bL7P V21E7lvZoo8sb5bLfAk1MJ66vM52IfKJ4hOds2kIaw+L2bzyc7mqMihh8qB3SW6GCNFwuY Nk6KOvAMMSDeXZxkWmcENZsAiA8tEuVA4cKtO3JZQO06MuPKI8w5u1LcsKvhpPoDbVaj/8 Y6hSi1Pbjmo3aJOtIr1wlOVCZGIUyYtn8KudtLjLc147849UfrXjSoEpgPp3/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j96rj4vk0zJJS for ; Thu, 22 Oct 2026 00:45:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 40c9c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 22 Oct 2026 00:45:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Maxim Konovalov Subject: git: 4292233234f3 - stable/15 - ping: do a better job with what we received from the net, part 2 List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: maxim X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 4292233234f36ccab7c1a8521fa6d68a8130e05a Auto-Submitted: auto-generated Date: Thu, 22 Oct 2026 00:45:41 +0000 Message-Id: <6ad95cb5.40c9c.60ae1584@gitrepo.freebsd.org> The branch stable/15 has been updated by maxim: URL: https://cgit.FreeBSD.org/src/commit/?id=4292233234f36ccab7c1a8521fa6d68a8130e05a commit 4292233234f36ccab7c1a8521fa6d68a8130e05a Author: Maxim Konovalov AuthorDate: 2026-09-16 18:42:00 +0000 Commit: Maxim Konovalov CommitDate: 2026-10-22 00:10:12 +0000 ping: do a better job with what we received from the net, part 2 When we see a difference between the payload we sent and what we received, we dump both but we were not prepared for the case when the received payload is less than we sent. In this case we were trying to dump more than needed. Funny enough, 23 years ago I already fixed a similar issue here but didn't pay attention to this small dumping loop. Test written by jlduran. Reviewed by: jlduran MFC after: 1 month Found with: Claude Code Sonnet 5 Differential Revision: https://reviews.freebsd.org/D59556 Differential Revision: https://reviews.freebsd.org/D59582 (cherry picked from commit 0b9434d707c71de7b1b62e400e6e780224f0384d) --- sbin/ping/ping.c | 6 ++++-- sbin/ping/tests/test_ping.py | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index ebad14c59823..b7043eee1709 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1102,7 +1102,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) const u_char *icmp_data_raw; ssize_t icmp_data_raw_len; double triptime; - int dupflag, i, j, recv_len; + int avail, dupflag, i, j, recv_len; int8_t hlen; uint16_t seq; static int old_rrlen; @@ -1266,9 +1266,11 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) (void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x", i, *dp, *cp); (void)printf("\ncp:"); + avail = (int)MIN((ssize_t)datalen, + i + cc); cp = (u_char*)(buf + hlen + offsetof(struct icmp, icmp_data)); - for (i = 0; i < datalen; ++i, ++cp) { + for (i = 0; i < avail; ++i, ++cp) { if ((i % 16) == 8) (void)printf("\n\t"); (void)printf(" %2x", *cp); diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py index 88164c2ab816..51b8287814aa 100644 --- a/sbin/ping/tests/test_ping.py +++ b/sbin/ping/tests/test_ping.py @@ -80,6 +80,10 @@ def build_response_packet(echo, ip, icmp, oip_ihl, special): # Build a package with a wrong last byte payload_no_last_byte = sc.bytes_hex(load)[:-2] load = (sc.hex_bytes(payload_no_last_byte)) + b"\x00" + if special == "short-wrong": + # Build a short package with a wrong last byte + payload_no_last_byte = sc.bytes_hex(load)[:-4] + load = (sc.hex_bytes(payload_no_last_byte)) + b"\x00" if special == "not-mine": # Modify the ICMP Identifier field oicmp.id += 1 @@ -202,7 +206,7 @@ def pinger( :keyword oip_ihl: Inner packet's Internet Header Length, defaults to None :type oip_ihl: class:`scapy.fields.BitField`, optional :keyword special: Send a special packet - one of `no-payload`, `not-mine`, - `tcp`, `udp`, `wrong` or `warp`, defaults to None + `short-wrong`, `tcp`, `udp`, `wrong` or `warp`, defaults to None :type special: str, optional :keyword icmp_pptr: ICMP pointer, defaults to 0 :type icmp_pptr: class:`scapy.fields.ByteField` @@ -1464,6 +1468,40 @@ round-trip min/avg/max/stddev = /// ms }, id="_0_0_special_wrong", ), + pytest.param( + { + "src": "192.0.2.1", + "dst": "192.0.2.2", + "icmp_type": 0, + "icmp_code": 0, + "special": "short-wrong", + }, + { + "returncode": 0, + "stdout": """\ +PATTERN: 0x01 +PING 192.0.2.2 (192.0.2.2): 56 data bytes +63 bytes from: icmp_seq=0 ttl= time= ms +wrong total length 83 instead of 84 +wrong data byte #54 should be 0x1 but was 0x0 +cp: xx xx xx xx xx xx xx xx + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 +dp: xx xx xx xx xx xx xx xx + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + +--- 192.0.2.2 ping statistics --- +1 packets transmitted, 1 packets received, 0.0% packet loss +round-trip min/avg/max/stddev = /// ms +""", + "stderr": "", + "redacted": True, + }, + id="_0_0_special_short_wrong", + ), ] @pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata)