From: Otto Date: Fri, 15 Oct 2021 06:33:17 +0000 (+0200) Subject: Only set recursion protection once we know we do not return because of an error. X-Git-Tag: dnsdist-1.7.0-alpha2~6^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10848%2Fhead;p=thirdparty%2Fpdns.git Only set recursion protection once we know we do not return because of an error. Also catch exception thrown by executeCode. --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 08f179a64a..1084b5bdcd 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1847,7 +1847,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) return; } - g_included = true; struct stat st; if (stat(dirname.c_str(), &st)) { errlog("The included directory %s does not exist!", dirname.c_str()); @@ -1890,6 +1889,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) closedir(dirp); files.sort(); + g_included = true; + for (auto file = files.begin(); file != files.end(); ++file) { std::ifstream ifs(*file); if (!ifs) { @@ -1898,7 +1899,13 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) vinfolog("Read configuration from '%s'", *file); } - luaCtx.executeCode(ifs); + try { + luaCtx.executeCode(ifs); + } + catch (...) { + g_included = false; + throw; + } } g_included = false;