Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Aug 2018 01:52: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: r338173 - head/stand/lua
Message-ID:  <201808220152.w7M1qu8u017359@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Aug 22 01:52:55 2018
New Revision: 338173
URL: https://svnweb.freebsd.org/changeset/base/338173

Log:
  lualoader: Fix loader.conf(5) EOL validation for 'exec' lines
  
  This includes some light rework to simplify the line parsing, as well.  If
  we hit a line match, we'll always either use the line and move on to the
  next line, or we'll spew out malformed line errors.
  
  We had multiple spots to output the error and set the status based on
  whether we had a non-nil first capture group or failed EOL validation, but
  it was always the same error.  Light rework entails a small label jump to
  skip error handling and elimination of 'found' local.

Modified:
  head/stand/lua/config.lua

Modified: head/stand/lua/config.lua
==============================================================================
--- head/stand/lua/config.lua	Wed Aug 22 01:50:12 2018	(r338172)
+++ head/stand/lua/config.lua	Wed Aug 22 01:52:55 2018	(r338173)
@@ -128,10 +128,20 @@ end
 -- pattern should have no more than two captures patterns, which correspond to
 -- the two parameters (usually 'key' and 'value') that are passed to the
 -- process function.  All trailing characters will be validated.
+--
+-- We have two special entries in this table: the first is the first entry,
+-- a full-line comment.  The second is for 'exec' handling.  Both have a single
+-- capture group, but the difference is that the full-line comment pattern will
+-- match the entire line.  This does not run afoul of the later end of line
+-- validation that we'll do after a match.  However, the 'exec' pattern will.
+-- We document the exceptions with a special 'groups' index that indicates
+-- the number of capture groups, if not two.  We'll use this later to do
+-- validation on the proper entry.
 local pattern_table = {
 	{
 		str = "(#.*)",
 		process = function(_, _)  end,
+		groups = 1,
 	},
 	--  module_load="value"
 	{
@@ -193,6 +203,7 @@ local pattern_table = {
 				print(MSG_FAILEXEC:format(k))
 			end
 		end,
+		groups = 1,
 	},
 	--  env_var="value"
 	{
@@ -394,31 +405,30 @@ function config.parse(text)
 
 	for line in text:gmatch("([^\n]+)") do
 		if line:match("^%s*$") == nil then
-			local found = false
-
 			for _, val in ipairs(pattern_table) do
 				local pattern = '^%s*' .. val.str .. '%s*(.*)';
+				local cgroups = val.groups or 2
 				local k, v, c = line:match(pattern)
 				if k ~= nil then
-					found = true
+					-- Offset by one, drats
+					if cgroups == 1 then
+						c = v
+						v = nil
+					end
 
 					if isValidComment(c) then
 						val.process(k, v)
-					else
-						print(MSG_MALFORMED:format(n,
-						    line))
-						status = false
+						goto nextline
 					end
 
 					break
 				end
 			end
 
-			if not found then
-				print(MSG_MALFORMED:format(n, line))
-				status = false
-			end
+			print(MSG_MALFORMED:format(n, line))
+			status = false
 		end
+		::nextline::
 		n = n + 1
 	end
 



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