According to the sysctl(3) man page, calling sysctl with a NULL value for
oldp should result in the current size being returned. This works correctly
for sysctl_rdstring(), but not for sysctl__string().

ok?

Index: kern_sysctl.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.206
diff -u -p -u -p -r1.206 kern_sysctl.c
--- kern_sysctl.c       5 Jul 2011 04:48:02 -0000       1.206
+++ kern_sysctl.c       3 Aug 2011 16:52:39 -0000
@@ -917,15 +917,15 @@ sysctl__string(void *oldp, size_t *oldle
        if (oldp) {
                if (trunc && *oldlenp < len) {
                        /* save & zap NUL terminator while copying */
+                       len = *oldlenp;
                        c = str[*oldlenp-1];
                        str[*oldlenp-1] = '\0';
                        error = copyout(str, oldp, *oldlenp);
                        str[*oldlenp-1] = c;
-               } else {
-                       *oldlenp = len;
+               } else
                        error = copyout(str, oldp, len);
-               }
        }
+       *oldlenp = len;
        if (error == 0 && newp) {
                error = copyin(newp, str, newlen);
                str[newlen] = 0;

-- 

    "Reason is not automatic. Those who deny it cannot be conquered by it.
     Do not count on them. Leave them alone." -- Ayn Rand

Reply via email to