]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add range checking to ConfigTag::getFloat.
authorPeter Powell <petpow@saberuk.com>
Sat, 14 Apr 2018 15:11:57 +0000 (16:11 +0100)
committerPeter Powell <petpow@saberuk.com>
Mon, 16 Apr 2018 14:29:58 +0000 (15:29 +0100)
include/configreader.h
include/inspircd.h
src/configparser.cpp
src/coremods/core_xline/core_xline.cpp

index dba0929208d182d2456154615b0a5d6e9ca5bfc0..460fd342c6a47a45a08d5e5299394d0259bbfc15 100644 (file)
@@ -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);
 
index 035eff49cda597534fdd101818c4b672e8b75d01..a7f19f483171123635956686847ece1f1b70363d 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <cfloat>
 #include <climits>
 #include <cmath>
 #include <csignal>
index 5ee86c81178c49acd128ac940ae02aedc05757dc..8a3042ebadba5393f4281eeb244fc2fd11181f76 100644 (file)
@@ -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)
index d6c804748559d93678ec7f1eafca5665fc0bef8e..ab80ab4ed50bfeba7d1b72dfdbeaafcad6718eb4 100644 (file)
@@ -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);