svn commit: r267961 - in head/sys: amd64/acpica amd64/amd64 amd64/pci amd64/vmm arm/arm arm/freescale/imx arm/xscale/ixp425 cam cam/ata cam/ctl cam/scsi cddl/compat/opensolaris/kern cddl/contrib/op...

Mateusz Guzik mjguzik at gmail.com
Fri Jun 27 20:19:14 UTC 2014


On Fri, Jun 27, 2014 at 03:27:30PM -0400, Ed Maste wrote:
> On 27 June 2014 12:33, Hans Petter Selasky <hselasky at freebsd.org> wrote:
> > Author: hselasky
> > Date: Fri Jun 27 16:33:43 2014
> > New Revision: 267961
> > URL: http://svnweb.freebsd.org/changeset/base/267961
> 
> At r267969 sysctl strings are broken for me:
> 
> # uname -a
> uname: sysctl: Cannot allocate memory
> # sysctl kern.ostype
> #
> 

The problem was with (arg2 == 0) check.

I have a hack which restores things for me, but since the check was put
in place just removing it may not be the correct approach.

That said, I would suggest reverting the change for the time being until
it is concluded what is the correct thing to do here.

fwiw, the hack is:
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index cb5a266..9b7f108 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1210,21 +1210,23 @@ sysctl_handle_string(SYSCTL_HANDLER_ARGS)
        size_t outlen;
        int error = 0;
 
-       /* check for zero-length buffer */
-       if (arg2 == 0)
-               return (ENOMEM);
-
        if (req->oldptr != NULL) {
                char *tmparg;
 
-               /* try to make a coherent snapshot of the string */
-               tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
-               memcpy(tmparg, arg1, arg2);
+               if (arg2 != 0) {
+                       /* try to make a coherent snapshot of the string */
+                       tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
+                       memcpy(tmparg, arg1, arg2);
+                       outlen = strnlen(tmparg, arg2 - 1) + 1;
+               } else {
+                       tmparg = arg1;
+                       outlen = strlen((char *)arg1)+1;
+               }
 
-               outlen = strnlen(tmparg, arg2 - 1) + 1;
                error = SYSCTL_OUT(req, tmparg, outlen);
 
-               free(tmparg, M_SYSCTLTMP);
+               if (tmparg != arg1)
+                       free(tmparg, M_SYSCTLTMP);
        } else {
                outlen = strnlen((char *)arg1, arg2 - 1) + 1;
                error = SYSCTL_OUT(req, NULL, outlen);

-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the svn-src-head mailing list