summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-07-21 03:59:59 -0400
committerAdam <Adam@anope.org>2013-07-21 03:59:59 -0400
commit604da898136b9299f555336df633e30a09f44ddd (patch)
treeab4a3e380d16a6f9b6e2f320feaaeb095ff2c872
parente11abdc4f00b19feae7830d4de6098e282e7eb39 (diff)
More basic config validation, and fix crash when no uplinks are configured. spotted by fgs
-rw-r--r--data/example.conf4
-rw-r--r--src/config.cpp15
-rw-r--r--src/uplink.cpp6
3 files changed, 21 insertions, 4 deletions
diff --git a/data/example.conf b/data/example.conf
index 41a1a0163..b6e0231ce 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -238,13 +238,13 @@ serverinfo
/*
* The filename containing the Services process ID. The path is relative to the
- * services root directory. If not given, defaults to "data/services.pid".
+ * services root directory.
*/
pid = "data/services.pid"
/*
* The filename containing the Message of the Day. The path is relative to the
- * services root directory. If not given, defaults to "conf/services.motd".
+ * services root directory.
*/
motd = "conf/services.motd"
}
diff --git a/src/config.cpp b/src/config.cpp
index 8ba56bda2..1000e6cf4 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -106,6 +106,12 @@ static void ValidateNotEmpty(const Anope::string &block, const Anope::string &na
throw ConfigException("The value for <" + block + ":" + name + "> cannot be empty!");
}
+static void ValidateNoSpaces(const Anope::string &block, const Anope::string &name, const Anope::string &value)
+{
+ if (value.find(' ') != Anope::string::npos)
+ throw ConfigException("The value for <" + block + ":" + name + "> may not contain spaces!");
+}
+
template<typename T> static void ValidateNotZero(const Anope::string &block, const Anope::string &name, T value)
{
if (!value)
@@ -158,14 +164,18 @@ Conf::Conf() : Block("")
throw ConfigException("<" + noreload[i].block + ":" + noreload[i].name + "> can not be modified once set");
}
- Block *options = this->GetBlock("options"), *mail = this->GetBlock("mail");
+ Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"), *mail = this->GetBlock("mail");
+
+ ValidateNotEmpty("serverinfo", "name", serverinfo->Get<const Anope::string>("name"));
+ ValidateNotEmpty("serverinfo", "description", serverinfo->Get<const Anope::string>("description"));
+ ValidateNotEmpty("serverinfo", "pid", serverinfo->Get<const Anope::string>("pid"));
+ ValidateNotEmpty("serverinfo", "motd", serverinfo->Get<const Anope::string>("motd"));
ValidateNotZero("options", "releasetimeout", options->Get<time_t>("releasetimeout"));
ValidateNotZero("options", "updatetimeout", options->Get<time_t>("updatetimeout"));
ValidateNotZero("options", "expiretimeout", options->Get<time_t>("expiretimeout"));
ValidateNotZero("options", "readtimeout", options->Get<time_t>("readtimeout"));
ValidateNotZero("options", "warningtimeout", options->Get<time_t>("warningtimeout"));
- ValidateNotZero("options", "timeoutcheck", options->Get<time_t>("timeoutcheck"));
ValidateNotEmpty("options", "enforceruser", options->Get<const Anope::string>("enforceruser"));
ValidateNotEmpty("options", "enforcerhost", options->Get<const Anope::string>("enforcerhost"));
@@ -313,6 +323,7 @@ Conf::Conf() : Block("")
ValidateNotEmpty("service", "user", user);
ValidateNotEmpty("service", "host", host);
ValidateNotEmpty("service", "gecos", gecos);
+ ValidateNoSpaces("service", "channels", channels);
BotInfo *bi = BotInfo::Find(nick, true);
if (!bi)
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 9f2caa02d..871121cc9 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -38,6 +38,12 @@ class ReconnectTimer : public Timer
void Uplink::Connect()
{
+ if (Config->Uplinks.empty())
+ {
+ Log() << "Warning: There are no configured uplinks.";
+ return;
+ }
+
if (static_cast<unsigned>(++Anope::CurrentUplink) >= Config->Uplinks.size())
Anope::CurrentUplink = 0;