mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-16 17:41:52 +03:00
Replace usage of range-checked 'at' method when vector/string has already been size checked
This commit is contained in:
@@ -107,12 +107,12 @@ inline std::string toHexIfNeeded(const std::string &str, bool escape_spec = fals
|
||||
// spec chars: '"' (quotation mark, ascii 34), '\' (backslash, ascii 92)
|
||||
std::stringstream res;
|
||||
|
||||
for (int i = 0; i < str.size(); i++) {
|
||||
int c = (unsigned char)str.at(i);
|
||||
for (const auto ch : str) {
|
||||
int c = (unsigned char)ch;
|
||||
if (c < 32 || c > 126 || (escape_spec == true && (c == 34 || c == 92))) {
|
||||
res << "\\x" << std::setw(2) << std::setfill('0') << std::hex << c;
|
||||
} else {
|
||||
res << str.at(i);
|
||||
res << ch;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,10 +177,10 @@ inline void replaceAll(std::string &str, std::string_view from,
|
||||
|
||||
|
||||
inline std::string removeWhiteSpacesIfNeeded(std::string a) {
|
||||
while (a.size() > 1 && a.at(0) == ' ') {
|
||||
while (a.size() > 1 && a.front() == ' ') {
|
||||
a.erase(0, 1);
|
||||
}
|
||||
while (a.size() > 1 && a.at(a.length()-1) == ' ') {
|
||||
while (a.size() > 1 && a.back() == ' ') {
|
||||
a.pop_back();
|
||||
}
|
||||
return a;
|
||||
@@ -188,11 +188,11 @@ inline std::string removeWhiteSpacesIfNeeded(std::string a) {
|
||||
|
||||
|
||||
inline std::string removeBracketsIfNeeded(std::string a) {
|
||||
if (a.length() > 1 && a.at(0) == '"' && a.at(a.length()-1) == '"') {
|
||||
if (a.length() > 1 && a.front() == '"' && a.back() == '"') {
|
||||
a.pop_back();
|
||||
a.erase(0, 1);
|
||||
}
|
||||
if (a.length() > 1 && a.at(0) == '\'' && a.at(a.length()-1) == '\'') {
|
||||
if (a.length() > 1 && a.front() == '\'' && a.back() == '\'') {
|
||||
a.pop_back();
|
||||
a.erase(0, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user