24 Commits

Author SHA1 Message Date
Eduardo Arias
0613ceeb75 Replace usage of range-checked 'at' method when vector/string has already been size checked 2024-10-15 15:12:10 -03:00
Eduardo Arias
a6d64bf615 Replaced VALID_HEX, ISODIGIT & NBSP macros in string.h
- Moved them into modsecurity::utils::string to avoid polluting the
  global namespace.
2024-08-27 10:00:54 -03:00
Eduardo Arias
5d39890783 Updated Transformation::evaluate signature to allow for in-place updates, removing unnecessary heap allocated copies.
- Renamed Transformation::evaluate to Transformation::transform to avoid
  confusion with Action's overload methods.
- Updated Transformation::transform signature to receive the value by
  reference and perform the transformation inline, if possible.
  - Some transformations still need to use a temporary std::string to
    perform their work, and then copy the result back.
- Made Transformation::transform methods const and updated Transaction
  parameter to be const.
  - Transaction parameter could not be removed because it's used by just
    a single transformation, UrlDecodeUni.
- Removed std::string Action::evaluate(const std::string &exp,
  Transaction *transaction); which was only implemented by
  Transformation but was not used from the base class, but only after
  downcasting to Transformation, so it can just be declared there (and
  not pollute other actions with a default member implementation -that
  does nothing- which is never called).
2024-08-27 10:00:17 -03:00
Eduardo Arias
5e6fcbc60b Replace usage of std::ctime, which is not safe for use in multithreaded contexts
- std::ctime returns a pointer to a string that "may be shared between
  std::asctime and std::ctime, and may be overwritten on each invocation
  of any of those functions.".
  - https://en.cppreference.com/w/cpp/chrono/c/ctime
- Replaced with call to strftime to generate the same string
  representation (using the format string: %c)
- Leveraged localtime_r (which is thread-safe) to convert time_t to
  struct tm, as required by strftime.
2024-08-13 10:54:06 -07:00
Eduardo Arias
77adb57524 Avoid std::string copy in ssplit argument
- Other minor changes reported by sonarcloud
2024-08-12 12:59:28 -07:00
Eduardo Arias
cc0f893854 Removed unused overload of dash_if_empty that sonarcloud flags as potential buffer overflow 2024-08-09 14:07:39 -07:00
Eduardo Arias
8b17f3691f Inline string functions 2024-08-09 13:21:46 -07:00
Eduardo Arias
bb07de9ad7 toupper/tolower is already receiving a copy, so it doesn't need to create a new one to transform it
- Make functions inline to improve performance
- Introduced helper method toCaseHelper to remove code duplication
2024-08-09 12:52:25 -07:00
Eduardo Arias
0b5493d4e7 Minor performance improvements setting up intervention's log
- Initialize `log` temporary value on construction instead of doing
  default initialization and then calling `append`.
- Leverage `std::string_view` to replace `const std::string&` parameters
  in `utils::string::replaceAll` to avoid creating a `std::string`
  object (and associated allocation and copy) for the string literal`%d`
2024-08-06 14:40:45 -07:00
Martin Vierula
cb4d7ae371
Adjust some copyright dates 2023-10-31 06:23:19 -07:00
Martin Vierula
4fac8d72f4
Address some constParameter complaints from cppcheck 2023-04-28 08:20:37 -07:00
Ervin Hegedüs
6dd00be229 Refactorized multiple prototypes 2023-01-18 16:40:52 +01:00
Ervin Hegedüs
d63d8849a8 Remove previously removed fn proto from header 2023-01-18 16:28:47 +01:00
Ervin Hegedüs
c7306d174a Extend utils::string::toHexIfNeeded() to encode '"' and '\' characters optionally 2023-01-17 20:57:03 +01:00
Ervin Hegedüs
3b7ca3e44c Escape log field 'data' value 2022-12-30 12:23:00 +01:00
Felipe Zimmerle
3748d62f19
Changes copyright dates on the code 2021-01-19 09:24:37 -03:00
Felipe Zimmerle
357c140003
Changens copyright year 2020-01-31 10:32:37 -03:00
martinhsv
9cac167faf Fix argument key-value pair parsing cases 2019-11-05 13:06:29 -03:00
Athmane Madjoudj
968d83f1ff
Fix build on non x86 arch build failed on ppc64/ppc64le/arch64/armv7hl/s390x due to how this arch represent chars 2017-10-25 16:44:27 -03:00
Felipe Zimmerle
49b7ea99e6 Adds a set of sanity checks to validate API inputs (1 of 2) 2017-06-21 12:59:19 -07:00
Felipe Zimmerle
e795253ecf
Fix crash on SecRuleRemoveById malformated parameter
Fix issue #1440
2017-06-06 22:14:13 -03:00
Felipe Zimmerle
bfc30dad34
Refactoring: how to report to error logs 2016-12-01 01:05:29 -03:00
Felipe Zimmerle
2244e874e2
Moves static methods from class String to the namespace string 2016-11-04 16:00:44 -03:00
Felipe Zimmerle
62a0cb468b
Renames utils/msc_string.[h|cc] to utils/string.[h|cc] 2016-11-04 16:00:42 -03:00