1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

sysctl strings include the termingating NUL character in both in and out lengths

Prompted by Nan Xiao noticing the redundancy of bzero+termination - thanks.

ok deraadt@
This commit is contained in:
tom 2017-09-10 11:30:43 +00:00
parent c476faa33c
commit 44bd97b4c7
2 changed files with 7 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: sysctl.3,v 1.281 2017/08/08 18:15:58 florian Exp $
.\" $OpenBSD: sysctl.3,v 1.282 2017/09/10 11:30:43 tom Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: August 8 2017 $
.Dd $Mdocdate: September 10 2017 $
.Dt SYSCTL 3
.Os
.Sh NAME
@ -99,6 +99,8 @@ For these operations,
the system attempts to round up so that the returned size is
large enough for a call to return the data shortly thereafter.
.Pp
The terminating NUL character is included in the lengths of string values.
.Pp
To set a new value,
.Fa newp
is set to point to a buffer of length

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pctr.c,v 1.22 2015/02/08 23:40:34 deraadt Exp $ */
/* $OpenBSD: pctr.c,v 1.23 2017/09/10 11:30:43 tom Exp $ */
/*
* Copyright (c) 2007 Mike Belopuhov, Aleksey Lomovtsev
@ -165,11 +165,9 @@ pctr_cpu_creds(void)
/* Get the architecture */
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
len = sizeof(arch) - 1;
bzero(arch, sizeof(arch));
len = sizeof(arch);
if (sysctl(mib, 2, arch, &len, NULL, 0) == -1)
err(1, "HW_MACHINE");
arch[len] = '\0';
if (strcmp(arch, "i386") == 0)
atype = ARCH_I386;
@ -194,11 +192,9 @@ pctr_cpu_creds(void)
/* Get the processor vendor */
mib[0] = CTL_MACHDEP;
mib[1] = CPU_CPUVENDOR;
len = sizeof(vendor) - 1;
bzero(vendor, sizeof(vendor));
len = sizeof(vendor);
if (sysctl(mib, 2, vendor, &len, NULL, 0) == -1)
err(1, "CPU_CPUVENDOR");
vendor[len] = '\0';
switch (atype) {
case ARCH_I386: