svn commit: r366656 - head/sys/kern
Warner Losh
imp at FreeBSD.org
Mon Oct 12 22:07:45 UTC 2020
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);
More information about the svn-src-head
mailing list