From 81d6c33bf9e44e7131ad3b1ffe5aeedb9571ff88 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 9 Nov 2016 19:03:51 +0100 Subject: [PATCH] e2lib: add extensive error checking to read_extension_config() Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 84696d7..36d3cc0 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1002,8 +1002,31 @@ function e2lib.read_extension_config(root) return false, e:cat(re) end - if not data then - return false, e:append("invalid extension configuration") + if type(data) ~= "table" then + return false, e:cat("invalid extension configuration, missing table") + end + + for _, entry in ipairs(data) do + if type(entry) ~= "table" then + return false, e:cat("extension entry is not a table") + end + + rc, re = e2lib.vrfy_dict_exp_keys(entry, "extension config", + { "ref", "name" }) + + if not rc then + return false, e:cat(re) + end + + for _, field in ipairs({"ref", "name"}) do + if entry[field] == nil then + return false, e:cat("field '%s' is mandatory", field) + end + + if type(entry[field]) ~= "string" then + return false, e:cat("field '%s' takes a string value", field) + end + end end return data -- 2.39.5