mod_firewall: Assume empty list if file could not be loaded
authorMatthew Wild <mwild1@gmail.com>
Sun, 19 Aug 2018 17:53:05 +0100
changeset 3244 c30f2cfe9f15
parent 3243 796c98e8e666
child 3245 4b52cafd5811
mod_firewall: Assume empty list if file could not be loaded
mod_firewall/definitions.lib.lua
--- a/mod_firewall/definitions.lib.lua	Sat Aug 18 18:17:42 2018 +0100
+++ b/mod_firewall/definitions.lib.lua	Sun Aug 19 17:53:05 2018 +0100
@@ -147,18 +147,19 @@
 	-- %LIST: file:/path/to/file
 	file = {
 		init = function (self, file_spec, opts)
+			local items = {};
+			local n = 0;
 			local filename = file_spec:gsub("^file:", "");
 			local file, err = io.open(filename);
 			if not file then
 				module:log("warn", "Failed to open list from %s: %s", filename, err);
 				return;
-			end
-			local items = {};
-			local n = 0;
-			for line in file:lines() do
-				if not items[line] then
-					n = n + 1;
-					items[line] = true;
+			else
+				for line in file:lines() do
+					if not items[line] then
+						n = n + 1;
+						items[line] = true;
+					end
 				end
 			end
 			self.items = items;