Skip to content

Commit

Permalink
Replaced VALID_HEX, ISODIGIT & NBSP macros in string.h
Browse files Browse the repository at this point in the history
- Moved them into modsecurity::utils::string to avoid polluting the
  global namespace.
  • Loading branch information
eduar-hte committed Aug 21, 2024
1 parent 2ef14bf commit b6eb3cb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/actions/transformations/css_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "src/utils/string.h"

using namespace modsecurity::utils::string;

namespace modsecurity::actions::transformations {

Expand Down
2 changes: 2 additions & 0 deletions src/actions/transformations/escape_seq_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "src/utils/string.h"

using namespace modsecurity::utils::string;

namespace modsecurity::actions::transformations {


Expand Down
1 change: 1 addition & 0 deletions src/actions/transformations/html_entity_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "src/compat/msvc.h"
#endif

using namespace modsecurity::utils::string;

namespace modsecurity::actions::transformations {

Expand Down
1 change: 1 addition & 0 deletions src/actions/transformations/js_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "src/utils/string.h"

using namespace modsecurity::utils::string;

namespace modsecurity::actions::transformations {

Expand Down
1 change: 1 addition & 0 deletions src/actions/transformations/sql_hex_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "src/utils/string.h"

using namespace modsecurity::utils::string;

namespace modsecurity::actions::transformations {

Expand Down
1 change: 1 addition & 0 deletions src/actions/transformations/url_decode_uni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "modsecurity/rules_set.h"
#include "src/utils/string.h"

using namespace modsecurity::utils::string;

namespace modsecurity::actions::transformations {

Expand Down
7 changes: 3 additions & 4 deletions src/utils/decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "modsecurity/modsecurity.h"
#include "src/utils/string.h"

using namespace modsecurity::utils::string;

namespace modsecurity {
namespace utils {
namespace modsecurity::utils {


bool urldecode_nonstrict_inplace(std::string &val,
Expand Down Expand Up @@ -112,5 +112,4 @@ std::string uri_decode(const std::string & sSrc) {
}


} // namespace utils
} // namespace modsecurity
} // namespace modsecurity::utils
28 changes: 16 additions & 12 deletions src/utils/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*
*/

#ifndef SRC_UTILS_STRING_H_
#define SRC_UTILS_STRING_H_

#include <ctime>
#include <string>
#include <cstring>
Expand All @@ -27,18 +30,21 @@
#include "src/compat/msvc.h"
#endif

#ifndef SRC_UTILS_STRING_H_
#define SRC_UTILS_STRING_H_
namespace modsecurity::utils::string {

#define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \
((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F')))
#define ISODIGIT(X) ((X >= '0') && (X <= '7'))
#define NBSP 160
template<typename CharT>
constexpr bool VALID_HEX(CharT X) {
return ((X >= '0') && (X <= '9'))
|| ((X >= 'a') && (X <= 'f'))
|| ((X >= 'A') && (X <= 'F'));
}

template<typename CharT>
constexpr bool ISODIGIT(CharT X) {
return (X >= '0') && (X <= '7');
}

namespace modsecurity {
namespace utils {
namespace string {
constexpr unsigned char NBSP = 160;

const char HEX2DEC[256] = {
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
Expand Down Expand Up @@ -271,8 +277,6 @@ inline std::string toupper(std::string str) { // cppcheck-suppress passedByValue
}


} // namespace string
} // namespace utils
} // namespace modsecurity
} // namespace modsecurity::utils::string

#endif // SRC_UTILS_STRING_H_

0 comments on commit b6eb3cb

Please sign in to comment.