aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-05-07 16:47:58 +0200
committerKim Alvefur <zash@zash.se>2021-05-07 16:47:58 +0200
commit37ad3b8fb2039684273b3cb63b5b573e879b04d7 (patch)
tree89b3b73f9c0d429a9e34242722b54711354f9b73 /core
parent2c902f163f0f31ac9ea7d803cf2a493cecbaf3fe (diff)
downloadprosody-37ad3b8fb2039684273b3cb63b5b573e879b04d7.tar.gz
prosody-37ad3b8fb2039684273b3cb63b5b573e879b04d7.zip
core.certmanager: Catch error from lfs
lfs.dir() throws a hard error if there's a problem, e.g. no such directory or permission issues. This also gets called early enough that the main loop error protection hasn't been brought up yet, causing a proper crash.
Diffstat (limited to 'core')
-rw-r--r--core/certmanager.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/certmanager.lua b/core/certmanager.lua
index a7432d35..69c8e32c 100644
--- a/core/certmanager.lua
+++ b/core/certmanager.lua
@@ -35,6 +35,7 @@ local io_open = io.open;
local select = select;
local now = os.time;
local next = next;
+local pcall = pcall;
local prosody = prosody;
local pathutil = require"util.paths";
@@ -112,7 +113,16 @@ local function index_certs(dir, files_by_name, depth_limit)
depth_limit = depth_limit or 3;
if depth_limit <= 0 then return files_by_name; end
- for file in lfs.dir(dir) do
+ local ok, iter, v, i = pcall(lfs.dir, dir);
+ if not ok then
+ log("error", "Error indexing certificate directory %s: %s", dir, iter);
+ -- Return an empty index, otherwise this just triggers a nil indexing
+ -- error, plus this function would get called again.
+ -- Reloading the config after correcting the problem calls this again so
+ -- that's what should be done.
+ return {}, iter;
+ end
+ for file in iter, v, i do
local full = pathutil.join(dir, file);
if lfs.attributes(full, "mode") == "directory" then
if file:sub(1,1) ~= "." then