[Midnightbsd-cvs] src [10504] trunk/lib/libutil/kinfo_getvmmap.c: nitems

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jun 6 21:46:39 EDT 2018


Revision: 10504
          http://svnweb.midnightbsd.org/src/?rev=10504
Author:   laffer1
Date:     2018-06-06 21:46:38 -0400 (Wed, 06 Jun 2018)
Log Message:
-----------
nitems

Modified Paths:
--------------
    trunk/lib/libutil/kinfo_getvmmap.c

Modified: trunk/lib/libutil/kinfo_getvmmap.c
===================================================================
--- trunk/lib/libutil/kinfo_getvmmap.c	2018-06-07 01:46:18 UTC (rev 10503)
+++ trunk/lib/libutil/kinfo_getvmmap.c	2018-06-07 01:46:38 UTC (rev 10504)
@@ -2,8 +2,8 @@
 __MBSDID("$MidnightBSD$");
 
 #include <sys/param.h>
+#include <sys/sysctl.h>
 #include <sys/user.h>
-#include <sys/sysctl.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -26,7 +26,7 @@
 	mib[2] = KERN_PROC_VMMAP;
 	mib[3] = pid;
 
-	error = sysctl(mib, 4, NULL, &len, NULL, 0);
+	error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
 	if (error)
 		return (NULL);
 	len = len * 4 / 3;
@@ -33,7 +33,7 @@
 	buf = malloc(len);
 	if (buf == NULL)
 		return (NULL);
-	error = sysctl(mib, 4, buf, &len, NULL, 0);
+	error = sysctl(mib, nitems(mib), buf, &len, NULL, 0);
 	if (error) {
 		free(buf);
 		return (NULL);
@@ -44,6 +44,8 @@
 	eb = buf + len;
 	while (bp < eb) {
 		kv = (struct kinfo_vmentry *)(uintptr_t)bp;
+		if (kv->kve_structsize == 0)
+			break;
 		bp += kv->kve_structsize;
 		cnt++;
 	}
@@ -59,6 +61,8 @@
 	/* Pass 2: unpack */
 	while (bp < eb) {
 		kv = (struct kinfo_vmentry *)(uintptr_t)bp;
+		if (kv->kve_structsize == 0)
+			break;
 		/* Copy/expand into pre-zeroed buffer */
 		memcpy(kp, kv, kv->kve_structsize);
 		/* Advance to next packed record */



More information about the Midnightbsd-cvs mailing list