diff options
| author | Ben Fuhrmannek | 2021-02-18 15:49:39 +0100 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-02-18 15:49:39 +0100 |
| commit | 01528718850c8528ef6d2ed5296e244d4aa7b675 (patch) | |
| tree | 4fa1763db9211919bd03bf0b8e2beb3aae0da463 /src/sp_utils.c | |
| parent | ae863454f6c757653e20260f54615944fc9a3319 (diff) | |
log forging protection
Diffstat (limited to 'src/sp_utils.c')
| -rw-r--r-- | src/sp_utils.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c index a7a3d27..73c0546 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -229,6 +229,19 @@ static char* zend_string_to_char(const zend_string* zs) { | |||
| 229 | return copy; | 229 | return copy; |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | static void sp_sanitize_charstring(char* c, size_t maxlen) | ||
| 233 | { | ||
| 234 | for (size_t i = 0; *c; c++, i++) { | ||
| 235 | if (maxlen && i > maxlen - 1) { | ||
| 236 | *c = 0; | ||
| 237 | return; | ||
| 238 | } | ||
| 239 | if (*c < 32 || *c > 126) { | ||
| 240 | *c = '*'; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 232 | const zend_string* sp_zval_to_zend_string(const zval* zv) { | 245 | const zend_string* sp_zval_to_zend_string(const zval* zv) { |
| 233 | switch (Z_TYPE_P(zv)) { | 246 | switch (Z_TYPE_P(zv)) { |
| 234 | case IS_LONG: { | 247 | case IS_LONG: { |
| @@ -295,6 +308,7 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, | |||
| 295 | char* char_repr = NULL; | 308 | char* char_repr = NULL; |
| 296 | if (arg_value) { | 309 | if (arg_value) { |
| 297 | char_repr = zend_string_to_char(arg_value); | 310 | char_repr = zend_string_to_char(arg_value); |
| 311 | sp_sanitize_charstring(char_repr, 255); | ||
| 298 | } | 312 | } |
| 299 | if (alias) { | 313 | if (alias) { |
| 300 | sp_log_auto( | 314 | sp_log_auto( |
| @@ -336,6 +350,7 @@ void sp_log_disable_ret(const char* restrict path, | |||
| 336 | } | 350 | } |
| 337 | if (ret_value) { | 351 | if (ret_value) { |
| 338 | char_repr = zend_string_to_char(ret_value); | 352 | char_repr = zend_string_to_char(ret_value); |
| 353 | sp_sanitize_charstring(char_repr, 255); | ||
| 339 | } | 354 | } |
| 340 | if (alias) { | 355 | if (alias) { |
| 341 | sp_log_auto( | 356 | sp_log_auto( |
