Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern That copystr() should be copyinstr(), and fix a cou...



details:   https://anonhg.NetBSD.org/src/rev/2767784393d0
branches:  trunk
changeset: 559819:2767784393d0
user:      atatat <atatat%NetBSD.org@localhost>
date:      Wed Mar 24 15:25:43 2004 +0000

description:
That copystr() should be copyinstr(), and fix a couple of places where
aliasing needs to be avoided.

diffstat:

 sys/kern/kern_sysctl.c |  42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)

diffs (93 lines):

diff -r 6a53147a8362 -r 2767784393d0 sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c    Wed Mar 24 14:47:19 2004 +0000
+++ b/sys/kern/kern_sysctl.c    Wed Mar 24 15:25:43 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sysctl.c,v 1.159 2004/03/08 03:31:26 atatat Exp $ */
+/*     $NetBSD: kern_sysctl.c,v 1.160 2004/03/24 15:25:43 atatat Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.159 2004/03/08 03:31:26 atatat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.160 2004/03/24 15:25:43 atatat Exp $");
 
 #include "opt_defcorename.h"
 #include "opt_insecure.h"
@@ -871,8 +871,8 @@
                                 */
                                e = nnode.sysctl_data;
                                do {
-                                       error = copystr(e, &v[0], sizeof(v),
-                                                       &s);
+                                       error = copyinstr(e, &v[0], sizeof(v),
+                                                         &s);
                                        if (error) {
                                                if (error != ENAMETOOLONG)
                                                        return (error);
@@ -1634,7 +1634,7 @@
         * find it, add the new node.
         */
        sz = sizeof(onode);
-       pnode = (rnode != NULL) ? *rnode : NULL;
+       pnode = rnode ? *rnode : NULL;
        error = sysctl_locate(NULL, &name[0], namelen - 1, &pnode, &ni);
        if (error == 0)
                error = sysctl_create(&name[ni], namelen - ni, &onode, &sz,
@@ -1680,9 +1680,24 @@
                 * sysctl_create() gave us back a copy of the node,
                 * but we need to know where it actually is...
                 */
-               name[namelen - 1] = onode.sysctl_num;
                pnode = *rnode;
-               error = sysctl_locate(NULL, &name[0], namelen, &pnode, &ni);
+               error = sysctl_locate(NULL, &name[0], namelen - 1, &pnode, &ni);
+
+               /*
+                * manual scan of last layer so that aliased nodes
+                * aren't followed.
+                */
+               if (error == 0) {
+                       for (ni = 0; ni < pnode->sysctl_clen; ni++)
+                               if (pnode->sysctl_child[ni].sysctl_num ==
+                                   onode.sysctl_num)
+                                       break;
+                       if (ni < pnode->sysctl_clen)
+                               pnode = &pnode->sysctl_child[ni];
+                       else
+                               error = ENOENT;
+               }
+
                /*
                 * not expecting an error here, but...
                 */
@@ -1738,7 +1753,7 @@
         * where is it?
         */
        node = rnode;
-        error = sysctl_locate(NULL, &name[0], namelen, &node, &ni);
+       error = sysctl_locate(NULL, &name[0], namelen - 1, &node, &ni);
        if (error) {
                /* they want it gone and it's not there, so... */
                sysctl_unlock(NULL);
@@ -1746,13 +1761,12 @@
        }
 
        /*
-        * check to see if we crossed an aliased node
+        * set up the deletion
         */
-       if (node->sysctl_num != name[namelen - 1]) {
-               memset(&dnode, 0, sizeof(dnode));
-               dnode.sysctl_num = name[namelen - 1];
-               node = &dnode;
-       }
+       pnode = node;
+       node = &dnode;
+       memset(&dnode, 0, sizeof(dnode));
+       dnode.sysctl_num = name[namelen - 1];
 
        /*
         * we found it, now let's nuke it



Home | Main Index | Thread Index | Old Index