From owner-svn-src-head@freebsd.org Mon Oct 12 22:07:45 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3EB4D4299A3; Mon, 12 Oct 2020 22:07:45 +0000 (UTC) (envelope-from imp@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C9CTs0l5Sz3Tqw; Mon, 12 Oct 2020 22:07:45 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F0DE512DF6; Mon, 12 Oct 2020 22:07:44 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09CM7iVo092242; Mon, 12 Oct 2020 22:07:44 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09CM7iwQ092241; Mon, 12 Oct 2020 22:07:44 GMT (envelope-from imp@FreeBSD.org) Message-Id: <202010122207.09CM7iwQ092241@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Mon, 12 Oct 2020 22:07:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366656 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 366656 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Oct 2020 22:07:45 -0000 Author: imp Date: Mon Oct 12 22:07:44 2020 New Revision: 366656 URL: https://svnweb.freebsd.org/changeset/base/366656 Log: newbus: use ssize_t to match sb's len and size, fix ordering of space check Both s_len and s_size are ssize_t, so their differece is also more properly a ssize_t not a size_t. Also, assert that len is <= size when we enter. This should always be the case. Ensure that we have that one byte that we write to the end of the buffer before we do so, though the error should already be set on the buffer if not, and the only times we supply 'partial' buffers they should be plenty large. Reviewed by: cem, jhb (prior version, I did cem's suggestion) Differential Revsion: https://reviews.freebsd.org/D26752 Modified: head/sys/kern/subr_bus.c Modified: head/sys/kern/subr_bus.c ============================================================================== --- head/sys/kern/subr_bus.c Mon Oct 12 21:35:29 2020 (r366655) +++ head/sys/kern/subr_bus.c Mon Oct 12 22:07:44 2020 (r366656) @@ -4956,18 +4956,19 @@ static int bus_child_pnpinfo_sb(device_t dev, struct sbuf *sb) { char *p; - size_t space; + ssize_t space; MPASS((sb->s_flags & SBUF_INCLUDENUL) == 0); + MPASS(sb->s_size >= sb->s_len); if (sb->s_error != 0) return (-1); - p = EOB(sb); - *p = '\0'; /* sbuf buffer isn't NUL terminated until sbuf_finish() */ space = SPACE(sb); if (space <= 1) { sb->s_error = ENOMEM; return (-1); } + p = EOB(sb); + *p = '\0'; /* sbuf buffer isn't NUL terminated until sbuf_finish() */ bus_child_pnpinfo_str(dev, p, space); sb->s_len += strlen(p); return (0); @@ -4985,18 +4986,19 @@ static int bus_child_location_sb(device_t dev, struct sbuf *sb) { char *p; - size_t space; + ssize_t space; MPASS((sb->s_flags & SBUF_INCLUDENUL) == 0); + MPASS(sb->s_size >= sb->s_len); if (sb->s_error != 0) return (-1); - p = EOB(sb); - *p = '\0'; /* sbuf buffer isn't NUL terminated until sbuf_finish() */ space = SPACE(sb); if (space <= 1) { sb->s_error = ENOMEM; return (-1); } + p = EOB(sb); + *p = '\0'; /* sbuf buffer isn't NUL terminated until sbuf_finish() */ bus_child_location_str(dev, p, space); sb->s_len += strlen(p); return (0);