From b3f67a16094168cc334f5da93a86f09476e01601 Mon Sep 17 00:00:00 2001 From: xXx-caillou-xXx Date: Thu, 30 Aug 2018 15:02:22 +0200 Subject: Change how we're handling invalid configurations Since our configuration format is a bit more complex than php's one, we have a `sp.allow_broken_configuration` parameter (`false` by default), that you can set to `true` if you want PHP to carry on if your Snuffleupagus' configuration contains syntax errors. You'll still get a big scary message in your logs of course. We do **not** recommend to use it of course, but sometimes it might be useful to be able to "debug in production" without breaking your website.--- src/snuffleupagus.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/snuffleupagus.c') diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 5ef8323..4fee81a 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c @@ -34,9 +34,21 @@ static inline void sp_op_array_handler(zend_op_array *op) { ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) +static PHP_INI_MH(StrictMode) { + TSRMLS_FETCH(); + + SNUFFLEUPAGUS_G(allow_broken_configuration) = false; + if (new_value && zend_string_equals_literal(new_value, "1")) { + SNUFFLEUPAGUS_G(allow_broken_configuration) = true; + } + return SUCCESS; +} + PHP_INI_BEGIN() PHP_INI_ENTRY("sp.configuration_file", "", PHP_INI_SYSTEM, OnUpdateConfiguration) +PHP_INI_ENTRY("sp.allow_broken_configuration", "0", PHP_INI_SYSTEM, + StrictMode) PHP_INI_END() void free_disabled_functions_hashtable(HashTable *ht) { @@ -181,6 +193,10 @@ PHP_RINIT_FUNCTION(snuffleupagus) { ZEND_TSRMLS_CACHE_UPDATE(); #endif + if (!SNUFFLEUPAGUS_G(allow_broken_configuration) && !SNUFFLEUPAGUS_G(is_config_valid)) { + sp_log_err("config", "Invalid configuration file"); + } + // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. if (SNUFFLEUPAGUS_G(config).config_wrapper->enabled && zend_hash_num_elements(php_stream_get_url_stream_wrappers_hash()) != -- cgit v1.3