Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Aug 2018 19:45:56 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338020 - head/sys/kern
Message-ID:  <201808181945.w7IJjuos075817@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sat Aug 18 19:45:56 2018
New Revision: 338020
URL: https://svnweb.freebsd.org/changeset/base/338020

Log:
  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.
  
  Reported by:	Dan Nelson <dnelson_1901@yahoo.com>
  Triaged by:	Dan Nelson <dnelson_1901@yahoo.com>
  MFC after:	3 days

Modified:
  head/sys/kern/subr_hints.c

Modified: head/sys/kern/subr_hints.c
==============================================================================
--- head/sys/kern/subr_hints.c	Sat Aug 18 19:14:06 2018	(r338019)
+++ head/sys/kern/subr_hints.c	Sat Aug 18 19:45:56 2018	(r338020)
@@ -174,30 +174,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)



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