]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib: add extensive error checking to read_extension_config()
authorTobias Ulmer <tu@emlix.com>
Wed, 9 Nov 2016 18:03:51 +0000 (19:03 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:18 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index 84696d76941eec054577ac27926163cfb5e731aa..36d3cc02b5ece293558fc247692fe12f4598ed8f 100644 (file)
@@ -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