From 9b6ea8251c5c6da99b44b32f87c3cfe14de3ae26 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 9 Apr 2012 21:42:04 +0200 Subject: [PATCH] WebModules: Fix a NULL pointer dereference Commit b1593238d5443bcd4f1b93 started using the module pointer before the NULL check. This caused crashes whenever someone (even without a login!) accessed a web page on znc for a module which didn't exist. Thanks to J0rd4n` for reporting this to us. Signed-off-by: Uli Schlachter --- src/WebModules.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/WebModules.cpp b/src/WebModules.cpp index 6092078c..de602c47 100644 --- a/src/WebModules.cpp +++ b/src/WebModules.cpp @@ -686,12 +686,13 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS break; } + if (!pModule) + return PAGE_NOTFOUND; + m_Template["ModPath"] = pModule->GetWebPath(); m_Template["ModFilesPath"] = pModule->GetWebFilesPath(); - if (!pModule) { - return PAGE_NOTFOUND; - } else if (pModule->WebRequiresLogin() && !ForceLogin()) { + if (pModule->WebRequiresLogin() && !ForceLogin()) { return PAGE_PRINT; } else if (pModule->WebRequiresAdmin() && !GetSession()->IsAdmin()) { PrintErrorPage(403, "Forbidden", "You need to be an admin to access this module");