diff options
| author | jvoisin | 2023-01-31 20:16:21 +0100 |
|---|---|---|
| committer | jvoisin | 2023-01-31 20:25:14 +0100 |
| commit | 78e451eaf99e8f239867def2d8220dfa348cc167 (patch) | |
| tree | dcd1f1964634919bd0b9784d3546fd3690f389a1 /src | |
| parent | 26f9987a538dc68d5a825b1712d3456a2d7aa109 (diff) | |
Add sp.log_max_len
Diffstat (limited to 'src')
| -rw-r--r-- | src/php_snuffleupagus.h | 1 | ||||
| -rw-r--r-- | src/snuffleupagus.c | 2 | ||||
| -rw-r--r-- | src/sp_config.c | 1 | ||||
| -rw-r--r-- | src/sp_config.h | 1 | ||||
| -rw-r--r-- | src/sp_config_keywords.c | 1 | ||||
| -rw-r--r-- | src/sp_utils.c | 4 | ||||
| -rw-r--r-- | src/tests/config/phplog_max_len.ini | 2 | ||||
| -rw-r--r-- | src/tests/phplog_max_len.phpt | 14 |
8 files changed, 24 insertions, 2 deletions
diff --git a/src/php_snuffleupagus.h b/src/php_snuffleupagus.h index 7af4da2..229c1b9 100644 --- a/src/php_snuffleupagus.h +++ b/src/php_snuffleupagus.h | |||
| @@ -131,6 +131,7 @@ sp_config_wrapper config_wrapper; | |||
| 131 | sp_config_session config_session; | 131 | sp_config_session config_session; |
| 132 | sp_config_ini config_ini; | 132 | sp_config_ini config_ini; |
| 133 | char config_log_media; | 133 | char config_log_media; |
| 134 | int config_log_max_len; | ||
| 134 | u_long config_max_execution_depth; | 135 | u_long config_max_execution_depth; |
| 135 | bool config_server_encode; | 136 | bool config_server_encode; |
| 136 | bool config_server_strip; | 137 | bool config_server_strip; |
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 8454fc1..c957cf6 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -89,6 +89,7 @@ static PHP_GINIT_FUNCTION(snuffleupagus) { | |||
| 89 | sp_load_other_modules(); | 89 | sp_load_other_modules(); |
| 90 | snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; | 90 | snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; |
| 91 | snuffleupagus_globals->in_eval = 0; | 91 | snuffleupagus_globals->in_eval = 0; |
| 92 | snuffleupagus_globals->config_log_max_len = 255; | ||
| 92 | 93 | ||
| 93 | #define SP_INIT_HT(F) \ | 94 | #define SP_INIT_HT(F) \ |
| 94 | snuffleupagus_globals->F = pemalloc(sizeof(*(snuffleupagus_globals->F)), 1); \ | 95 | snuffleupagus_globals->F = pemalloc(sizeof(*(snuffleupagus_globals->F)), 1); \ |
| @@ -355,6 +356,7 @@ static void dump_config() { | |||
| 355 | add_assoc_bool(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_ENCRYPTION_KEY, SPCFG(encryption_key) && ZSTR_LEN(SPCFG(encryption_key))); | 356 | add_assoc_bool(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_ENCRYPTION_KEY, SPCFG(encryption_key) && ZSTR_LEN(SPCFG(encryption_key))); |
| 356 | ADD_ASSOC_ZSTR(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_ENV_VAR, SPCFG(cookies_env_var)); | 357 | ADD_ASSOC_ZSTR(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_ENV_VAR, SPCFG(cookies_env_var)); |
| 357 | add_assoc_long(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_LOG_MEDIA, SPCFG(log_media)); | 358 | add_assoc_long(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_LOG_MEDIA, SPCFG(log_media)); |
| 359 | add_assoc_long(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_LOG_MAX_LEN, SPCFG(log_max_len)); | ||
| 358 | add_assoc_long(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_MAX_EXECUTION_DEPTH, SPCFG(max_execution_depth)); | 360 | add_assoc_long(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_MAX_EXECUTION_DEPTH, SPCFG(max_execution_depth)); |
| 359 | add_assoc_bool(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_SERVER_ENCODE, SPCFG(server_encode)); | 361 | add_assoc_bool(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_SERVER_ENCODE, SPCFG(server_encode)); |
| 360 | add_assoc_bool(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_SERVER_STRIP, SPCFG(server_strip)); | 362 | add_assoc_bool(&arr, SP_TOKEN_GLOBAL "." SP_TOKEN_SERVER_STRIP, SPCFG(server_strip)); |
diff --git a/src/sp_config.c b/src/sp_config.c index 8bd238a..5db511e 100644 --- a/src/sp_config.c +++ b/src/sp_config.c | |||
| @@ -11,6 +11,7 @@ static zend_result sp_process_config_root(sp_parsed_keyword *parsed_rule) { | |||
| 11 | {parse_unserialize_noclass, SP_TOKEN_UNSERIALIZE_NOCLASS, &(SPCFG(unserialize_noclass))}, | 11 | {parse_unserialize_noclass, SP_TOKEN_UNSERIALIZE_NOCLASS, &(SPCFG(unserialize_noclass))}, |
| 12 | {parse_enable, SP_TOKEN_HARDEN_RANDOM, &(SPCFG(random).enable)}, | 12 | {parse_enable, SP_TOKEN_HARDEN_RANDOM, &(SPCFG(random).enable)}, |
| 13 | {parse_log_media, SP_TOKEN_LOG_MEDIA, &(SPCFG(log_media))}, | 13 | {parse_log_media, SP_TOKEN_LOG_MEDIA, &(SPCFG(log_media))}, |
| 14 | {parse_ulong, SP_TOKEN_LOG_MAX_LEN, &(SPCFG(log_max_len))}, | ||
| 14 | {parse_disabled_functions, SP_TOKEN_DISABLE_FUNC, NULL}, | 15 | {parse_disabled_functions, SP_TOKEN_DISABLE_FUNC, NULL}, |
| 15 | {parse_readonly_exec, SP_TOKEN_READONLY_EXEC, &(SPCFG(readonly_exec))}, | 16 | {parse_readonly_exec, SP_TOKEN_READONLY_EXEC, &(SPCFG(readonly_exec))}, |
| 16 | {parse_enable, SP_TOKEN_GLOBAL_STRICT, &(SPCFG(global_strict).enable)}, | 17 | {parse_enable, SP_TOKEN_GLOBAL_STRICT, &(SPCFG(global_strict).enable)}, |
diff --git a/src/sp_config.h b/src/sp_config.h index cddf816..f957d15 100644 --- a/src/sp_config.h +++ b/src/sp_config.h | |||
| @@ -264,6 +264,7 @@ typedef struct { | |||
| 264 | #define SP_TOKEN_ENCRYPTION_KEY "secret_key" | 264 | #define SP_TOKEN_ENCRYPTION_KEY "secret_key" |
| 265 | #define SP_TOKEN_ENV_VAR "cookie_env_var" | 265 | #define SP_TOKEN_ENV_VAR "cookie_env_var" |
| 266 | #define SP_TOKEN_LOG_MEDIA "log_media" | 266 | #define SP_TOKEN_LOG_MEDIA "log_media" |
| 267 | #define SP_TOKEN_LOG_MAX_LEN "log_max_len" | ||
| 267 | #define SP_TOKEN_MAX_EXECUTION_DEPTH "max_execution_depth" | 268 | #define SP_TOKEN_MAX_EXECUTION_DEPTH "max_execution_depth" |
| 268 | #define SP_TOKEN_SERVER_ENCODE "server_encode" | 269 | #define SP_TOKEN_SERVER_ENCODE "server_encode" |
| 269 | #define SP_TOKEN_SERVER_STRIP "server_strip" | 270 | #define SP_TOKEN_SERVER_STRIP "server_strip" |
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index ff834dd..e7ff3e6 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -144,6 +144,7 @@ SP_PARSE_FN(parse_global) { | |||
| 144 | {parse_str, SP_TOKEN_ENCRYPTION_KEY, &(SPCFG(encryption_key))}, | 144 | {parse_str, SP_TOKEN_ENCRYPTION_KEY, &(SPCFG(encryption_key))}, |
| 145 | {parse_str, SP_TOKEN_ENV_VAR, &(SPCFG(cookies_env_var))}, | 145 | {parse_str, SP_TOKEN_ENV_VAR, &(SPCFG(cookies_env_var))}, |
| 146 | {parse_log_media, SP_TOKEN_LOG_MEDIA, &(SPCFG(log_media))}, | 146 | {parse_log_media, SP_TOKEN_LOG_MEDIA, &(SPCFG(log_media))}, |
| 147 | {parse_ulong, SP_TOKEN_LOG_MAX_LEN, &(SPCFG(log_max_len))}, | ||
| 147 | {parse_ulong, SP_TOKEN_MAX_EXECUTION_DEPTH, &(SPCFG(max_execution_depth))}, | 148 | {parse_ulong, SP_TOKEN_MAX_EXECUTION_DEPTH, &(SPCFG(max_execution_depth))}, |
| 148 | {parse_enable, SP_TOKEN_SERVER_ENCODE, &(SPCFG(server_encode))}, | 149 | {parse_enable, SP_TOKEN_SERVER_ENCODE, &(SPCFG(server_encode))}, |
| 149 | {parse_enable, SP_TOKEN_SERVER_STRIP, &(SPCFG(server_strip))}, | 150 | {parse_enable, SP_TOKEN_SERVER_STRIP, &(SPCFG(server_strip))}, |
diff --git a/src/sp_utils.c b/src/sp_utils.c index 3107f77..0fae9ba 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -300,7 +300,7 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, | |||
| 300 | char* char_repr = NULL; | 300 | char* char_repr = NULL; |
| 301 | if (arg_value) { | 301 | if (arg_value) { |
| 302 | char_repr = zend_string_to_char(arg_value); | 302 | char_repr = zend_string_to_char(arg_value); |
| 303 | sp_sanitize_charstring(char_repr, 255); | 303 | sp_sanitize_charstring(char_repr, SPCFG(log_max_len)); |
| 304 | } | 304 | } |
| 305 | if (alias) { | 305 | if (alias) { |
| 306 | sp_log_auto( | 306 | sp_log_auto( |
| @@ -341,7 +341,7 @@ void sp_log_disable_ret(const char* restrict path, | |||
| 341 | } | 341 | } |
| 342 | if (ret_value) { | 342 | if (ret_value) { |
| 343 | char_repr = zend_string_to_char(ret_value); | 343 | char_repr = zend_string_to_char(ret_value); |
| 344 | sp_sanitize_charstring(char_repr, 255); | 344 | sp_sanitize_charstring(char_repr, SPCFG(log_max_len)); |
| 345 | } | 345 | } |
| 346 | if (alias) { | 346 | if (alias) { |
| 347 | sp_log_auto( | 347 | sp_log_auto( |
diff --git a/src/tests/config/phplog_max_len.ini b/src/tests/config/phplog_max_len.ini new file mode 100644 index 0000000..3465d17 --- /dev/null +++ b/src/tests/config/phplog_max_len.ini | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | sp.disable_function.function("ini_set").param("option").value("1234567890abcdefghijklmnopqrstuvwxyz").drop(); | ||
| 2 | sp.log_max_len("16"); | ||
diff --git a/src/tests/phplog_max_len.phpt b/src/tests/phplog_max_len.phpt new file mode 100644 index 0000000..6294f4e --- /dev/null +++ b/src/tests/phplog_max_len.phpt | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | --TEST-- | ||
| 2 | Check the phplog output with a log_max_len | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | <?php if (PHP_VERSION_ID < 80000) print "skip"; ?> | ||
| 6 | --INI-- | ||
| 7 | sp.configuration_file={PWD}/config/phplog_max_len.ini | ||
| 8 | --FILE-- | ||
| 9 | <?php | ||
| 10 | var_dump(ini_set("1234567890abcdefghijklmnopqrstuvwxyz", "value")); | ||
| 11 | ?> | ||
| 12 | --EXPECTF-- | ||
| 13 | Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'ini_set', because its argument '$option' content (1234567890abcdef) matched a rule in %s/tests/phplog_max_len.php on line 2 | ||
| 14 | |||
