From owner-svn-src-head@freebsd.org Wed Aug 22 01:52:57 2018 Return-Path: Delivered-To: svn-src-head@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 D8EB41086DC1; Wed, 22 Aug 2018 01:52:56 +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 7EA5679C92; Wed, 22 Aug 2018 01:52:56 +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 414404853; Wed, 22 Aug 2018 01:52:56 +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 w7M1qucX017360; Wed, 22 Aug 2018 01:52:56 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7M1qu8u017359; Wed, 22 Aug 2018 01:52:56 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808220152.w7M1qu8u017359@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 22 Aug 2018 01:52:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338173 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 338173 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Aug 2018 01:52:57 -0000 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