Skip to content

Commit

Permalink
Add user input validation to prevent out-of-bound access.
Browse files Browse the repository at this point in the history
Adresses DSO-14405
  • Loading branch information
ev-mp committed Feb 6, 2020
1 parent 8c616ea commit 183c87d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tools/fw-logger/string-formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <regex>
#include <sstream>
#include <iomanip>
#include <iostream>

using namespace std;

Expand Down Expand Up @@ -99,7 +100,14 @@ namespace fw_logger
{
auto vec = _enums[enum_name];
regex e3 = e;
auto res1 = regex_replace(back_inserter(destTemp), source_temp.begin(), source_temp.end(), e3, vec[exp_replace_it->second]);
// Validate user's input is within the enumerated values
if (exp_replace_it->second >=0 && exp_replace_it->second <vec.size())
auto res1 = regex_replace(back_inserter(destTemp), source_temp.begin(), source_temp.end(), e3, vec[exp_replace_it->second]);
else
{
std::cout << "Protocol Error recognized!\nImproper log message received: " << source_temp
<< ", invalid parameter: " << exp_replace_it->second << std::endl;
}
source_temp = destTemp;
}
}
Expand Down

0 comments on commit 183c87d

Please sign in to comment.