diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_utils.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c index 0fae9ba..1bac1ae 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | #ifndef MIN | ||
| 4 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 5 | #endif | ||
| 6 | |||
| 3 | static char const* const default_ipaddr = "0.0.0.0"; | 7 | static char const* const default_ipaddr = "0.0.0.0"; |
| 4 | const char* get_ipaddr() { | 8 | const char* get_ipaddr() { |
| 5 | const char* client_ip = getenv("REMOTE_ADDR"); | 9 | const char* client_ip = getenv("REMOTE_ADDR"); |
| @@ -230,15 +234,12 @@ static char* zend_string_to_char(const zend_string* zs) { | |||
| 230 | 234 | ||
| 231 | static void sp_sanitize_charstring(char* c, size_t maxlen) | 235 | static void sp_sanitize_charstring(char* c, size_t maxlen) |
| 232 | { | 236 | { |
| 233 | for (size_t i = 0; *c; c++, i++) { | 237 | for (size_t i = 0; i < maxlen - 1; i++) { |
| 234 | if (maxlen && i > maxlen - 1) { | 238 | if (c[i] < 32 || c[i] > 126) { |
| 235 | *c = 0; | 239 | c[i] = '*'; |
| 236 | return; | ||
| 237 | } | ||
| 238 | if (*c < 32 || *c > 126) { | ||
| 239 | *c = '*'; | ||
| 240 | } | 240 | } |
| 241 | } | 241 | } |
| 242 | c[maxlen] = 0; | ||
| 242 | } | 243 | } |
| 243 | 244 | ||
| 244 | const zend_string* sp_zval_to_zend_string(const zval* zv) { | 245 | const zend_string* sp_zval_to_zend_string(const zval* zv) { |
| @@ -300,7 +301,7 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, | |||
| 300 | char* char_repr = NULL; | 301 | char* char_repr = NULL; |
| 301 | if (arg_value) { | 302 | if (arg_value) { |
| 302 | char_repr = zend_string_to_char(arg_value); | 303 | char_repr = zend_string_to_char(arg_value); |
| 303 | sp_sanitize_charstring(char_repr, SPCFG(log_max_len)); | 304 | sp_sanitize_charstring(char_repr, MIN(ZSTR_LEN(arg_value), (size_t)SPCFG(log_max_len))); |
| 304 | } | 305 | } |
| 305 | if (alias) { | 306 | if (alias) { |
| 306 | sp_log_auto( | 307 | sp_log_auto( |
| @@ -341,7 +342,7 @@ void sp_log_disable_ret(const char* restrict path, | |||
| 341 | } | 342 | } |
| 342 | if (ret_value) { | 343 | if (ret_value) { |
| 343 | char_repr = zend_string_to_char(ret_value); | 344 | char_repr = zend_string_to_char(ret_value); |
| 344 | sp_sanitize_charstring(char_repr, SPCFG(log_max_len)); | 345 | sp_sanitize_charstring(char_repr, MIN(ZSTR_LEN(ret_value), (size_t)SPCFG(log_max_len))); |
| 345 | } | 346 | } |
| 346 | if (alias) { | 347 | if (alias) { |
| 347 | sp_log_auto( | 348 | sp_log_auto( |
