Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Jun 2014 22:19:07 +0200
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        Ed Maste <emaste@freebsd.org>
Cc:        "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, Hans Petter Selasky <hselasky@freebsd.org>
Subject:   Re: 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...
Message-ID:  <20140627201907.GC22501@dft-labs.eu>
In-Reply-To: <CAPyFy2CyRiNp1Z1zX2-LQEc-KOHqrzc_LDuaaEg2zbFvWAoU1w@mail.gmail.com>
References:  <201406271633.s5RGXih6076565@svn.freebsd.org> <CAPyFy2CyRiNp1Z1zX2-LQEc-KOHqrzc_LDuaaEg2zbFvWAoU1w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jun 27, 2014 at 03:27:30PM -0400, Ed Maste wrote:
> On 27 June 2014 12:33, Hans Petter Selasky <hselasky@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>



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