git: b39f500e6ac8 - main - stand: lines with comments a '"' in loader.conf are ignored

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sun, 16 Mar 2025 14:50:47 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=b39f500e6ac8404aa0acdc025bd12829e881fcd1

commit b39f500e6ac8404aa0acdc025bd12829e881fcd1
Author:     Cyrus Rahman <crahman@gmail.com>
AuthorDate: 2025-03-16 14:44:57 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-03-16 14:46:57 +0000

    stand: lines with comments a '"' in loader.conf are ignored
    
    So the problem is that the lua parser in /boot/lua/config.lua is
    splitting the line on the '=', sending the first match to the key and
    the second to the value.
    
    In the problem case, the value is:
       '"test b"               # This is "test_directive_b"'
    Then the value gets matched against QVALEXPR = '"(.*)"'.
    
    This cleans up the value by removing the first and last '"', but in this
    case turns it into:
      test b"               # This is "test_directive_b
    which then gets rejected in processEnvVar() with MSG_FAILSYN_QUOTE,
    since values aren't allowed to contain '"'.
    
    Changing QVALEXPR to '([-%w_]+)' fixes this problem.  Since the value is
    explicitly prevented from containing quotes, it's not unreasonable to
    load it from an expression that excludes them.  The only other place
    this is used is in the 'exec="command"' expression, which also should
    not contain '"' in the command value.
    
    PR: 265001
    Reviewed by: imp
    Differential Revision: https://reviews.freebsd.org/D35975
---
 stand/lua/config.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stand/lua/config.lua b/stand/lua/config.lua
index 86f5ef6174a2..26f65ecc17b6 100644
--- a/stand/lua/config.lua
+++ b/stand/lua/config.lua
@@ -65,7 +65,7 @@ local MSG_FAILSYN_BADVAR = "Malformed variable expression at position '%d'"
 -- env_var entries in the pattern table.  This is perhaps a good target for a
 -- little refactoring.
 local MODULEEXPR = '([%w%d-_.]+)'
-local QVALEXPR = '"(.*)"'
+local QVALEXPR = '"([^"]*)"'
 local QVALREPL = QVALEXPR:gsub('%%', '%%%%')
 local WORDEXPR = "([-%w%d][-%w%d_.]*)"
 local WORDREPL = WORDEXPR:gsub('%%', '%%%%')