From b7abfe5eca076c29a0d49a411320612264093bdf Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 4 May 2023 17:56:37 +0100 Subject: Avoid returning null when a config tag does not exist. This invokes undefined behaviour on modern compilers. --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 025b34c4e..22f8385ee 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -427,8 +427,8 @@ void Anope::Init(int ac, char **av) if (!getuid() && !getgid()) { /* If we are configured to setuid later, don't issue a warning */ - Configuration::Block *options = Config->GetBlock("options"); - if (options->Get("user").empty()) + Configuration::Block *options = Config ? Config->GetBlock("options") : NULL; + if (!options || options->Get("user").empty()) { std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl; std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl; -- cgit From 0646547c9eecc464dfc3c6fb0c7dfa9a3298a268 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 28 May 2023 20:40:00 -0400 Subject: config: remove dependency on no-delete-null-pointer-checks --- src/init.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 22f8385ee..082f39b96 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -422,20 +422,6 @@ void Anope::Init(int ac, char **av) #ifdef _WIN32 if (!SupportedWindowsVersion()) throw CoreException(GetWindowsVersion() + " is not a supported version of Windows"); -#else - /* If we're root, issue a warning now */ - if (!getuid() && !getgid()) - { - /* If we are configured to setuid later, don't issue a warning */ - Configuration::Block *options = Config ? Config->GetBlock("options") : NULL; - if (!options || options->Get("user").empty()) - { - std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl; - std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl; - std::cerr << " as the root superuser." << std::endl; - sleep(3); - } - } #endif #ifdef _WIN32 @@ -527,6 +513,20 @@ void Anope::Init(int ac, char **av) ModuleManager::LoadModule(Config->GetBlock("module", i)->Get("name"), NULL); #ifndef _WIN32 + /* If we're root, issue a warning now */ + if (!getuid() && !getgid()) + { + /* If we are configured to setuid later, don't issue a warning */ + Configuration::Block *options = Config->GetBlock("options"); + if (options->Get("user").empty()) + { + std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl; + std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl; + std::cerr << " as the root superuser." << std::endl; + sleep(3); + } + } + /* We won't background later, so we should setuid now */ if (Anope::NoFork) setuidgid(); -- cgit