diff options
| -rw-r--r-- | src/php_snuffleupagus.h | 6 | ||||
| -rw-r--r-- | src/snuffleupagus.c | 34 | ||||
| -rw-r--r-- | src/sp_crypt.c | 4 | ||||
| -rw-r--r-- | src/sp_disabled_functions.c | 8 | ||||
| -rw-r--r-- | src/sp_execute.c | 5 | ||||
| -rw-r--r-- | src/sp_upload_validation.c | 13 | ||||
| -rw-r--r-- | src/sp_utils.c | 36 | ||||
| -rw-r--r-- | src/tests/broken_configuration/broken_conf_no_file_specified.phpt | 4 | ||||
| -rw-r--r-- | src/tests/loading.phpt | 4 |
9 files changed, 69 insertions, 45 deletions
diff --git a/src/php_snuffleupagus.h b/src/php_snuffleupagus.h index 0849d36..6b0e210 100644 --- a/src/php_snuffleupagus.h +++ b/src/php_snuffleupagus.h | |||
| @@ -62,6 +62,10 @@ typedef void (*zif_handler)(INTERNAL_FUNCTION_PARAMETERS); | |||
| 62 | #define TSRMLS_C | 62 | #define TSRMLS_C |
| 63 | #endif | 63 | #endif |
| 64 | 64 | ||
| 65 | #define SP_CONFIG_VALID 1 | ||
| 66 | #define SP_CONFIG_INVALID 0 | ||
| 67 | #define SP_CONFIG_NONE -1 | ||
| 68 | |||
| 65 | #include "sp_pcre_compat.h" | 69 | #include "sp_pcre_compat.h" |
| 66 | #include "sp_list.h" | 70 | #include "sp_list.h" |
| 67 | #include "sp_tree.h" | 71 | #include "sp_tree.h" |
| @@ -101,7 +105,7 @@ extern zend_module_entry snuffleupagus_module_entry; | |||
| 101 | ZEND_BEGIN_MODULE_GLOBALS(snuffleupagus) | 105 | ZEND_BEGIN_MODULE_GLOBALS(snuffleupagus) |
| 102 | size_t in_eval; | 106 | size_t in_eval; |
| 103 | sp_config config; | 107 | sp_config config; |
| 104 | bool is_config_valid; | 108 | int is_config_valid; // 1 = valid, 0 = invalid, -1 = none |
| 105 | bool allow_broken_configuration; | 109 | bool allow_broken_configuration; |
| 106 | HashTable *disabled_functions_hook; | 110 | HashTable *disabled_functions_hook; |
| 107 | HashTable *sp_internal_functions_hook; | 111 | HashTable *sp_internal_functions_hook; |
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index d62069c..7c69150 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -68,6 +68,7 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { | |||
| 68 | STANDARD_ZEND_EXTENSION_PROPERTIES}; | 68 | STANDARD_ZEND_EXTENSION_PROPERTIES}; |
| 69 | 69 | ||
| 70 | PHP_GINIT_FUNCTION(snuffleupagus) { | 70 | PHP_GINIT_FUNCTION(snuffleupagus) { |
| 71 | snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; | ||
| 71 | snuffleupagus_globals->in_eval = 0; | 72 | snuffleupagus_globals->in_eval = 0; |
| 72 | 73 | ||
| 73 | #define SP_INIT_HT(F) snuffleupagus_globals->F = \ | 74 | #define SP_INIT_HT(F) snuffleupagus_globals->F = \ |
| @@ -186,8 +187,12 @@ PHP_RINIT_FUNCTION(snuffleupagus) { | |||
| 186 | ZEND_TSRMLS_CACHE_UPDATE(); | 187 | ZEND_TSRMLS_CACHE_UPDATE(); |
| 187 | #endif | 188 | #endif |
| 188 | 189 | ||
| 189 | if (!SNUFFLEUPAGUS_G(allow_broken_configuration) && !SNUFFLEUPAGUS_G(is_config_valid)) { | 190 | if (!SNUFFLEUPAGUS_G(allow_broken_configuration)) { |
| 190 | sp_log_err("config", "Invalid configuration file"); | 191 | if (SNUFFLEUPAGUS_G(is_config_valid) == SP_CONFIG_INVALID ) { |
| 192 | sp_log_err("config", "Invalid configuration file"); | ||
| 193 | } else if (SNUFFLEUPAGUS_G(is_config_valid) == SP_CONFIG_NONE) { | ||
| 194 | sp_log_warn("config", "No configuration specificed via sp.configuration_file"); | ||
| 195 | } | ||
| 191 | } | 196 | } |
| 192 | 197 | ||
| 193 | // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. | 198 | // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. |
| @@ -209,12 +214,23 @@ PHP_RINIT_FUNCTION(snuffleupagus) { | |||
| 209 | PHP_RSHUTDOWN_FUNCTION(snuffleupagus) { return SUCCESS; } | 214 | PHP_RSHUTDOWN_FUNCTION(snuffleupagus) { return SUCCESS; } |
| 210 | 215 | ||
| 211 | PHP_MINFO_FUNCTION(snuffleupagus) { | 216 | PHP_MINFO_FUNCTION(snuffleupagus) { |
| 217 | const char *valid_config; | ||
| 218 | switch(SNUFFLEUPAGUS_G(is_config_valid)) { | ||
| 219 | case SP_CONFIG_VALID: | ||
| 220 | valid_config = "yes"; | ||
| 221 | break; | ||
| 222 | case SP_CONFIG_INVALID: | ||
| 223 | valid_config = "invalid"; | ||
| 224 | break; | ||
| 225 | case SP_CONFIG_NONE: | ||
| 226 | default: | ||
| 227 | valid_config = "no"; | ||
| 228 | } | ||
| 212 | php_info_print_table_start(); | 229 | php_info_print_table_start(); |
| 213 | php_info_print_table_row(2, "snuffleupagus support", "enabled"); | 230 | php_info_print_table_row(2, "snuffleupagus support", |
| 231 | SNUFFLEUPAGUS_G(is_config_valid)?"enabled":"disabled"); | ||
| 214 | php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); | 232 | php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); |
| 215 | php_info_print_table_row( | 233 | php_info_print_table_row( 2, "Valid config", valid_config); |
| 216 | 2, "Valid config", | ||
| 217 | (SNUFFLEUPAGUS_G(is_config_valid) == true) ? "yes" : "no"); | ||
| 218 | php_info_print_table_end(); | 234 | php_info_print_table_end(); |
| 219 | DISPLAY_INI_ENTRIES(); | 235 | DISPLAY_INI_ENTRIES(); |
| 220 | } | 236 | } |
| @@ -234,14 +250,14 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 234 | int ret = glob(config_file, GLOB_NOCHECK, NULL, &globbuf); | 250 | int ret = glob(config_file, GLOB_NOCHECK, NULL, &globbuf); |
| 235 | 251 | ||
| 236 | if (ret != 0) { | 252 | if (ret != 0) { |
| 237 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 253 | SNUFFLEUPAGUS_G(is_config_valid) = SP_CONFIG_INVALID; |
| 238 | globfree(&globbuf); | 254 | globfree(&globbuf); |
| 239 | return FAILURE; | 255 | return FAILURE; |
| 240 | } | 256 | } |
| 241 | 257 | ||
| 242 | for (size_t i = 0; globbuf.gl_pathv[i]; i++) { | 258 | for (size_t i = 0; globbuf.gl_pathv[i]; i++) { |
| 243 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { | 259 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { |
| 244 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 260 | SNUFFLEUPAGUS_G(is_config_valid) = SP_CONFIG_INVALID; |
| 245 | globfree(&globbuf); | 261 | globfree(&globbuf); |
| 246 | return FAILURE; | 262 | return FAILURE; |
| 247 | } | 263 | } |
| @@ -249,7 +265,7 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 249 | globfree(&globbuf); | 265 | globfree(&globbuf); |
| 250 | } | 266 | } |
| 251 | 267 | ||
| 252 | SNUFFLEUPAGUS_G(is_config_valid) = true; | 268 | SNUFFLEUPAGUS_G(is_config_valid) = SP_CONFIG_VALID; |
| 253 | 269 | ||
| 254 | if ((SNUFFLEUPAGUS_G(config).config_sloppy->enable)) { | 270 | if ((SNUFFLEUPAGUS_G(config).config_sloppy->enable)) { |
| 255 | hook_sloppy(); | 271 | hook_sloppy(); |
diff --git a/src/sp_crypt.c b/src/sp_crypt.c index b353ebe..c57ac0b 100644 --- a/src/sp_crypt.c +++ b/src/sp_crypt.c | |||
| @@ -108,8 +108,8 @@ int decrypt_zval(zval *pDest, bool simulation, zend_hash_key *hash_key) { | |||
| 108 | return ZEND_HASH_APPLY_KEEP; | 108 | return ZEND_HASH_APPLY_KEEP; |
| 109 | } else { | 109 | } else { |
| 110 | sp_log_warn("cookie_encryption", | 110 | sp_log_warn("cookie_encryption", |
| 111 | "Something went wrong with the decryption of %s", | 111 | "Something went wrong with the decryption of %s", |
| 112 | hash_key ? ZSTR_VAL(hash_key->key) : "the session"); | 112 | hash_key ? ZSTR_VAL(hash_key->key) : "the session"); |
| 113 | efree(backup); | 113 | efree(backup); |
| 114 | return ZEND_HASH_APPLY_REMOVE; | 114 | return ZEND_HASH_APPLY_REMOVE; |
| 115 | } | 115 | } |
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index a7136df..7be1c34 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -575,12 +575,12 @@ ZEND_FUNCTION(eval_blacklist_callback) { | |||
| 575 | } | 575 | } |
| 576 | if (config_eval->simulation) { | 576 | if (config_eval->simulation) { |
| 577 | sp_log_simulation("eval", | 577 | sp_log_simulation("eval", |
| 578 | "A call to %s was tried in eval, in %s:%d, logging it.", | 578 | "A call to %s was tried in eval, in %s:%d, logging it.", |
| 579 | current_function_name, ZSTR_VAL(filename), line_number); | 579 | current_function_name, ZSTR_VAL(filename), line_number); |
| 580 | } else { | 580 | } else { |
| 581 | sp_log_drop("eval", | 581 | sp_log_drop("eval", |
| 582 | "A call to %s was tried in eval, in %s:%d, dropping it.", | 582 | "A call to %s was tried in eval, in %s:%d, dropping it.", |
| 583 | current_function_name, ZSTR_VAL(filename), line_number); | 583 | current_function_name, ZSTR_VAL(filename), line_number); |
| 584 | } | 584 | } |
| 585 | efree(filename); | 585 | efree(filename); |
| 586 | } | 586 | } |
diff --git a/src/sp_execute.c b/src/sp_execute.c index 73cc560..140e227 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c | |||
| @@ -19,10 +19,11 @@ ZEND_COLD static inline void terminate_if_writable(const char *filename) { | |||
| 19 | } | 19 | } |
| 20 | if (true == config_ro_exec->simulation) { | 20 | if (true == config_ro_exec->simulation) { |
| 21 | sp_log_simulation("readonly_exec", | 21 | sp_log_simulation("readonly_exec", |
| 22 | "Attempted execution of a writable file (%s).", filename); | 22 | "Attempted execution of a writable file (%s).", |
| 23 | filename); | ||
| 23 | } else { | 24 | } else { |
| 24 | sp_log_drop("readonly_exec", | 25 | sp_log_drop("readonly_exec", |
| 25 | "Attempted execution of a writable file (%s).", filename); | 26 | "Attempted execution of a writable file (%s).", filename); |
| 26 | zend_bailout(); | 27 | zend_bailout(); |
| 27 | } | 28 | } |
| 28 | } else { | 29 | } else { |
diff --git a/src/sp_upload_validation.c b/src/sp_upload_validation.c index 4ee7bd7..f3ae311 100644 --- a/src/sp_upload_validation.c +++ b/src/sp_upload_validation.c | |||
| @@ -13,10 +13,11 @@ int sp_rfc1867_callback(unsigned int event, void *event_data, void **extra); | |||
| 13 | 13 | ||
| 14 | int sp_rfc1867_callback_win(unsigned int event, void *event_data, | 14 | int sp_rfc1867_callback_win(unsigned int event, void *event_data, |
| 15 | void **extra) { | 15 | void **extra) { |
| 16 | sp_log_simulation("upload_validation", | 16 | sp_log_simulation( |
| 17 | "The upload validation doesn't work for now on Windows yet, " | 17 | "upload_validation", |
| 18 | "see https://github.com/jvoisin/snuffleupagus/issues/248 for " | 18 | "The upload validation doesn't work for now on Windows yet, " |
| 19 | "details."); | 19 | "see https://github.com/jvoisin/snuffleupagus/issues/248 for " |
| 20 | "details."); | ||
| 20 | return SUCCESS; | 21 | return SUCCESS; |
| 21 | } | 22 | } |
| 22 | 23 | ||
| @@ -91,8 +92,8 @@ int sp_rfc1867_callback(unsigned int event, void *event_data, void **extra) { | |||
| 91 | char *uri = getenv("REQUEST_URI"); | 92 | char *uri = getenv("REQUEST_URI"); |
| 92 | int sim = config_upload->simulation; | 93 | int sim = config_upload->simulation; |
| 93 | sp_log_auto("upload_validation", sim, | 94 | sp_log_auto("upload_validation", sim, |
| 94 | "The upload of %s on %s was rejected.", | 95 | "The upload of %s on %s was rejected.", filename, |
| 95 | filename, uri ? uri : "?"); | 96 | uri ? uri : "?"); |
| 96 | } | 97 | } |
| 97 | } | 98 | } |
| 98 | ZEND_HASH_FOREACH_END(); | 99 | ZEND_HASH_FOREACH_END(); |
diff --git a/src/sp_utils.c b/src/sp_utils.c index 8032e0a..4c78ce5 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -41,7 +41,7 @@ const char* get_ipaddr() { | |||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | void sp_log_msgf(char const* restrict feature, int level, int type, | 43 | void sp_log_msgf(char const* restrict feature, int level, int type, |
| 44 | const char* restrict fmt, ...) { | 44 | const char* restrict fmt, ...) { |
| 45 | char* msg; | 45 | char* msg; |
| 46 | va_list args; | 46 | va_list args; |
| 47 | 47 | ||
| @@ -51,7 +51,7 @@ void sp_log_msgf(char const* restrict feature, int level, int type, | |||
| 51 | 51 | ||
| 52 | const char* client_ip = get_ipaddr(); | 52 | const char* client_ip = get_ipaddr(); |
| 53 | const char* logtype = NULL; | 53 | const char* logtype = NULL; |
| 54 | switch(type) { | 54 | switch (type) { |
| 55 | case SP_TYPE_SIMULATION: | 55 | case SP_TYPE_SIMULATION: |
| 56 | logtype = "simulation"; | 56 | logtype = "simulation"; |
| 57 | break; | 57 | break; |
| @@ -80,7 +80,8 @@ void sp_log_msgf(char const* restrict feature, int level, int type, | |||
| 80 | } | 80 | } |
| 81 | case SP_ZEND: | 81 | case SP_ZEND: |
| 82 | default: | 82 | default: |
| 83 | zend_error(level, "[snuffleupagus][%s][%s][%s] %s", client_ip, feature, logtype, msg); | 83 | zend_error(level, "[snuffleupagus][%s][%s][%s] %s", client_ip, feature, |
| 84 | logtype, msg); | ||
| 84 | break; | 85 | break; |
| 85 | } | 86 | } |
| 86 | } | 87 | } |
| @@ -280,26 +281,27 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, | |||
| 280 | char_repr = zend_string_to_char(arg_value); | 281 | char_repr = zend_string_to_char(arg_value); |
| 281 | } | 282 | } |
| 282 | if (alias) { | 283 | if (alias) { |
| 283 | sp_log_auto("disabled_function", sim, | 284 | sp_log_auto( |
| 284 | "Aborted execution on call of the function '%s', " | 285 | "disabled_function", sim, |
| 285 | "because its argument '%s' content (%s) matched the rule '%s'", | 286 | "Aborted execution on call of the function '%s', " |
| 286 | path, arg_name, char_repr ? char_repr : "?", ZSTR_VAL(alias)); | 287 | "because its argument '%s' content (%s) matched the rule '%s'", |
| 288 | path, arg_name, char_repr ? char_repr : "?", ZSTR_VAL(alias)); | ||
| 287 | } else { | 289 | } else { |
| 288 | sp_log_auto("disabled_function", sim, | 290 | sp_log_auto("disabled_function", sim, |
| 289 | "Aborted execution on call of the function '%s', " | 291 | "Aborted execution on call of the function '%s', " |
| 290 | "because its argument '%s' content (%s) matched a rule", | 292 | "because its argument '%s' content (%s) matched a rule", |
| 291 | path, arg_name, char_repr ? char_repr : "?"); | 293 | path, arg_name, char_repr ? char_repr : "?"); |
| 292 | } | 294 | } |
| 293 | efree(char_repr); | 295 | efree(char_repr); |
| 294 | } else { | 296 | } else { |
| 295 | if (alias) { | 297 | if (alias) { |
| 296 | sp_log_auto("disabled_function", sim, | 298 | sp_log_auto("disabled_function", sim, |
| 297 | "Aborted execution on call of the function '%s', " | 299 | "Aborted execution on call of the function '%s', " |
| 298 | "because of the the rule '%s'", | 300 | "because of the the rule '%s'", |
| 299 | path, ZSTR_VAL(alias)); | 301 | path, ZSTR_VAL(alias)); |
| 300 | } else { | 302 | } else { |
| 301 | sp_log_auto("disabled_function", sim, | 303 | sp_log_auto("disabled_function", sim, |
| 302 | "Aborted execution on call of the function '%s'", path); | 304 | "Aborted execution on call of the function '%s'", path); |
| 303 | } | 305 | } |
| 304 | } | 306 | } |
| 305 | } | 307 | } |
| @@ -327,9 +329,9 @@ void sp_log_disable_ret(const char* restrict path, | |||
| 327 | path, char_repr ? char_repr : "?", ZSTR_VAL(alias)); | 329 | path, char_repr ? char_repr : "?", ZSTR_VAL(alias)); |
| 328 | } else { | 330 | } else { |
| 329 | sp_log_auto("disabled_function", sim, | 331 | sp_log_auto("disabled_function", sim, |
| 330 | "Aborted execution on return of the function '%s', " | 332 | "Aborted execution on return of the function '%s', " |
| 331 | "because the function returned '%s', which matched a rule", | 333 | "because the function returned '%s', which matched a rule", |
| 332 | path, char_repr ? char_repr : "?"); | 334 | path, char_repr ? char_repr : "?"); |
| 333 | } | 335 | } |
| 334 | efree(char_repr); | 336 | efree(char_repr); |
| 335 | } | 337 | } |
diff --git a/src/tests/broken_configuration/broken_conf_no_file_specified.phpt b/src/tests/broken_configuration/broken_conf_no_file_specified.phpt index 8b360d4..cb2d95f 100644 --- a/src/tests/broken_configuration/broken_conf_no_file_specified.phpt +++ b/src/tests/broken_configuration/broken_conf_no_file_specified.phpt | |||
| @@ -6,5 +6,5 @@ Broken configuration - No configuration file specified | |||
| 6 | --FILE-- | 6 | --FILE-- |
| 7 | <?php echo "1\n"; ?> | 7 | <?php echo "1\n"; ?> |
| 8 | --EXPECT-- | 8 | --EXPECT-- |
| 9 | Fatal error: [snuffleupagus][0.0.0.0][config][log] Invalid configuration file in Unknown on line 0 | 9 | Warning: [snuffleupagus][0.0.0.0][config][log] No configuration specificed via sp.configuration_file in Unknown on line 0 |
| 10 | Could not startup. | 10 | 1 |
diff --git a/src/tests/loading.phpt b/src/tests/loading.phpt index 761917a..2514ec5 100644 --- a/src/tests/loading.phpt +++ b/src/tests/loading.phpt | |||
| @@ -7,5 +7,5 @@ Check for snuffleupagus presence | |||
| 7 | echo "snuffleupagus extension is available"; | 7 | echo "snuffleupagus extension is available"; |
| 8 | ?> | 8 | ?> |
| 9 | --EXPECT-- | 9 | --EXPECT-- |
| 10 | Fatal error: [snuffleupagus][0.0.0.0][config][log] Invalid configuration file in Unknown on line 0 | 10 | Warning: [snuffleupagus][0.0.0.0][config][log] No configuration specificed via sp.configuration_file in Unknown on line 0 |
| 11 | Could not startup. | 11 | snuffleupagus extension is available |
