mirror of https://github.com/Icinga/icinga2.git
Improve argument validation for the String#substr and String#find methods
refs #8169
This commit is contained in:
parent
dd1cbb6fe7
commit
c0a5ed81f4
|
@ -49,7 +49,7 @@ static String StringSubstr(const std::vector<Value>& args)
|
|||
if (args.empty())
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments"));
|
||||
|
||||
if (static_cast<double>(args[0]) >= self.GetLength())
|
||||
if (static_cast<double>(args[0]) < 0 || static_cast<double>(args[0]) >= self.GetLength())
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("String index is out of range"));
|
||||
|
||||
if (args.size() > 1)
|
||||
|
@ -96,9 +96,12 @@ static Value StringFind(const std::vector<Value>& args)
|
|||
|
||||
String::SizeType result;
|
||||
|
||||
if (args.size() > 1)
|
||||
if (args.size() > 1) {
|
||||
if (static_cast<double>(args[1]) < 0)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("String index is out of range"));
|
||||
|
||||
result = self.Find(args[0], args[1]);
|
||||
else
|
||||
} else
|
||||
result = self.Find(args[0]);
|
||||
|
||||
if (result == String::NPos)
|
||||
|
|
Loading…
Reference in New Issue