Skip to content

Commit

Permalink
MFC r285188:
Browse files Browse the repository at this point in the history
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.

Approved by: re
  • Loading branch information
pkelsey committed Jul 15, 2015
1 parent 8a1877e commit df98062
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/libc/gen/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit df98062

Please sign in to comment.