From 46acfd0490bee851ef82897fa6a7686f64b2544e Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 Jun 2017 20:46:29 -0400 Subject: Stop init if a module can't be loaded because it doesn't exist --- src/init.cpp | 11 ++++++++++- src/modulemanager.cpp | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 6c69580c6..aed6b8a24 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -543,7 +543,16 @@ void Anope::Init(int ac, char **av) /* load modules */ Anope::Logger.Log("Loading modules..."); for (int i = 0; i < Config->CountBlock("module"); ++i) - ModuleManager::LoadModule(Config->GetBlock("module", i)->Get("name"), NULL); + { + Configuration::Block *config = Config->GetBlock("module", i); + + ModuleReturn modret = ModuleManager::LoadModule(config->Get("name"), NULL); + + if (modret == ModuleReturn::NOEXIST) + { + throw CoreException("Module " + config->Get("name") + " does not exist!"); + } + } Config->LoadOpers(); Config->ApplyBots(); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index a8cfbd547..661519ca4 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -157,6 +157,13 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) } #else Anope::string pbuf = Anope::ModuleDir + "/modules/" + modname.replace_all_cs("/", "_") + ".so"; + + struct stat s; + if (stat(pbuf.c_str(), &s) == -1 || !S_ISREG(s.st_mode)) + { + Anope::Logger.Terminal(_("Error while loading {0} (file does not exist)"), modname); + return ModuleReturn::NOEXIST; + } #endif dlerror(); -- cgit