mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-17 09:55:28 +03:00
Replace usage of range-checked 'at' method when vector/string has already been size checked
This commit is contained in:
@@ -23,13 +23,14 @@
|
||||
namespace modsecurity {
|
||||
namespace operators {
|
||||
|
||||
bool ContainsWord::acceptableChar(const std::string& a, size_t pos) {
|
||||
inline bool ContainsWord::acceptableChar(const std::string& a, size_t pos) {
|
||||
if (a.size() - 1 < pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((a.at(pos) >= 65 && a.at(pos) <= 90) ||
|
||||
(a.at(pos) >= 97 && a.at(pos) <= 122)) {
|
||||
const auto ch = a[pos];
|
||||
if ((ch >= 65 && ch <= 90) ||
|
||||
(ch >= 97 && ch <= 122)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ bool InspectFile::evaluate(Transaction *transaction, const std::string &str) {
|
||||
pclose(in);
|
||||
|
||||
res.append(s.str());
|
||||
if (res.size() > 1 && res.at(0) != '1') {
|
||||
if (res.size() > 1 && res[0] != '1') {
|
||||
return true; /* match */
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ static inline std::string parse_pm_content(const std::string &op_parm) {
|
||||
|
||||
auto size = op_parm.size() - offset;
|
||||
if (size >= 2 &&
|
||||
op_parm.at(offset) == '\"' && op_parm.back() == '\"') {
|
||||
op_parm[offset] == '\"' && op_parm.back() == '\"') {
|
||||
offset++;
|
||||
size -= 2;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ bool ValidateByteRange::evaluate(Transaction *transaction, RuleWithActions *rule
|
||||
bool ret = true;
|
||||
|
||||
size_t count = 0;
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
int x = (unsigned char) input.at(i);
|
||||
for (std::string::size_type i = 0; i < input.length(); i++) {
|
||||
int x = (unsigned char) input[i];
|
||||
if (!(table[x >> 3] & (1 << (x & 0x7)))) {
|
||||
// debug(9, "Value " + std::to_string(x) + " in " +
|
||||
// input + " ouside range: " + param);
|
||||
|
||||
Reference in New Issue
Block a user