Module Name: src Committed By: dsl Date: Sat Mar 1 17:27:48 UTC 2014
Modified Files: src/sys/kern: kern_sysctl.c Log Message: When converting out of range 64bit sysctl values to 'int' (because of an 'int' sized read) don't assume that sizeof (int) is 4. To generate a diff of this commit: cvs rdiff -u -r1.247 -r1.248 src/sys/kern/kern_sysctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_sysctl.c diff -u src/sys/kern/kern_sysctl.c:1.247 src/sys/kern/kern_sysctl.c:1.248 --- src/sys/kern/kern_sysctl.c:1.247 Thu Feb 27 22:50:52 2014 +++ src/sys/kern/kern_sysctl.c Sat Mar 1 17:27:48 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sysctl.c,v 1.247 2014/02/27 22:50:52 dsl Exp $ */ +/* $NetBSD: kern_sysctl.c,v 1.248 2014/03/01 17:27:48 dsl Exp $ */ /*- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.247 2014/02/27 22:50:52 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.248 2014/03/01 17:27:48 dsl Exp $"); #include "opt_defcorename.h" #include "ksyms.h" @@ -1513,7 +1513,7 @@ sysctl_lookup(SYSCTLFN_ARGS) switch (SYSCTL_TYPE(rnode->sysctl_flags)) { case CTLTYPE_INT: /* Allow for 64bit read of 32bit value */ - if (*oldlenp == sizeof (uint64_t)) { + if (*oldlenp != sz && *oldlenp == sizeof (uint64_t)) { qval = *(int *)d; d_out = &qval; sz = sizeof (uint64_t); @@ -1521,9 +1521,12 @@ sysctl_lookup(SYSCTLFN_ARGS) break; case CTLTYPE_QUAD: /* Allow for 32bit read of 64bit value */ - if (*oldlenp == sizeof (int)) { + if (*oldlenp != sz && *oldlenp == sizeof (int)) { qval = *(uint64_t *)d; - ival = qval < 0x100000000 ? qval : 0xffffffff; + ival = qval; + /* Replace out of range values with -1 */ + if (ival != qval) + ival = -1; d_out = &ival; sz = sizeof (int); }