summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2018-04-14 16:11:57 +0100
committerPeter Powell <petpow@saberuk.com>2018-04-16 15:29:58 +0100
commit9b8dc77585ada328a306bc12bb9827f083e7cf93 (patch)
tree13f89459bd95cca9fcd23ba2a3cd36e17f85b361
parent780dda83ba3857bc3c330d4b5d38bb251a9d879b (diff)
Add range checking to ConfigTag::getFloat.
-rw-r--r--include/configreader.h2
-rw-r--r--include/inspircd.h1
-rw-r--r--src/configparser.cpp7
-rw-r--r--src/coremods/core_xline/core_xline.cpp2
4 files changed, 8 insertions, 4 deletions
diff --git a/include/configreader.h b/include/configreader.h
index dba092920..460fd342c 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -49,7 +49,7 @@ class CoreExport ConfigTag : public refcountbase
/** Get the value of an option, using def if it does not exist */
unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
/** Get the value of an option, using def if it does not exist */
- double getFloat(const std::string& key, double def);
+ double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX);
/** Get the value of an option, using def if it does not exist */
bool getBool(const std::string& key, bool def = false);
diff --git a/include/inspircd.h b/include/inspircd.h
index 035eff49c..a7f19f483 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -25,6 +25,7 @@
#pragma once
+#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
diff --git a/src/configparser.cpp b/src/configparser.cpp
index 5ee86c811..8a3042eba 100644
--- a/src/configparser.cpp
+++ b/src/configparser.cpp
@@ -524,12 +524,15 @@ unsigned long ConfigTag::getDuration(const std::string& key, unsigned long def,
return ret;
}
-double ConfigTag::getFloat(const std::string &key, double def)
+double ConfigTag::getFloat(const std::string& key, double def, double min, double max)
{
std::string result;
if (!readString(key, result))
return def;
- return strtod(result.c_str(), NULL);
+
+ double res = strtod(result.c_str(), NULL);
+ CheckRange(tag, key, res, def, min, max);
+ return res;
}
bool ConfigTag::getBool(const std::string &key, bool def)
diff --git a/src/coremods/core_xline/core_xline.cpp b/src/coremods/core_xline/core_xline.cpp
index d6c804748..ab80ab4ed 100644
--- a/src/coremods/core_xline/core_xline.cpp
+++ b/src/coremods/core_xline/core_xline.cpp
@@ -28,7 +28,7 @@ bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User
if (insane->getBool(confkey))
return false;
- float itrigger = insane->getFloat("trigger", 95.5);
+ float itrigger = insane->getFloat("trigger", 95.5, 0.0, 100.0);
long matches = test.Run(mask);