summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/config.rst10
-rw-r--r--src/php_snuffleupagus.h1
-rw-r--r--src/snuffleupagus.c2
-rw-r--r--src/sp_config.c1
-rw-r--r--src/sp_config.h1
-rw-r--r--src/sp_config_keywords.c1
-rw-r--r--src/sp_utils.c4
-rw-r--r--src/tests/config/phplog_max_len.ini2
-rw-r--r--src/tests/phplog_max_len.phpt14
9 files changed, 34 insertions, 2 deletions
diff --git a/doc/source/config.rst b/doc/source/config.rst
index bce4667..2c5fc96 100644
--- a/doc/source/config.rst
+++ b/doc/source/config.rst
@@ -151,6 +151,16 @@ it's `possible to modify php's logging system via php
151<https://www.php.net/manual/en/errorfunc.configuration.php>`__, it's 151<https://www.php.net/manual/en/errorfunc.configuration.php>`__, it's
152heavily recommended to use the ``syslog`` option instead. 152heavily recommended to use the ``syslog`` option instead.
153 153
154log_max_len
155^^^^^^^^^^^
156
157This configuration variable allows to specify (roughly) the size of the log.
158
159::
160
161 sp.log_max_len("16");
162
163The default value for ``sp.log_max_len`` is ``255``.
154 164
155Bugclass-killer features 165Bugclass-killer features
156------------------------ 166------------------------
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;
131sp_config_session config_session; 131sp_config_session config_session;
132sp_config_ini config_ini; 132sp_config_ini config_ini;
133char config_log_media; 133char config_log_media;
134int config_log_max_len;
134u_long config_max_execution_depth; 135u_long config_max_execution_depth;
135bool config_server_encode; 136bool config_server_encode;
136bool config_server_strip; 137bool 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 @@
1sp.disable_function.function("ini_set").param("option").value("1234567890abcdefghijklmnopqrstuvwxyz").drop();
2sp.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--
2Check 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--
7sp.configuration_file={PWD}/config/phplog_max_len.ini
8--FILE--
9<?php
10var_dump(ini_set("1234567890abcdefghijklmnopqrstuvwxyz", "value"));
11?>
12--EXPECTF--
13Fatal 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