Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Feb 2020 20:53:59 +0000 (UTC)
From:      Li-Wen Hsu <lwhsu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r357745 - head/sys/kern
Message-ID:  <202002102053.01AKrxEt094785@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002102053.01AKrxEt094785>