Validate section names from site.conf in various packages

This commit is contained in:
Matthias Schiffer 2015-10-11 19:31:44 +02:00
parent fddbc1df2e
commit 05f146f817
4 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,8 @@
need_string 'autoupdater.branch' need_string 'autoupdater.branch'
local function check_branch(k, _) local function check_branch(k, _)
assert_uci_name(k)
local prefix = string.format('autoupdater.branches[%q].', k) local prefix = string.format('autoupdater.branches[%q].', k)
need_string(prefix .. 'name') need_string(prefix .. 'name')

View File

@ -6,6 +6,8 @@ need_boolean('fastd_mesh_vpn.configurable', false)
local function check_peer(prefix) local function check_peer(prefix)
return function(k, _) return function(k, _)
assert_uci_name(k)
local table = string.format('%s[%q].', prefix, k) local table = string.format('%s[%q].', prefix, k)
need_string(table .. 'key') need_string(table .. 'key')
@ -15,6 +17,8 @@ end
local function check_group(prefix) local function check_group(prefix)
return function(k, _) return function(k, _)
assert_uci_name(k)
local table = string.format('%s[%q].', prefix, k) local table = string.format('%s[%q].', prefix, k)
need_number(table .. 'limit', false) need_number(table .. 'limit', false)

View File

@ -1,4 +1,6 @@
local function check_entry(k, _) local function check_entry(k, _)
assert_uci_name(k)
local prefix = string.format('simple_tc[%q].', k) local prefix = string.format('simple_tc[%q].', k)
need_string(prefix .. 'ifname') need_string(prefix .. 'ifname')

View File

@ -12,6 +12,12 @@ local function assert_type(var, t, msg)
end end
function assert_uci_name(var)
-- We don't use character classes like %w here to be independent of the locale
assert(var:match('^[0-9a-zA-Z_]+$'), "site.conf error: `" .. var .. "' is not a valid config section name (only alphanumeric characters and the underscore are allowed)")
end
function need_string(varname, required) function need_string(varname, required)
local var = loadvar(varname) local var = loadvar(varname)