Avoid segfault if name is invalid. Basically, only

check for CTL_USER if the sysctl fails with ENOENT.

PR:		169056
Reviewed by:	jhb
This commit is contained in:
Tom Rhodes 2012-09-06 20:15:44 +00:00
parent 0dbe75e145
commit 4d8ed60cb4

View File

@ -50,8 +50,11 @@ int
sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
const void *newp, size_t newlen)
{
if (name[0] != CTL_USER)
return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
int retval;
retval = __sysctl(name, namelen, oldp, oldlenp, newp, newlen);
if (retval != -1 || errno != ENOENT || name[0] != CTL_USER)
return (retval);
if (newp != NULL) {
errno = EPERM;