svn commit: r357745 - head/sys/kern

Li-Wen Hsu lwhsu at FreeBSD.org
Mon Feb 10 20:54:00 UTC 2020


Author: lwhsu
Date: Mon Feb 10 20:53:59 2020
New Revision: 357745
URL: https://svnweb.freebsd.org/changeset/base/357745

Log:
  Restore the behavior of allowing empty string in a string sysctl
  
  Added as a special case to avoid unnecessary memory operations.
  
  Reviewed by:	delphij
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==============================================================================
--- head/sys/kern/kern_sysctl.c	Mon Feb 10 20:23:08 2020	(r357744)
+++ head/sys/kern/kern_sysctl.c	Mon Feb 10 20:53:59 2020	(r357745)
@@ -1687,8 +1687,12 @@ sysctl_handle_string(SYSCTL_HANDLER_ARGS)
 		return (error);
 
 	if (req->newlen - req->newidx >= arg2 ||
-	    req->newlen - req->newidx <= 0) {
+	    req->newlen - req->newidx < 0) {
 		error = EINVAL;
+	} else if (req->newlen - req->newidx == 0) {
+		sx_xlock(&sysctlstringlock);
+		((char *)arg1)[0] = '\0';
+		sx_xunlock(&sysctlstringlock);
 	} else {
 		arg2 = req->newlen - req->newidx;
 		tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);


More information about the svn-src-all mailing list