diff options
author | pkelsey <pkelsey@FreeBSD.org> | 2015-07-06 01:42:12 +0000 |
---|---|---|
committer | pkelsey <pkelsey@FreeBSD.org> | 2015-07-06 01:42:12 +0000 |
commit | 2671c7e7e688b9b5c2a0afba3ad1f18cac1a220e (patch) | |
tree | 807544ee81a1a775ba82de8370b5bf819d62d46e /lib | |
parent | 2cab64f3fc8c57504e807b86869f5428a7de7fa4 (diff) | |
download | FreeBSD-src-2671c7e7e688b9b5c2a0afba3ad1f18cac1a220e.zip FreeBSD-src-2671c7e7e688b9b5c2a0afba3ad1f18cac1a220e.tar.gz |
Fix sysctl(3) so it returns the intended values for all mib names in
the 'user' sysctl tree, which have all been coming back 0 or empty
since r240176.
Differential Revision: https://reviews.freebsd.org/D2945
Reviewed by: sbruno
Approved by: jmallett (mentor)
MFC after: 3 days
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/sysctl.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c index a5a3d49..b83b439 100644 --- a/lib/libc/gen/sysctl.c +++ b/lib/libc/gen/sysctl.c @@ -51,9 +51,21 @@ sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen) { int retval; + size_t orig_oldlen; + orig_oldlen = oldlenp ? *oldlenp : 0; retval = __sysctl(name, namelen, oldp, oldlenp, newp, newlen); - if (retval != -1 || errno != ENOENT || name[0] != CTL_USER) + /* + * All valid names under CTL_USER have a dummy entry in the sysctl + * tree (to support name lookups and enumerations) with an + * empty/zero value, and the true value is supplied by this routine. + * For all such names, __sysctl() is used solely to validate the + * name. + * + * Return here unless there was a successful lookup for a CTL_USER + * name. + */ + if (retval || name[0] != CTL_USER) return (retval); if (newp != NULL) { @@ -67,7 +79,7 @@ sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, switch (name[1]) { case USER_CS_PATH: - if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) { + if (oldp && orig_oldlen < sizeof(_PATH_STDPATH)) { errno = ENOMEM; return -1; } |