svn commit: r246689 - head/sys/kern

Marius Strobl marius at FreeBSD.org
Mon Feb 11 21:50:00 UTC 2013


Author: marius
Date: Mon Feb 11 21:50:00 2013
New Revision: 246689
URL: http://svnweb.freebsd.org/changeset/base/246689

Log:
  Make SYSCTL_{LONG,QUAD,ULONG,UQUAD}(9) work as advertised and also handle
  constant values.
  
  Reviewed by:	kib
  MFC after:	3 days

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==============================================================================
--- head/sys/kern/kern_sysctl.c	Mon Feb 11 21:10:55 2013	(r246688)
+++ head/sys/kern/kern_sysctl.c	Mon Feb 11 21:50:00 2013	(r246689)
@@ -1051,9 +1051,10 @@ sysctl_handle_long(SYSCTL_HANDLER_ARGS)
 	/*
 	 * 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,12 +1066,15 @@ sysctl_handle_long(SYSCTL_HANDLER_ARGS)
 	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);
 }
@@ -1087,15 +1091,19 @@ sysctl_handle_64(SYSCTL_HANDLER_ARGS)
 	/*
 	 * 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 svn-src-all mailing list