From owner-svn-src-stable@freebsd.org Fri Aug 24 02:21:15 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 20F1F109E64C; Fri, 24 Aug 2018 02:21:15 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C84207233C; Fri, 24 Aug 2018 02:21:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8F3BB2A98; Fri, 24 Aug 2018 02:21:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7O2LE7E023108; Fri, 24 Aug 2018 02:21:14 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7O2LEnq023107; Fri, 24 Aug 2018 02:21:14 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808240221.w7O2LEnq023107@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 24 Aug 2018 02:21:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r338289 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 338289 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 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, 24 Aug 2018 02:21:15 -0000 Author: kevans Date: Fri Aug 24 02:21:14 2018 New Revision: 338289 URL: https://svnweb.freebsd.org/changeset/base/338289 Log: MFC r338020: res_find: Fix fallback logic The fallback logic was broken if hints were found in multiple environments. If we found a hint in either the loader environment or the static environment, fallback would be incremented excessively when we returned to the environment-selection bits. These checks should have also been guarded by the fbacklvl checks. As a result, fbacklvl could quickly get to a point where we skip either the static environment and/or the static hints depending on which environments contained valid hints. The impact of this bug is minimal, mostly affecting mips boards that use static hints and may have hints in either the loader environment or the static environment. There may be better ways to express the searchable environments and describing their characteristics (immutable, already searched, etc.) but this may be revisited after 12 branches. Modified: stable/11/sys/kern/subr_hints.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/subr_hints.c ============================================================================== --- stable/11/sys/kern/subr_hints.c Fri Aug 24 01:59:25 2018 (r338288) +++ stable/11/sys/kern/subr_hints.c Fri Aug 24 02:21:14 2018 (r338289) @@ -172,30 +172,37 @@ fallback: if (dyn_used || fbacklvl >= FBACK_STATIC) return (ENOENT); - if (fbacklvl <= FBACK_MDENV && - _res_checkenv(md_envp)) { - hintp = md_envp; - goto found; - } - fbacklvl++; + switch (fbacklvl) { + case FBACK_MDENV: + fbacklvl++; + if (_res_checkenv(md_envp)) { + hintp = md_envp; + break; + } - if (!stenv_skip && fbacklvl <= FBACK_STENV && - _res_checkenv(kern_envp)) { - hintp = kern_envp; - goto found; - } else - stenv_skip = true; + /* FALLTHROUGH */ + case FBACK_STENV: + fbacklvl++; + if (!stenv_skip && _res_checkenv(kern_envp)) { + hintp = kern_envp; + break; + } else + stenv_skip = true; - fbacklvl++; + /* FALLTHROUGH */ + case FBACK_STATIC: + fbacklvl++; + /* We'll fallback to static_hints if needed/can */ + if (!sthints_skip && + _res_checkenv(static_hints)) + hintp = static_hints; + else + sthints_skip = true; - /* We'll fallback to static_hints if needed/can */ - if (!sthints_skip && fbacklvl <= FBACK_STATIC && - _res_checkenv(static_hints)) - hintp = static_hints; - else - sthints_skip = true; -found: - fbacklvl++; + break; + default: + return (ENOENT); + } } if (hintp == NULL)