From owner-svn-src-stable@FreeBSD.ORG Fri May 18 19:08:11 2012 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 15BE11065670; Fri, 18 May 2012 19:08:11 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DBC9B8FC08; Fri, 18 May 2012 19:08:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q4IJ8AqN071397; Fri, 18 May 2012 19:08:10 GMT (envelope-from jamie@svn.freebsd.org) Received: (from jamie@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4IJ8ABl071395; Fri, 18 May 2012 19:08:10 GMT (envelope-from jamie@svn.freebsd.org) Message-Id: <201205181908.q4IJ8ABl071395@svn.freebsd.org> From: Jamie Gritton Date: Fri, 18 May 2012 19:08:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r235624 - stable/9/lib/libjail X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 May 2012 19:08:11 -0000 Author: jamie Date: Fri May 18 19:08:10 2012 New Revision: 235624 URL: http://svn.freebsd.org/changeset/base/235624 Log: MFC r235291: The linker isn't consistent in the ordering of dynamic sysctls, so don't assume that the unnamed final component of "security.jail.param.foo." is one less than the "foo" component. It might be one greater instead. Modified: stable/9/lib/libjail/jail.c Directory Properties: stable/9/lib/libjail/ (props changed) Modified: stable/9/lib/libjail/jail.c ============================================================================== --- stable/9/lib/libjail/jail.c Fri May 18 19:02:39 2012 (r235623) +++ stable/9/lib/libjail/jail.c Fri May 18 19:08:10 2012 (r235624) @@ -855,7 +855,7 @@ jailparam_type(struct jailparam *jp) { char *p, *nname; size_t miblen, desclen; - int isarray; + int i, isarray; struct { int i; char s[MAXPATHLEN]; @@ -977,21 +977,33 @@ jailparam_type(struct jailparam *jp) } break; case CTLTYPE_NODE: - /* A node might be described by an empty-named child. */ + /* + * A node might be described by an empty-named child, + * which would be immediately before or after the node itself. + */ mib[1] = 1; - mib[(miblen / sizeof(int)) + 2] = - mib[(miblen / sizeof(int)) + 1] - 1; miblen += sizeof(int); - desclen = sizeof(desc.s); - if (sysctl(mib, (miblen / sizeof(int)) + 2, desc.s, &desclen, - NULL, 0) < 0) { - snprintf(jail_errmsg, JAIL_ERRMSGLEN, - "sysctl(0.1): %s", strerror(errno)); - return (-1); + for (i = -1; i <= 1; i += 2) { + mib[(miblen / sizeof(int)) + 1] = + mib[(miblen / sizeof(int))] + i; + desclen = sizeof(desc.s); + if (sysctl(mib, (miblen / sizeof(int)) + 2, desc.s, + &desclen, NULL, 0) < 0) { + if (errno == ENOENT) + continue; + snprintf(jail_errmsg, JAIL_ERRMSGLEN, + "sysctl(0.1): %s", strerror(errno)); + return (-1); + } + if (desclen == + sizeof(SJPARAM) + strlen(jp->jp_name) + 2 && + memcmp(SJPARAM ".", desc.s, sizeof(SJPARAM)) == 0 && + memcmp(jp->jp_name, desc.s + sizeof(SJPARAM), + desclen - sizeof(SJPARAM) - 2) == 0 && + desc.s[desclen - 2] == '.') + goto mib_desc; } - if (desc.s[desclen - 2] != '.') - goto unknown_parameter; - goto mib_desc; + goto unknown_parameter; default: snprintf(jail_errmsg, JAIL_ERRMSGLEN, "unknown type for %s", jp->jp_name);