diff --git a/src/actions/transformations/css_decode.cc b/src/actions/transformations/css_decode.cc index 79f5f27c..b75ee1e2 100644 --- a/src/actions/transformations/css_decode.cc +++ b/src/actions/transformations/css_decode.cc @@ -37,11 +37,12 @@ namespace transformations { std::string CssDecode::evaluate(std::string value, Assay *assay) { - char *tmp = (char *) malloc(sizeof(char) * value.size() + 1); + char *tmp = reinterpret_cast( + malloc(sizeof(char) * value.size() + 1)); memcpy(tmp, value.c_str(), value.size() + 1); tmp[value.size()] = '\0'; - css_decode_inplace((unsigned char *)tmp, value.size()); + css_decode_inplace(reinterpret_cast(tmp), value.size()); std::string ret(tmp, 0, value.size()); free(tmp); return ret; diff --git a/src/actions/transformations/escape_seq_decode.cc b/src/actions/transformations/escape_seq_decode.cc index a927069b..eb7530db 100644 --- a/src/actions/transformations/escape_seq_decode.cc +++ b/src/actions/transformations/escape_seq_decode.cc @@ -46,7 +46,7 @@ int EscapeSeqDecode::ansi_c_sequences_decode_inplace(unsigned char *input, if ((input[i] == '\\') && (i + 1 < input_len)) { int c = -1; - switch(input[i + 1]) { + switch (input[i + 1]) { case 'a' : c = '\a'; break; @@ -86,22 +86,22 @@ int EscapeSeqDecode::ansi_c_sequences_decode_inplace(unsigned char *input, /* Hexadecimal or octal? */ if (c == -1) { - if ((input[i + 1] == 'x')||(input[i + 1] == 'X')) { + if ((input[i + 1] == 'x') || (input[i + 1] == 'X')) { /* Hexadecimal. */ - if ((i + 3 < input_len)&&(isxdigit(input[i + 2]))&&(isxdigit(input[i + 3]))) { + if ((i + 3 < input_len) && (isxdigit(input[i + 2])) + && (isxdigit(input[i + 3]))) { /* Two digits. */ c = x2c(&input[i + 2]); i += 4; } else { /* Invalid encoding, do nothing. */ } - } - else + } else { if (ISODIGIT(input[i + 1])) { /* Octal. */ char buf[4]; int j = 0; - while((i + 1 + j < input_len)&&(j < 3)) { + while ((i + 1 + j < input_len) && (j < 3)) { buf[j] = input[i + 1 + j]; j++; if (!ISODIGIT(input[i + 1 + j])) break; @@ -113,6 +113,7 @@ int EscapeSeqDecode::ansi_c_sequences_decode_inplace(unsigned char *input, i += 1 + j; } } + } } if (c == -1) { @@ -149,8 +150,7 @@ std::string EscapeSeqDecode::evaluate(std::string value, int size = ansi_c_sequences_decode_inplace(tmp, value.size()); std::string ret(""); - ret.assign((char *)tmp, size); - //ret.append((const char *)tmp); + ret.assign(reinterpret_cast(tmp), size); free(tmp); return ret; diff --git a/src/actions/transformations/hex_decode.cc b/src/actions/transformations/hex_decode.cc index 0265e67a..dd21ca7c 100644 --- a/src/actions/transformations/hex_decode.cc +++ b/src/actions/transformations/hex_decode.cc @@ -42,9 +42,10 @@ std::string HexDecode::evaluate(std::string value, int len = value.length(); std::string newString; - for(int i=0; i< len; i+=2) { - std::string byte = value.substr(i,2); - char chr = (char) (int)strtol(byte.c_str(), NULL, 16); + for (int i=0; i< len; i+=2) { + std::string byte = value.substr(i, 2); + char chr = static_cast(static_cast(strtol(byte.c_str(), + NULL, 16))); newString.push_back(chr); } diff --git a/src/actions/transformations/hex_encode.cc b/src/actions/transformations/hex_encode.cc index 827d702b..e4b87942 100644 --- a/src/actions/transformations/hex_encode.cc +++ b/src/actions/transformations/hex_encode.cc @@ -41,7 +41,7 @@ std::string HexEncode::evaluate(std::string value, std::stringstream result; for (std::size_t i=0; i < value.length(); i++) { - int ii = (char)value[i]; + int ii = reinterpret_cast(value[i]); result << std::setw(2) << std::setfill('0') << std::hex << ii; } diff --git a/src/actions/transformations/js_decode.cc b/src/actions/transformations/js_decode.cc index e704f0b3..d26b1e6c 100644 --- a/src/actions/transformations/js_decode.cc +++ b/src/actions/transformations/js_decode.cc @@ -37,7 +37,8 @@ namespace transformations { std::string JsDecode::evaluate(std::string value, Assay *assay) { - char *val = (char *) malloc(sizeof(char) * value.size() + 1); + char *val = reinterpret_cast( + malloc(sizeof(char) * value.size() + 1)); memcpy(val, value.c_str(), value.size() + 1); val[value.size()] = '\0'; diff --git a/src/actions/transformations/normalise_path.cc b/src/actions/transformations/normalise_path.cc index 7f482bbb..2b81356a 100644 --- a/src/actions/transformations/normalise_path.cc +++ b/src/actions/transformations/normalise_path.cc @@ -42,7 +42,8 @@ std::string NormalisePath::evaluate(std::string value, Assay *assay) { int changed = 0; - char *tmp = (char *) malloc(sizeof(char) * value.size() + 1); + char *tmp = reinterpret_cast( + malloc(sizeof(char) * value.size() + 1)); memcpy(tmp, value.c_str(), value.size() + 1); tmp[value.size()] = '\0'; diff --git a/src/actions/transformations/normalise_path_win.cc b/src/actions/transformations/normalise_path_win.cc index 69cd1f63..15b35a86 100644 --- a/src/actions/transformations/normalise_path_win.cc +++ b/src/actions/transformations/normalise_path_win.cc @@ -38,11 +38,12 @@ std::string NormalisePathWin::evaluate(std::string value, Assay *assay) { int changed; - char *tmp = (char *) malloc(sizeof(char) * value.size() + 1); + char *tmp = reinterpret_cast( + malloc(sizeof(char) * value.size() + 1)); memcpy(tmp, value.c_str(), value.size() + 1); tmp[value.size()] = '\0'; - int i = normalize_path_inplace((unsigned char *)tmp, + int i = normalize_path_inplace(reinterpret_cast(tmp), value.size(), 1, &changed); std::string ret(""); diff --git a/src/actions/transformations/replace_comments.cc b/src/actions/transformations/replace_comments.cc index 9303984d..8e798254 100644 --- a/src/actions/transformations/replace_comments.cc +++ b/src/actions/transformations/replace_comments.cc @@ -39,15 +39,16 @@ ReplaceComments::ReplaceComments(std::string action) std::string ReplaceComments::evaluate(std::string value, Assay *assay) { - long int i, j, incomment; + uint64_t i, j, incomment; int changed = 0; - char *input = (char *) malloc(sizeof(char) * value.size() + 1); + char *input = reinterpret_cast( + malloc(sizeof(char) * value.size() + 1)); memcpy(input, value.c_str(), value.size() + 1); input[value.size()] = '\0'; i = j = incomment = 0; - while(i < value.size()) { + while (i < value.size()) { if (incomment == 0) { if ((input[i] == '/') && (i + 1 < value.size()) && (input[i + 1] == '*')) { @@ -78,7 +79,7 @@ std::string ReplaceComments::evaluate(std::string value, std::string resp; - resp.append((char *)input, j); + resp.append(reinterpret_cast(input), j); free(input); diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index e8d3429c..86753fad 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -45,7 +45,6 @@ #include "actions/transformations/remove_comments.h" #include "actions/transformations/remove_nulls.h" #include "actions/transformations/remove_whitespace.h" -#include "actions/transformations/compress_whitespace.h" #include "actions/transformations/replace_comments.h" #include "actions/transformations/replace_nulls.h" #include "actions/transformations/sha1.h" diff --git a/src/actions/transformations/url_decode.cc b/src/actions/transformations/url_decode.cc index 0dc9a312..31fe94b7 100644 --- a/src/actions/transformations/url_decode.cc +++ b/src/actions/transformations/url_decode.cc @@ -32,9 +32,9 @@ namespace transformations { int UrlDecode::urldecode_nonstrict_inplace(unsigned char *input, - long int input_len, int *invalid_count, int *changed) { + uint64_t input_len, int *invalid_count, int *changed) { unsigned char *d = (unsigned char *)input; - long int i, count; + uint64_t i, count; *changed = 0; @@ -52,7 +52,7 @@ int UrlDecode::urldecode_nonstrict_inplace(unsigned char *input, char c1 = input[i + 1]; char c2 = input[i + 2]; if (VALID_HEX(c1) && VALID_HEX(c2)) { - unsigned long uni = x2c(&input[i + 1]); + uint64_t uni = x2c(&input[i + 1]); *d++ = (wchar_t)uni; count++; @@ -61,13 +61,13 @@ int UrlDecode::urldecode_nonstrict_inplace(unsigned char *input, } else { /* Not a valid encoding, skip this % */ *d++ = input[i++]; - count ++; + count++; (*invalid_count)++; } } else { /* Not enough bytes available, copy the raw bytes. */ *d++ = input[i++]; - count ++; + count++; (*invalid_count)++; } } else { @@ -104,7 +104,8 @@ std::string UrlDecode::evaluate(std::string value, memcpy(val, value.c_str(), value.size() + 1); val[value.size()] = '\0'; - int size = urldecode_nonstrict_inplace(val, value.size(), &invalid_count, &changed); + int size = urldecode_nonstrict_inplace(val, value.size(), + &invalid_count, &changed); std::string out; out.append((const char *)val, size); diff --git a/src/actions/transformations/url_decode.h b/src/actions/transformations/url_decode.h index fdde03c9..dad317d6 100644 --- a/src/actions/transformations/url_decode.h +++ b/src/actions/transformations/url_decode.h @@ -34,7 +34,7 @@ class UrlDecode : public Transformation { std::string evaluate(std::string exp, Assay *assay) override; - int urldecode_nonstrict_inplace(unsigned char *input, long int input_len, + int urldecode_nonstrict_inplace(unsigned char *input, uint64_t input_len, int *invalid_count, int *changed); }; diff --git a/src/actions/transformations/url_encode.cc b/src/actions/transformations/url_encode.cc index 8c900eac..5756255c 100644 --- a/src/actions/transformations/url_encode.cc +++ b/src/actions/transformations/url_encode.cc @@ -46,7 +46,7 @@ std::string UrlEncode::url_enc(const char *input, *changed = 0; len = input_len * 3 + 1; - d = rval = (char *)malloc(len); + d = rval = reinterpret_cast(malloc(len)); if (rval == NULL) { return NULL; } @@ -63,7 +63,7 @@ std::string UrlEncode::url_enc(const char *input, } else { if ( (c == 42) || ((c >= 48) && (c <= 57)) || ((c >= 65) && (c <= 90)) - || ((c >= 97)&&(c <= 122))) { + || ((c >= 97) && (c <= 122))) { *d++ = c; count++; } else { diff --git a/src/operators/verify_cc.cc b/src/operators/verify_cc.cc index e654228a..5908fce1 100644 --- a/src/operators/verify_cc.cc +++ b/src/operators/verify_cc.cc @@ -15,9 +15,10 @@ #include "operators/verify_cc.h" -#include #include +#include #include +#include #include "operators/operator.h" diff --git a/src/operators/verify_cc.h b/src/operators/verify_cc.h index 66a16c0e..9257e8cc 100644 --- a/src/operators/verify_cc.h +++ b/src/operators/verify_cc.h @@ -16,8 +16,8 @@ #ifndef SRC_OPERATORS_VERIFY_CC_H_ #define SRC_OPERATORS_VERIFY_CC_H_ -#include #include +#include #include "operators/operator.h" diff --git a/src/utils.h b/src/utils.h index 3534b353..f583bd62 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,7 +21,7 @@ #include "modsecurity/modsecurity.h" #ifndef SRC_UTILS_H_ - +#define SRC_UTILS_H_ #define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \ ((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F'))) @@ -60,6 +60,5 @@ namespace ModSecurity { const std::string& param); } // namespace ModSecurity -#define SRC_UTILS_H_ #endif // SRC_UTILS_H_ diff --git a/src/utils/sha1.cc b/src/utils/sha1.cc index bb7d10c1..2badaf40 100644 --- a/src/utils/sha1.cc +++ b/src/utils/sha1.cc @@ -104,7 +104,6 @@ std::string SHA1::final_bin(bool toReset = true) { std::string SHA1::final() { - final_bin(false); /* Hex std::string */ diff --git a/test/unit/unit_test.cc b/test/unit/unit_test.cc index 48545546..2f3bec44 100644 --- a/test/unit/unit_test.cc +++ b/test/unit/unit_test.cc @@ -72,8 +72,10 @@ std::string UnitTest::print() { i << this->obtained << "\"" << std::endl; } if (this->output != this->obtainedOutput) { - i << "Expecting: \"" << ModSecurity::toHexIfNeeded(this->output) << "\" - returned: \""; - i << ModSecurity::toHexIfNeeded(this->obtainedOutput) << "\"" << std::endl; + i << "Expecting: \"" << ModSecurity::toHexIfNeeded(this->output); + i << "\" - returned: \""; + i << ModSecurity::toHexIfNeeded(this->obtainedOutput) << "\""; + i << std::endl; } return i.str();