Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Sep 2012 20:15:44 +0000 (UTC)
From:      Tom Rhodes <trhodes@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r240176 - head/lib/libc/gen
Message-ID:  <201209062015.q86KFiHV078384@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trhodes
Date: Thu Sep  6 20:15:44 2012
New Revision: 240176
URL: http://svn.freebsd.org/changeset/base/240176

Log:
  Avoid segfault if name is invalid.  Basically, only
  check for CTL_USER if the sysctl fails with ENOENT.
  
  PR:		169056
  Reviewed by:	jhb

Modified:
  head/lib/libc/gen/sysctl.c

Modified: head/lib/libc/gen/sysctl.c
==============================================================================
--- head/lib/libc/gen/sysctl.c	Thu Sep  6 19:26:59 2012	(r240175)
+++ head/lib/libc/gen/sysctl.c	Thu Sep  6 20:15:44 2012	(r240176)
@@ -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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209062015.q86KFiHV078384>