diff options
| author | jvoisin | 2023-02-01 21:12:58 +0100 |
|---|---|---|
| committer | jvoisin | 2023-02-02 13:17:22 +0100 |
| commit | 2dcf2a2d7578d1e43ee7e3fa69386ccc5afebbf0 (patch) | |
| tree | a1b4b74396e89f66ccb9f54fe878ba607c103aec /src/sp_utils.c | |
| parent | f4d3c01bd196400548f5712223171007563ab834 (diff) | |
Url encode functions arguments when logging them
Diffstat (limited to '')
| -rw-r--r-- | src/sp_utils.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c index 1bac1ae..eeebcc4 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -232,16 +232,6 @@ static char* zend_string_to_char(const zend_string* zs) { | |||
| 232 | return copy; | 232 | return copy; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | static void sp_sanitize_charstring(char* c, size_t maxlen) | ||
| 236 | { | ||
| 237 | for (size_t i = 0; i < maxlen - 1; i++) { | ||
| 238 | if (c[i] < 32 || c[i] > 126) { | ||
| 239 | c[i] = '*'; | ||
| 240 | } | ||
| 241 | } | ||
| 242 | c[maxlen] = 0; | ||
| 243 | } | ||
| 244 | |||
| 245 | const zend_string* sp_zval_to_zend_string(const zval* zv) { | 235 | const zend_string* sp_zval_to_zend_string(const zval* zv) { |
| 246 | switch (Z_TYPE_P(zv)) { | 236 | switch (Z_TYPE_P(zv)) { |
| 247 | case IS_LONG: { | 237 | case IS_LONG: { |
| @@ -300,8 +290,11 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, | |||
| 300 | if (arg_name) { | 290 | if (arg_name) { |
| 301 | char* char_repr = NULL; | 291 | char* char_repr = NULL; |
| 302 | if (arg_value) { | 292 | if (arg_value) { |
| 303 | char_repr = zend_string_to_char(arg_value); | 293 | zend_string *arg_value_dup = zend_string_init(ZSTR_VAL(arg_value), ZSTR_LEN(arg_value), 0); |
| 304 | sp_sanitize_charstring(char_repr, MIN(ZSTR_LEN(arg_value), (size_t)SPCFG(log_max_len))); | 294 | arg_value_dup = php_raw_url_encode(ZSTR_VAL(arg_value_dup), ZSTR_LEN(arg_value_dup)); |
| 295 | char_repr = zend_string_to_char(arg_value_dup); | ||
| 296 | size_t max_len = MIN(ZSTR_LEN(arg_value_dup), (size_t)SPCFG(log_max_len)); | ||
| 297 | char_repr[max_len] = '\0'; | ||
| 305 | } | 298 | } |
| 306 | if (alias) { | 299 | if (alias) { |
| 307 | sp_log_auto( | 300 | sp_log_auto( |
| @@ -341,8 +334,11 @@ void sp_log_disable_ret(const char* restrict path, | |||
| 341 | sp_log_request(dump, config_node->textual_representation); | 334 | sp_log_request(dump, config_node->textual_representation); |
| 342 | } | 335 | } |
| 343 | if (ret_value) { | 336 | if (ret_value) { |
| 344 | char_repr = zend_string_to_char(ret_value); | 337 | zend_string *ret_value_dup = zend_string_init(ZSTR_VAL(ret_value), ZSTR_LEN(ret_value), 0); |
| 345 | sp_sanitize_charstring(char_repr, MIN(ZSTR_LEN(ret_value), (size_t)SPCFG(log_max_len))); | 338 | ret_value_dup = php_raw_url_encode(ZSTR_VAL(ret_value_dup), ZSTR_LEN(ret_value_dup)); |
| 339 | char_repr = zend_string_to_char(ret_value_dup); | ||
| 340 | size_t max_len = MIN(ZSTR_LEN(ret_value_dup), (size_t)SPCFG(log_max_len)); | ||
| 341 | char_repr[max_len] = '\0'; | ||
| 346 | } | 342 | } |
| 347 | if (alias) { | 343 | if (alias) { |
| 348 | sp_log_auto( | 344 | sp_log_auto( |
