From owner-freebsd-current Sun Nov 12 22:13:58 1995 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id WAA26142 for current-outgoing; Sun, 12 Nov 1995 22:13:58 -0800 Received: from jhome.DIALix.COM (jhome.DIALix.COM [192.203.228.69]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id WAA25110 for ; Sun, 12 Nov 1995 22:06:36 -0800 Received: (from peter@localhost) by jhome.DIALix.COM (8.6.12/8.6.9) id OAA00313; Mon, 13 Nov 1995 14:05:23 +0800 Date: Mon, 13 Nov 1995 14:05:23 +0800 (WST) From: Peter Wemm To: current@freebsd.org Subject: possible sysctl fix Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-current@freebsd.org Precedence: bulk I think poor Poul-Henning must have broken a few mirrors, walked under ladders and crossed 17 black cat's paths lately to have this much bad luck... The following patch against -current fixes things for me, but I have not run it for long enough to see for sure. If you try it, make sure you can back out if you need to. Beware, I'm tired and quite possibly have screwed it.... There's a lot of changes here, some un-needed. Your mileage may vary. But it just may get you out of a jam until phk wakes up and commits a proper fix. -Peter Index: kern_sysctl.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_sysctl.c,v retrieving revision 1.38 diff -u -r1.38 kern_sysctl.c --- kern_sysctl.c 1995/11/12 19:51:51 1.38 +++ kern_sysctl.c 1995/11/13 05:30:04 @@ -300,18 +300,22 @@ { int error = 0; - if (arg1) - error = SYSCTL_OUT(req, arg1, sizeof(int)); - else if (arg2) - error = SYSCTL_OUT(req, &arg2, sizeof(int)); + if (req->oldlen) { + if (arg1) + error = SYSCTL_OUT(req, arg1, sizeof(int)); + else if (arg2) + error = SYSCTL_OUT(req, &arg2, sizeof(int)); + } - if (error || !req->newptr) + if (error) return (error); - if (!arg1) - error = EPERM; - else - error = SYSCTL_IN(req, arg1, sizeof(int)); + if (req->newptr) { + if (!arg1) + error = EPERM; + else + error = SYSCTL_IN(req, arg1, sizeof(int)); + } return (error); } @@ -327,20 +331,29 @@ { int error=0; - if (arg2) - error = SYSCTL_OUT(req, arg1, arg2); - else - error = SYSCTL_OUT(req, arg1, strlen((char *)arg1)+1); + if (req->oldlen) { +#if 0 +/* this breaks gethostname(buf, 64) (eg: gated) */ + if (arg2) + error = SYSCTL_OUT(req, arg1, arg2); + else +#endif + error = SYSCTL_OUT(req, arg1, strlen((char *)arg1)+1); + } - if (error || !req->newptr) + if (error) return (error); - if ((req->newlen - req->newidx) > arg2) { - error = E2BIG; - } else { - arg2 = (req->newlen - req->newidx); - error = SYSCTL_IN(req, arg1, arg2); - ((char *)arg1)[arg2] = '\0'; + if (req->newptr) { + if (!arg2) { + error = EPERM; + } else if ((req->newlen - req->newidx) > arg2) { + error = E2BIG; + } else { + arg2 = (req->newlen - req->newidx); + error = SYSCTL_IN(req, arg1, arg2); + ((char *)arg1)[arg2] = '\0'; + } } return (error); @@ -354,14 +367,16 @@ int sysctl_handle_opaque SYSCTL_HANDLER_ARGS { - int error; + int error = 0; - error = SYSCTL_OUT(req, arg1, arg2); + if (req->oldlen) + error = SYSCTL_OUT(req, arg1, arg2); - if (error || !req->newptr) + if (error) return (error); - error = SYSCTL_IN(req, arg1, arg2); + if (req->newptr) + error = SYSCTL_IN(req, arg1, arg2); return (error); } @@ -395,8 +410,14 @@ int sysctl_old_user(struct sysctl_req *req, void *p, int l) { - int error , i = min(req->oldlen - req->oldidx, l); + int error, i; + if (!req->oldptr) { + req->oldidx += l; + return 0; + } + + i = min(req->oldlen - req->oldidx, l); error = copyout(p, req->oldptr + req->oldidx, i); req->oldidx += i; if (error) @@ -575,6 +596,8 @@ error = sysctl_root(0, name, namelen, &req); if (!error || error == ENOMEM) { + if (req.oldptr == NULL && oldlenp) + req.oldlen = req.oldidx; if (retval) *retval = req.oldlen; if (oldlenp) {