[Midnightbsd-cvs] src [8887] trunk/sys/kern/kern_sysctl.c: use right data types

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Sep 26 18:26:35 EDT 2016


Revision: 8887
          http://svnweb.midnightbsd.org/src/?rev=8887
Author:   laffer1
Date:     2016-09-26 18:26:35 -0400 (Mon, 26 Sep 2016)
Log Message:
-----------
use right data types

Modified Paths:
--------------
    trunk/sys/kern/kern_sysctl.c

Modified: trunk/sys/kern/kern_sysctl.c
===================================================================
--- trunk/sys/kern/kern_sysctl.c	2016-09-26 22:26:13 UTC (rev 8886)
+++ trunk/sys/kern/kern_sysctl.c	2016-09-26 22:26:35 UTC (rev 8887)
@@ -1036,7 +1036,10 @@
 
 
 /*
- * Handle a long, signed or unsigned.  arg1 points to it.
+ * Handle a long, signed or unsigned.
+ * Two cases:
+ *     a variable:  point arg1 at it.
+ *     a constant:  pass it in arg2.
  */
 
 int
@@ -1051,9 +1054,10 @@
 	/*
 	 * Attempt to get a coherent snapshot by making a copy of the data.
 	 */
-	if (!arg1)
-		return (EINVAL);
-	tmplong = *(long *)arg1;
+	if (arg1)
+		tmplong = *(long *)arg1;
+	else
+		tmplong = arg2;
 #ifdef SCTL_MASK32
 	if (req->flags & SCTL_MASK32) {
 		tmpint = tmplong;
@@ -1065,18 +1069,24 @@
 	if (error || !req->newptr)
 		return (error);
 
+	if (!arg1)
+		error = EPERM;
 #ifdef SCTL_MASK32
-	if (req->flags & SCTL_MASK32) {
+	else if (req->flags & SCTL_MASK32) {
 		error = SYSCTL_IN(req, &tmpint, sizeof(int));
 		*(long *)arg1 = (long)tmpint;
-	} else
+	}
 #endif
+	else
 		error = SYSCTL_IN(req, arg1, sizeof(long));
 	return (error);
 }
 
 /*
- * Handle a 64 bit int, signed or unsigned.  arg1 points to it.
+ * Handle a 64 bit int, signed or unsigned.
+ * Two cases:
+ *     a variable:  point arg1 at it.
+ *     a constant:  pass it in arg2.
  */
 int
 sysctl_handle_64(SYSCTL_HANDLER_ARGS)
@@ -1087,15 +1097,19 @@
 	/*
 	 * Attempt to get a coherent snapshot by making a copy of the data.
 	 */
-	if (!arg1)
-		return (EINVAL);
-	tmpout = *(uint64_t *)arg1;
+	if (arg1)
+		tmpout = *(uint64_t *)arg1;
+	else
+		tmpout = arg2;
 	error = SYSCTL_OUT(req, &tmpout, sizeof(uint64_t));
 
 	if (error || !req->newptr)
 		return (error);
 
-	error = SYSCTL_IN(req, arg1, sizeof(uint64_t));
+	if (!arg1)
+		error = EPERM;
+	else
+		error = SYSCTL_IN(req, arg1, sizeof(uint64_t));
 	return (error);
 }
 



More information about the Midnightbsd-cvs mailing list