From nobody Sun Jul 21 08:51:56 2024 X-Original-To: dev-commits-src-main@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 4WRcbd0mbcz5R4mc; Sun, 21 Jul 2024 08:51:57 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WRcbd0Gb9z4mmw; Sun, 21 Jul 2024 08:51:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721551917; 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=ZoH3NCgFSpli4tGNZuy+rGtt02Po9cavXhtVeWSHpbo=; b=J2ps21Hzq+DjmrLnXeSVICPVAyen11GmtQAhJQRkAhQ4F5/A7oIhoqVierUOZCCOMacHEM EBzaLNvr4MNwnlnjpbQzdnciI7I+5INHfLzOZ5YPqlMJ13uIfe1Z1F93F2bgS4RU973wTM cII7gaQLMb2MK7h8YOi5/gPjrhs5Shg3awuZ5BebeEbxGvisCleUBSYq+c8Rw3igXyjwIq rp2V+apYt5PBZoOGxurBwctDTVyj2tydQoLPclcpR4yREFJcj1UmEGAFaZjcOCWPqVKw4+ CnQjwFlsggxF6cG+Kum4GanMMYVgiNQND3P2MzqxHaSPY/JSePKcRgzNHps3pQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721551917; a=rsa-sha256; cv=none; b=FSj3A9mjEf3UCYsGXi7EXs3VUtDlqWPFu88E7OHyIGdIaEWQQo/mNyRNRInx1wZkSNRgNG 4EBF0N3um3ni8yZ8TegHwQ68Su/AqwjyUX1O0PxNQ/npLcg3aT7+lo/63maglOhriJjah1 kl2qA6klJkerp/GOlHxXOIW9pEZeNIIikRvbaI61yKevZPtOwgU3AL3chy2wY0tr4kzmmd dO20DxHjKmVSAcSwjcPWXwcgvSV6Ooc2/bs5phzd834lAzk+6Qzvl9rzsbdjPa3h7GAWaP MeI2Vzd2kY/iGeW+DY837NQpCsxe9RxUtKNH9VML1RvfMRXw9uB8p8mqZNiHqw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721551917; 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=ZoH3NCgFSpli4tGNZuy+rGtt02Po9cavXhtVeWSHpbo=; b=Ny67kOEcQiCZo9/5Ff0CHn3ljeJv1Bk4Vi5k3fbeFhDUFFKVY9UxXvxLAEVQfuPvieoEND oT7IZ4fvFIsn39n6OpmezCVmuUin4PtYUeaWrwMXwj/ItM2t/49wKM38zRMWgSmRrIxut8 /iJmjUH1ZCWl3QPII8hrTW+OZvJHwPRl+jaooJL/4vW5ZxvJsJEo1WQJWEfQxNdlHGtK2l XYGPjiWQ/8lHpRyiR9qP1auC6si2gViIytF6kbsjKwpuMMijc/nzfsk0RST23pFCC8vFX3 ptat3hPFOKDBFKmLl/qmDhwwJk7arqHDfJ5lPavNVY1zm3vNmCannFx1kTMdfQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WRcbc6srNztGs; Sun, 21 Jul 2024 08:51:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46L8pu9T072662; Sun, 21 Jul 2024 08:51:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46L8pu8L072659; Sun, 21 Jul 2024 08:51:56 GMT (envelope-from git) Date: Sun, 21 Jul 2024 08:51:56 GMT Message-Id: <202407210851.46L8pu8L072659@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 35f498434322 - main - sockstat(1): tolerate situation where file info cannot be fetched List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 35f4984343229545881a324a00cdbb3980d675ce Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=35f4984343229545881a324a00cdbb3980d675ce commit 35f4984343229545881a324a00cdbb3980d675ce Author: Konstantin Belousov AuthorDate: 2024-07-20 00:30:55 +0000 Commit: Konstantin Belousov CommitDate: 2024-07-21 08:51:42 +0000 sockstat(1): tolerate situation where file info cannot be fetched Either due to a race, or to the privilege restrictions, it is not guaranteed that kern.files returned file information for all pcbs read from net.inet..pcblist. In this case the file rbtree does not return the matching file by data address, and code must avoid dereferencing NULL. PR: 279875 Reviewed by: asomers Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46050 --- usr.bin/sockstat/sockstat.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index 73b1f00a4481..5eac327ca184 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -1164,8 +1164,11 @@ displaysock(struct sock *s, int pos) f = RB_FIND(files_t, &ftree, &(struct file){ .xf_data = p->socket }); - pos += xprintf("[%lu %d]", - (u_long)f->xf_pid, f->xf_fd); + if (f != NULL) { + pos += xprintf("[%lu %d]", + (u_long)f->xf_pid, + f->xf_fd); + } } else pos += printaddr(&p->laddr->address); } @@ -1183,9 +1186,12 @@ displaysock(struct sock *s, int pos) f = RB_FIND(files_t, &ftree, &(struct file){ .xf_data = p->socket }); - pos += xprintf("%s[%lu %d]", - fref ? "" : ",", - (u_long)f->xf_pid, f->xf_fd); + if (f != NULL) { + pos += xprintf("%s[%lu %d]", + fref ? "" : ",", + (u_long)f->xf_pid, + f->xf_fd); + } ref = p->faddr->nextref; fref = false; }