Improve argument validation for the String#substr and String#find methods

refs #8169
This commit is contained in:
Gunnar Beutner 2015-01-14 17:02:10 +01:00
parent dd1cbb6fe7
commit c0a5ed81f4
1 changed files with 6 additions and 3 deletions

View File

@ -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)