Source-Changes-HG archive

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

[src/trunk]: src/sys/kern old_sysctl: fix null dereference when oldlenp == NULL.



details:   https://anonhg.NetBSD.org/src/rev/3ae69c966879
branches:  trunk
changeset: 583751:3ae69c966879
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sun Aug 21 13:14:54 2005 +0000

description:
old_sysctl: fix null dereference when oldlenp == NULL.

diffstat:

 sys/kern/kern_sysctl.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (49 lines):

diff -r e234df85fdb4 -r 3ae69c966879 sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c    Sun Aug 21 13:13:50 2005 +0000
+++ b/sys/kern/kern_sysctl.c    Sun Aug 21 13:14:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sysctl.c,v 1.185 2005/08/07 04:54:07 yamt Exp $   */
+/*     $NetBSD: kern_sysctl.c,v 1.186 2005/08/21 13:14:54 yamt 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.185 2005/08/07 04:54:07 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.186 2005/08/21 13:14:54 yamt Exp $");
 
 #include "opt_defcorename.h"
 #include "opt_insecure.h"
@@ -2545,17 +2545,27 @@
           void *newp, size_t newlen, struct lwp *l)
 {
        int error;
-       size_t savelen = *oldlenp;
+       size_t oldlen = 0;
+       size_t savelen;
+
+       if (oldlenp) {
+               oldlen = *oldlenp;
+       }
+       savelen = oldlen;
 
        error = sysctl_lock(l, oldp, savelen);
        if (error)
                return (error);
-       error = sysctl_dispatch(name, namelen, oldp, oldlenp,
+       error = sysctl_dispatch(name, namelen, oldp, &oldlen,
                                newp, newlen, name, l, NULL);
        sysctl_unlock(l);
-       if (error == 0 && oldp != NULL && savelen < *oldlenp)
+       if (error == 0 && oldp != NULL && savelen < oldlen)
                error = ENOMEM;
 
+       if (oldlenp) {
+               *oldlenp = oldlen;
+       }
+
        return (error);
 }
 



Home | Main Index | Thread Index | Old Index