diff options
author | trhodes <trhodes@FreeBSD.org> | 2012-09-06 20:15:44 +0000 |
---|---|---|
committer | trhodes <trhodes@FreeBSD.org> | 2012-09-06 20:15:44 +0000 |
commit | b483b4ba3d82feaef71fa09be9ad987686bd4204 (patch) | |
tree | c83fd08bdd5db2103d575027fd15e5d867cd4dcb /lib/libc | |
parent | 88d971cbf76aa5b7791ee8f01781a67000b53876 (diff) | |
download | FreeBSD-src-b483b4ba3d82feaef71fa09be9ad987686bd4204.zip FreeBSD-src-b483b4ba3d82feaef71fa09be9ad987686bd4204.tar.gz |
Avoid segfault if name is invalid. Basically, only
check for CTL_USER if the sysctl fails with ENOENT.
PR: 169056
Reviewed by: jhb
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/sysctl.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c index fbc2c0c..a5a3d49 100644 --- a/lib/libc/gen/sysctl.c +++ b/lib/libc/gen/sysctl.c @@ -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; |