From nobody Thu Sep 17 00:37:14 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 4hlcK7276yz6sZ0p for ; Thu, 17 Sep 2026 00:37:15 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hlcK709Qsz4RlT for ; Thu, 17 Sep 2026 00:37:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789605435; 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=WwCYyXuBn78WU+uc5iRrKkh9ZUCm4cjeV+n6O20WcKI=; b=Y2gaIs6VuH+NBmi6+krJlPuoiWGVfKD0v64Fi/NBnQyfhPktffMOyFEWK9XvuKYvxjxXIi 31Al+LUssWHcFnf1PfnQpxO0aqr16R+38p3M/4YSupufTD3KrdThpq2lQsrnpiTQGzlBY8 MfKWIoLm37MphmAQ6VYCYQZb7SpO8UBtqobMZnpFfAz7I2/fzd0U2Z1JjIwUNRQVI94gfW 3CUDTam20KFFaK6JYNRnRIEKEs0ALbh4Pb7rR+iv3QYyS7Fi2LaPa9U1/gEjFWEtL33gLa SZE79cz96n/HSIMQ0lzyLFiVAwkGygzpB5f+kqJTlmhkrA6D72TYLr9PNzjNYw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789605435; b=i2z9DtIiFKdbTNzTkSQJleEOVPE4hjh05pcZzPRIMkgfr63U7F4HSdhGRqC5Bx/einoY3p 4NyYUjJX5tVSjXL5LfRTWb5DYPR7kkNAd8eIJdzqLMg9vxSPa/76eamkoYJ8E6T1kwMxCd H22SF36RoeE3/XOV4+fLj+VV/AKsujsDgJf8osmJMUuJVoGc+tLu0O0mRNGxJWUNRhhWip 8e5Oce/xT5ZzjtR3BBnjHV0Fa8jlJeZhdcfNfPWQceZHsJ0zQwP1I9/unboGuvSOfRV8/q BjOoA3NZnx6Kq+AUCnI/2noNXXC7zysEiJ7y7UCX02c0a6bUKq19AvTpr3HTJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789605435; 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=WwCYyXuBn78WU+uc5iRrKkh9ZUCm4cjeV+n6O20WcKI=; b=gxinIoDOZxf22ptQQCvpsDEmwcur3eK7o/u3iIgNzz2j2N0fmjpoX2m9UxsyBOcpOj+aLC g9rFspG5W6wd6mLEh2/Fv2k3WjfhoZ9/68l5/ADGzawt9KpdnAlqn8buyq7dhoEFZd6nnD sT7xVHGVrg+uKcjHOXut9akvU914nE84CvJlFocBBpezKZ9UJ2KqcEPK7Cht3y1LwGYNNX BM0AvzjJoTlkwj8zBK9MLwQGOQ0XDTc+JqoQdULtpqsubAc1uCsnyc+Lnn62n682fvlIDG LqaVTBRFtpo9mPc+CeZAZBCHGkfCLYUnzRYr6Erie//lL+rSIJWmDSA0GgSqnA== 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 4hlcK666ksz18gX for ; Thu, 17 Sep 2026 00:37:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 317b0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 17 Sep 2026 00:37:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Maxim Konovalov Subject: git: 0b9434d707c7 - main - ping: do a better job with what we received from the net, part 2 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: 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/main X-Git-Reftype: branch X-Git-Commit: 0b9434d707c71de7b1b62e400e6e780224f0384d Auto-Submitted: auto-generated Date: Thu, 17 Sep 2026 00:37:14 +0000 Message-Id: <6aab363a.317b0.3dce178e@gitrepo.freebsd.org> The branch main has been updated by maxim: URL: https://cgit.FreeBSD.org/src/commit/?id=0b9434d707c71de7b1b62e400e6e780224f0384d commit 0b9434d707c71de7b1b62e400e6e780224f0384d Author: Maxim Konovalov AuthorDate: 2026-09-16 18:42:00 +0000 Commit: Maxim Konovalov CommitDate: 2026-09-17 00:31:10 +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 --- 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 5926641a4a50..362561f246e8 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1109,7 +1109,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; @@ -1273,9 +1273,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)