mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-17 06:36:13 +03:00
Adds functions limitTo and toHexIfNeed into utils.cc
Those will be used in order to make the debug and audit logs readable.
This commit is contained in:
parent
97214edf6e
commit
8772daec4d
29
src/utils.cc
29
src/utils.cc
@ -992,6 +992,35 @@ int urldecode_uni_nonstrict_inplace_ex(Assay *assay, unsigned char *input,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string limitTo(int amount, const std::string &str) {
|
||||||
|
std::string ret;
|
||||||
|
|
||||||
|
if (str.length() > amount) {
|
||||||
|
ret.assign(str, 0, amount);
|
||||||
|
ret = ret + " (" + std::to_string(str.length() - amount) + " " \
|
||||||
|
"characters omitted)";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toHexIfNeeded(const std::string &str) {
|
||||||
|
std::stringstream res;
|
||||||
|
size_t pos;
|
||||||
|
|
||||||
|
for (int i = 0; i < str.size(); i++) {
|
||||||
|
int c = str.at(i);
|
||||||
|
if (c < 33 || c > 126) {
|
||||||
|
res << "\\x" << std::setw(2) << std::setfill('0') << std::hex << c;
|
||||||
|
} else {
|
||||||
|
res << str.at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace ModSecurity
|
} // namespace ModSecurity
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ namespace ModSecurity {
|
|||||||
int urldecode_uni_nonstrict_inplace_ex(Assay *assay, unsigned char *input,
|
int urldecode_uni_nonstrict_inplace_ex(Assay *assay, unsigned char *input,
|
||||||
int64_t input_len, int *changed);
|
int64_t input_len, int *changed);
|
||||||
std::string phase_name(int x);
|
std::string phase_name(int x);
|
||||||
|
std::string limitTo(int amount, const std::string &str);
|
||||||
|
std::string toHexIfNeeded(const std::string &str);
|
||||||
} // namespace ModSecurity
|
} // namespace ModSecurity
|
||||||
|
|
||||||
#define SRC_UTILS_H_
|
#define SRC_UTILS_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user