diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/snuffleupagus.c | 196 | ||||
| -rw-r--r-- | src/sp_config.c | 3 | ||||
| -rw-r--r-- | src/sp_config_keywords.c | 2 | ||||
| -rw-r--r-- | src/sp_cookie_encryption.c | 4 | ||||
| -rw-r--r-- | src/sp_crypt.c | 3 | ||||
| -rw-r--r-- | src/sp_disabled_functions.c | 10 | ||||
| -rw-r--r-- | src/sp_execute.c | 81 | ||||
| -rw-r--r-- | src/sp_harden_rand.c | 4 | ||||
| -rw-r--r-- | src/sp_session.c | 9 | ||||
| -rw-r--r-- | src/sp_unserialize.c | 20 | ||||
| -rw-r--r-- | src/sp_upload_validation.c | 28 | ||||
| -rw-r--r-- | src/sp_utils.c | 15 |
12 files changed, 186 insertions, 189 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 4fee81a..0126a37 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -51,12 +51,6 @@ PHP_INI_ENTRY("sp.allow_broken_configuration", "0", PHP_INI_SYSTEM, | |||
| 51 | StrictMode) | 51 | StrictMode) |
| 52 | PHP_INI_END() | 52 | PHP_INI_END() |
| 53 | 53 | ||
| 54 | void free_disabled_functions_hashtable(HashTable *ht) { | ||
| 55 | void *ptr = NULL; | ||
| 56 | ZEND_HASH_FOREACH_PTR(ht, ptr) { sp_list_free(ptr); } | ||
| 57 | ZEND_HASH_FOREACH_END(); | ||
| 58 | } | ||
| 59 | |||
| 60 | ZEND_DLEXPORT zend_extension zend_extension_entry = { | 54 | ZEND_DLEXPORT zend_extension zend_extension_entry = { |
| 61 | PHP_SNUFFLEUPAGUS_EXTNAME, | 55 | PHP_SNUFFLEUPAGUS_EXTNAME, |
| 62 | PHP_SNUFFLEUPAGUS_VERSION, | 56 | PHP_SNUFFLEUPAGUS_VERSION, |
| @@ -79,47 +73,45 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { | |||
| 79 | PHP_GINIT_FUNCTION(snuffleupagus) { | 73 | PHP_GINIT_FUNCTION(snuffleupagus) { |
| 80 | snuffleupagus_globals->in_eval = 0; | 74 | snuffleupagus_globals->in_eval = 0; |
| 81 | 75 | ||
| 82 | #define SP_INIT(F) F = pecalloc(sizeof(*F), 1, 1); | 76 | #define SP_INIT_HT(F) snuffleupagus_globals->F = \ |
| 83 | #define SP_INIT_HT(F) \ | 77 | pemalloc(sizeof(*(snuffleupagus_globals->F)), 1); \ |
| 84 | F = pemalloc(sizeof(*F), 1); \ | 78 | zend_hash_init(snuffleupagus_globals->F, 10, NULL, NULL, 1); |
| 85 | zend_hash_init(F, 10, NULL, NULL, 1); | 79 | SP_INIT_HT(disabled_functions_hook); |
| 86 | 80 | SP_INIT_HT(sp_internal_functions_hook); | |
| 87 | SP_INIT_HT(snuffleupagus_globals->disabled_functions_hook); | 81 | SP_INIT_HT(sp_eval_blacklist_functions_hook); |
| 88 | SP_INIT_HT(snuffleupagus_globals->sp_internal_functions_hook); | 82 | SP_INIT_HT(config.config_disabled_functions); |
| 89 | SP_INIT_HT(snuffleupagus_globals->sp_eval_blacklist_functions_hook); | 83 | SP_INIT_HT(config.config_disabled_functions_hooked); |
| 90 | SP_INIT_HT(snuffleupagus_globals->config.config_disabled_functions); | 84 | SP_INIT_HT(config.config_disabled_functions_ret); |
| 91 | SP_INIT_HT(snuffleupagus_globals->config.config_disabled_functions_hooked); | 85 | SP_INIT_HT(config.config_disabled_functions_ret_hooked); |
| 92 | SP_INIT_HT(snuffleupagus_globals->config.config_disabled_functions_ret); | 86 | #undef SP_INIT_HT |
| 93 | SP_INIT_HT( | ||
| 94 | snuffleupagus_globals->config.config_disabled_functions_ret_hooked); | ||
| 95 | |||
| 96 | SP_INIT(snuffleupagus_globals->config.config_unserialize); | ||
| 97 | SP_INIT(snuffleupagus_globals->config.config_random); | ||
| 98 | SP_INIT(snuffleupagus_globals->config.config_sloppy); | ||
| 99 | SP_INIT(snuffleupagus_globals->config.config_readonly_exec); | ||
| 100 | SP_INIT(snuffleupagus_globals->config.config_global_strict); | ||
| 101 | SP_INIT(snuffleupagus_globals->config.config_auto_cookie_secure); | ||
| 102 | SP_INIT(snuffleupagus_globals->config.config_snuffleupagus); | ||
| 103 | SP_INIT(snuffleupagus_globals->config.config_disable_xxe); | ||
| 104 | SP_INIT(snuffleupagus_globals->config.config_upload_validation); | ||
| 105 | SP_INIT(snuffleupagus_globals->config.config_disabled_functions_reg); | ||
| 106 | SP_INIT(snuffleupagus_globals->config.config_disabled_functions_reg_ret); | ||
| 107 | SP_INIT(snuffleupagus_globals->config.config_cookie); | ||
| 108 | SP_INIT(snuffleupagus_globals->config.config_session); | ||
| 109 | SP_INIT(snuffleupagus_globals->config.config_eval); | ||
| 110 | SP_INIT(snuffleupagus_globals->config.config_wrapper); | ||
| 111 | |||
| 112 | snuffleupagus_globals->config.config_disabled_functions_reg | ||
| 113 | ->disabled_functions = NULL; | ||
| 114 | snuffleupagus_globals->config.config_disabled_functions_reg_ret | ||
| 115 | ->disabled_functions = NULL; | ||
| 116 | snuffleupagus_globals->config.config_cookie->cookies = NULL; | ||
| 117 | snuffleupagus_globals->config.config_eval->blacklist = NULL; | ||
| 118 | snuffleupagus_globals->config.config_eval->whitelist = NULL; | ||
| 119 | snuffleupagus_globals->config.config_wrapper->whitelist = NULL; | ||
| 120 | 87 | ||
| 88 | #define SP_INIT(F) snuffleupagus_globals->config.F = \ | ||
| 89 | pecalloc(sizeof(*(snuffleupagus_globals->config.F)), 1, 1); | ||
| 90 | SP_INIT(config_unserialize); | ||
| 91 | SP_INIT(config_random); | ||
| 92 | SP_INIT(config_sloppy); | ||
| 93 | SP_INIT(config_readonly_exec); | ||
| 94 | SP_INIT(config_global_strict); | ||
| 95 | SP_INIT(config_auto_cookie_secure); | ||
| 96 | SP_INIT(config_snuffleupagus); | ||
| 97 | SP_INIT(config_disable_xxe); | ||
| 98 | SP_INIT(config_upload_validation); | ||
| 99 | SP_INIT(config_disabled_functions_reg); | ||
| 100 | SP_INIT(config_disabled_functions_reg_ret); | ||
| 101 | SP_INIT(config_cookie); | ||
| 102 | SP_INIT(config_session); | ||
| 103 | SP_INIT(config_eval); | ||
| 104 | SP_INIT(config_wrapper); | ||
| 121 | #undef SP_INIT | 105 | #undef SP_INIT |
| 122 | #undef SP_INIT_HT | 106 | |
| 107 | #define SP_INIT_NULL(F) snuffleupagus_globals->config.F = NULL; | ||
| 108 | SP_INIT_NULL(config_disabled_functions_reg->disabled_functions); | ||
| 109 | SP_INIT_NULL(config_disabled_functions_reg_ret->disabled_functions); | ||
| 110 | SP_INIT_NULL(config_cookie->cookies); | ||
| 111 | SP_INIT_NULL(config_eval->blacklist); | ||
| 112 | SP_INIT_NULL(config_eval->whitelist); | ||
| 113 | SP_INIT_NULL(config_wrapper->whitelist); | ||
| 114 | #undef SP_INIT_NULL | ||
| 123 | } | 115 | } |
| 124 | 116 | ||
| 125 | PHP_MINIT_FUNCTION(snuffleupagus) { | 117 | PHP_MINIT_FUNCTION(snuffleupagus) { |
| @@ -128,60 +120,62 @@ PHP_MINIT_FUNCTION(snuffleupagus) { | |||
| 128 | return SUCCESS; | 120 | return SUCCESS; |
| 129 | } | 121 | } |
| 130 | 122 | ||
| 123 | static void free_disabled_functions_hashtable(HashTable *ht) { | ||
| 124 | void *ptr = NULL; | ||
| 125 | ZEND_HASH_FOREACH_PTR(ht, ptr) { sp_list_free(ptr); } | ||
| 126 | ZEND_HASH_FOREACH_END(); | ||
| 127 | } | ||
| 128 | |||
| 131 | PHP_MSHUTDOWN_FUNCTION(snuffleupagus) { | 129 | PHP_MSHUTDOWN_FUNCTION(snuffleupagus) { |
| 132 | free_disabled_functions_hashtable( | ||
| 133 | SNUFFLEUPAGUS_G(config).config_disabled_functions); | ||
| 134 | free_disabled_functions_hashtable( | ||
| 135 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 136 | free_disabled_functions_hashtable( | ||
| 137 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret); | ||
| 138 | free_disabled_functions_hashtable( | ||
| 139 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked); | ||
| 140 | 130 | ||
| 141 | #define FREE_HT(F) \ | 131 | #define FREE_HT(F) \ |
| 142 | zend_hash_destroy(SNUFFLEUPAGUS_G(F)); \ | 132 | zend_hash_destroy(SNUFFLEUPAGUS_G(F)); \ |
| 143 | pefree(SNUFFLEUPAGUS_G(F), 1); | 133 | pefree(SNUFFLEUPAGUS_G(F), 1); |
| 144 | |||
| 145 | FREE_HT(disabled_functions_hook); | 134 | FREE_HT(disabled_functions_hook); |
| 146 | FREE_HT(sp_eval_blacklist_functions_hook); | 135 | FREE_HT(sp_eval_blacklist_functions_hook); |
| 147 | FREE_HT(config.config_disabled_functions); | ||
| 148 | FREE_HT(config.config_disabled_functions_hooked); | ||
| 149 | FREE_HT(config.config_disabled_functions_ret); | ||
| 150 | FREE_HT(config.config_disabled_functions_ret_hooked); | ||
| 151 | 136 | ||
| 137 | #define FREE_HT_LIST(F) \ | ||
| 138 | free_disabled_functions_hashtable(SNUFFLEUPAGUS_G(config).F); \ | ||
| 139 | FREE_HT(config.F); | ||
| 140 | FREE_HT_LIST(config_disabled_functions); | ||
| 141 | FREE_HT_LIST(config_disabled_functions_hooked); | ||
| 142 | FREE_HT_LIST(config_disabled_functions_ret); | ||
| 143 | FREE_HT_LIST(config_disabled_functions_ret_hooked); | ||
| 144 | #undef FREE_HT_LIST | ||
| 152 | #undef FREE_HT | 145 | #undef FREE_HT |
| 153 | 146 | ||
| 154 | pefree(SNUFFLEUPAGUS_G(config.config_unserialize), 1); | ||
| 155 | pefree(SNUFFLEUPAGUS_G(config.config_random), 1); | ||
| 156 | pefree(SNUFFLEUPAGUS_G(config.config_readonly_exec), 1); | ||
| 157 | pefree(SNUFFLEUPAGUS_G(config.config_global_strict), 1); | ||
| 158 | pefree(SNUFFLEUPAGUS_G(config.config_auto_cookie_secure), 1); | ||
| 159 | pefree(SNUFFLEUPAGUS_G(config.config_snuffleupagus), 1); | ||
| 160 | pefree(SNUFFLEUPAGUS_G(config.config_disable_xxe), 1); | ||
| 161 | pefree(SNUFFLEUPAGUS_G(config.config_upload_validation), 1); | ||
| 162 | pefree(SNUFFLEUPAGUS_G(config.config_session), 1); | ||
| 163 | |||
| 164 | #define FREE_LST_DISABLE(L) \ | 147 | #define FREE_LST_DISABLE(L) \ |
| 165 | do { \ | 148 | do { \ |
| 166 | sp_list_node *_n = SNUFFLEUPAGUS_G(L); \ | 149 | sp_list_node *_n = SNUFFLEUPAGUS_G(config).L; \ |
| 167 | sp_disabled_function_list_free(_n); \ | 150 | sp_disabled_function_list_free(_n); \ |
| 168 | sp_list_free(_n); \ | 151 | sp_list_free(_n); \ |
| 169 | } while (0) | 152 | } while (0) |
| 170 | 153 | FREE_LST_DISABLE(config_disabled_functions_reg->disabled_functions); | |
| 171 | FREE_LST_DISABLE(config.config_disabled_functions_reg->disabled_functions); | 154 | FREE_LST_DISABLE(config_disabled_functions_reg_ret->disabled_functions); |
| 172 | FREE_LST_DISABLE( | ||
| 173 | config.config_disabled_functions_reg_ret->disabled_functions); | ||
| 174 | sp_list_free(SNUFFLEUPAGUS_G(config).config_cookie->cookies); | ||
| 175 | sp_list_free(SNUFFLEUPAGUS_G(config).config_eval->blacklist); | ||
| 176 | sp_list_free(SNUFFLEUPAGUS_G(config).config_eval->whitelist); | ||
| 177 | sp_list_free(SNUFFLEUPAGUS_G(config).config_wrapper->whitelist); | ||
| 178 | |||
| 179 | #undef FREE_LST_DISABLE | 155 | #undef FREE_LST_DISABLE |
| 180 | 156 | ||
| 181 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions_reg), 1); | 157 | #define FREE_LST(L) sp_list_free(SNUFFLEUPAGUS_G(config).L); |
| 182 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions_reg_ret), 1); | 158 | FREE_LST(config_cookie->cookies); |
| 183 | pefree(SNUFFLEUPAGUS_G(config.config_cookie), 1); | 159 | FREE_LST(config_eval->blacklist); |
| 184 | pefree(SNUFFLEUPAGUS_G(config.config_wrapper), 1); | 160 | FREE_LST(config_eval->whitelist); |
| 161 | FREE_LST(config_wrapper->whitelist); | ||
| 162 | #undef FREE_LST | ||
| 163 | |||
| 164 | #define FREE_CFG(C) pefree(SNUFFLEUPAGUS_G(config).C, 1); | ||
| 165 | FREE_CFG(config_unserialize); | ||
| 166 | FREE_CFG(config_random); | ||
| 167 | FREE_CFG(config_readonly_exec); | ||
| 168 | FREE_CFG(config_global_strict); | ||
| 169 | FREE_CFG(config_auto_cookie_secure); | ||
| 170 | FREE_CFG(config_snuffleupagus); | ||
| 171 | FREE_CFG(config_disable_xxe); | ||
| 172 | FREE_CFG(config_upload_validation); | ||
| 173 | FREE_CFG(config_session); | ||
| 174 | FREE_CFG(config_disabled_functions_reg); | ||
| 175 | FREE_CFG(config_disabled_functions_reg_ret); | ||
| 176 | FREE_CFG(config_cookie); | ||
| 177 | FREE_CFG(config_wrapper); | ||
| 178 | #undef FREE_CFG | ||
| 185 | 179 | ||
| 186 | UNREGISTER_INI_ENTRIES(); | 180 | UNREGISTER_INI_ENTRIES(); |
| 187 | 181 | ||
| @@ -189,6 +183,8 @@ PHP_MSHUTDOWN_FUNCTION(snuffleupagus) { | |||
| 189 | } | 183 | } |
| 190 | 184 | ||
| 191 | PHP_RINIT_FUNCTION(snuffleupagus) { | 185 | PHP_RINIT_FUNCTION(snuffleupagus) { |
| 186 | const sp_config_wrapper* config_wrapper = | ||
| 187 | SNUFFLEUPAGUS_G(config).config_wrapper; | ||
| 192 | #if defined(COMPILE_DL_SNUFFLEUPAGUS) && defined(ZTS) | 188 | #if defined(COMPILE_DL_SNUFFLEUPAGUS) && defined(ZTS) |
| 193 | ZEND_TSRMLS_CACHE_UPDATE(); | 189 | ZEND_TSRMLS_CACHE_UPDATE(); |
| 194 | #endif | 190 | #endif |
| @@ -198,9 +194,9 @@ PHP_RINIT_FUNCTION(snuffleupagus) { | |||
| 198 | } | 194 | } |
| 199 | 195 | ||
| 200 | // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. | 196 | // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. |
| 201 | if (SNUFFLEUPAGUS_G(config).config_wrapper->enabled && | 197 | if (config_wrapper->enabled && |
| 202 | zend_hash_num_elements(php_stream_get_url_stream_wrappers_hash()) != | 198 | zend_hash_num_elements(php_stream_get_url_stream_wrappers_hash()) != |
| 203 | SNUFFLEUPAGUS_G(config).config_wrapper->num_wrapper) { | 199 | config_wrapper->num_wrapper) { |
| 204 | sp_disable_wrapper(); | 200 | sp_disable_wrapper(); |
| 205 | } | 201 | } |
| 206 | 202 | ||
| @@ -265,28 +261,32 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 265 | if (SNUFFLEUPAGUS_G(config).config_random->enable) { | 261 | if (SNUFFLEUPAGUS_G(config).config_random->enable) { |
| 266 | hook_rand(); | 262 | hook_rand(); |
| 267 | } | 263 | } |
| 264 | |||
| 268 | if (SNUFFLEUPAGUS_G(config).config_upload_validation->enable) { | 265 | if (SNUFFLEUPAGUS_G(config).config_upload_validation->enable) { |
| 269 | hook_upload(); | 266 | hook_upload(); |
| 270 | } | 267 | } |
| 268 | |||
| 271 | if (SNUFFLEUPAGUS_G(config).config_disable_xxe->enable == 0) { | 269 | if (SNUFFLEUPAGUS_G(config).config_disable_xxe->enable == 0) { |
| 272 | hook_libxml_disable_entity_loader(); | 270 | hook_libxml_disable_entity_loader(); |
| 273 | } | 271 | } |
| 272 | |||
| 274 | if (SNUFFLEUPAGUS_G(config).config_wrapper->enabled) { | 273 | if (SNUFFLEUPAGUS_G(config).config_wrapper->enabled) { |
| 275 | hook_stream_wrappers(); | 274 | hook_stream_wrappers(); |
| 276 | } | 275 | } |
| 277 | hook_disabled_functions(); | 276 | |
| 278 | hook_execute(); | 277 | if (SNUFFLEUPAGUS_G(config).config_session->encrypt) { |
| 278 | hook_session(); | ||
| 279 | } | ||
| 279 | 280 | ||
| 280 | if (NULL != SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key) { | 281 | if (NULL != SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key) { |
| 281 | if (SNUFFLEUPAGUS_G(config).config_unserialize->enable) { | 282 | if (SNUFFLEUPAGUS_G(config).config_unserialize->enable) { |
| 282 | hook_serialize(); | 283 | hook_serialize(); |
| 283 | } | 284 | } |
| 284 | } | 285 | } |
| 285 | hook_cookies(); | ||
| 286 | 286 | ||
| 287 | if (SNUFFLEUPAGUS_G(config).config_session->encrypt) { | 287 | hook_disabled_functions(); |
| 288 | hook_session(); | 288 | hook_execute(); |
| 289 | } | 289 | hook_cookies(); |
| 290 | 290 | ||
| 291 | if (true == SNUFFLEUPAGUS_G(config).config_global_strict->enable) { | 291 | if (true == SNUFFLEUPAGUS_G(config).config_global_strict->enable) { |
| 292 | if (!zend_get_extension(PHP_SNUFFLEUPAGUS_EXTNAME)) { | 292 | if (!zend_get_extension(PHP_SNUFFLEUPAGUS_EXTNAME)) { |
| @@ -300,10 +300,10 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 300 | // If `zend_write_default` is not NULL it is already hooked. | 300 | // If `zend_write_default` is not NULL it is already hooked. |
| 301 | if ((zend_hash_str_find( | 301 | if ((zend_hash_str_find( |
| 302 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked, "echo", | 302 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked, "echo", |
| 303 | strlen("echo")) || | 303 | sizeof("echo") - 1) || |
| 304 | zend_hash_str_find( | 304 | zend_hash_str_find( |
| 305 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked, "echo", | 305 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked, "echo", |
| 306 | strlen("echo"))) && NULL == zend_write_default) { | 306 | sizeof("echo") - 1)) && NULL == zend_write_default) { |
| 307 | zend_write_default = zend_write; | 307 | zend_write_default = zend_write; |
| 308 | zend_write = hook_echo; | 308 | zend_write = hook_echo; |
| 309 | } | 309 | } |
diff --git a/src/sp_config.c b/src/sp_config.c index 2480362..dbf3881 100644 --- a/src/sp_config.c +++ b/src/sp_config.c | |||
| @@ -113,8 +113,7 @@ int parse_php_type(char *restrict line, char *restrict keyword, void *retval) { | |||
| 113 | sp_log_err("error", | 113 | sp_log_err("error", |
| 114 | "%s) is expecting a valid php type ('false', 'true'," | 114 | "%s) is expecting a valid php type ('false', 'true'," |
| 115 | " 'array'. 'object', 'long', 'double', 'null', 'resource', " | 115 | " 'array'. 'object', 'long', 'double', 'null', 'resource', " |
| 116 | "'reference'," | 116 | "'reference', 'undef') on line %zu", |
| 117 | " 'undef') on line %zu", | ||
| 118 | keyword, sp_line_no); | 117 | keyword, sp_line_no); |
| 119 | return -1; | 118 | return -1; |
| 120 | } | 119 | } |
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 93077c6..6bb7130 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -486,7 +486,7 @@ int parse_disabled_functions(char *line) { | |||
| 486 | 486 | ||
| 487 | if (df->function && zend_string_equals_literal(df->function, "print")) { | 487 | if (df->function && zend_string_equals_literal(df->function, "print")) { |
| 488 | zend_string_release(df->function); | 488 | zend_string_release(df->function); |
| 489 | df->function = zend_string_init("echo", strlen("echo"), 1); | 489 | df->function = zend_string_init("echo", sizeof("echo") - 1, 1); |
| 490 | } | 490 | } |
| 491 | 491 | ||
| 492 | if (df->function && !df->functions_list) { | 492 | if (df->function && !df->functions_list) { |
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index 1b59e44..31dde95 100644 --- a/src/sp_cookie_encryption.c +++ b/src/sp_cookie_encryption.c | |||
| @@ -45,9 +45,9 @@ static zend_string *encrypt_data(zend_string *data) { | |||
| 45 | PHP_FUNCTION(sp_setcookie) { | 45 | PHP_FUNCTION(sp_setcookie) { |
| 46 | zend_string *name = NULL, *value = NULL, *path = NULL, *domain = NULL, *value_enc = NULL, | 46 | zend_string *name = NULL, *value = NULL, *path = NULL, *domain = NULL, *value_enc = NULL, |
| 47 | #if PHP_VERSION_ID < 70300 | 47 | #if PHP_VERSION_ID < 70300 |
| 48 | *path_samesite = NULL; | 48 | *path_samesite = NULL; |
| 49 | #else | 49 | #else |
| 50 | *samesite = NULL; | 50 | *samesite = NULL; |
| 51 | #endif | 51 | #endif |
| 52 | 52 | ||
| 53 | zend_long expires = 0; | 53 | zend_long expires = 0; |
diff --git a/src/sp_crypt.c b/src/sp_crypt.c index f4d1799..8336973 100644 --- a/src/sp_crypt.c +++ b/src/sp_crypt.c | |||
| @@ -31,8 +31,7 @@ void generate_key(unsigned char *key) { | |||
| 31 | "cookie_encryption", | 31 | "cookie_encryption", |
| 32 | "The environment variable '%s' " | 32 | "The environment variable '%s' " |
| 33 | "is empty, cookies are weakly encrypted", | 33 | "is empty, cookies are weakly encrypted", |
| 34 | ZSTR_VAL( | 34 | ZSTR_VAL(env_var_zend)); |
| 35 | SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)); | ||
| 36 | } | 35 | } |
| 37 | 36 | ||
| 38 | if (encryption_key) { | 37 | if (encryption_key) { |
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index 379ed75..835776b 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -580,13 +580,13 @@ ZEND_FUNCTION(eval_blacklist_callback) { | |||
| 580 | if (SNUFFLEUPAGUS_G(in_eval) > 0) { | 580 | if (SNUFFLEUPAGUS_G(in_eval) > 0) { |
| 581 | zend_string* filename = get_eval_filename(zend_get_executed_filename()); | 581 | zend_string* filename = get_eval_filename(zend_get_executed_filename()); |
| 582 | const int line_number = zend_get_executed_lineno(TSRMLS_C); | 582 | const int line_number = zend_get_executed_lineno(TSRMLS_C); |
| 583 | if (SNUFFLEUPAGUS_G(config).config_eval->dump) { | 583 | const sp_config_eval* config_eval = SNUFFLEUPAGUS_G(config).config_eval; |
| 584 | sp_log_request( | 584 | |
| 585 | SNUFFLEUPAGUS_G(config).config_eval->dump, | 585 | if (config_eval->dump) { |
| 586 | SNUFFLEUPAGUS_G(config).config_eval->textual_representation, | 586 | sp_log_request(config_eval->dump, config_eval->textual_representation, |
| 587 | SP_TOKEN_EVAL_BLACKLIST); | 587 | SP_TOKEN_EVAL_BLACKLIST); |
| 588 | } | 588 | } |
| 589 | if (SNUFFLEUPAGUS_G(config).config_eval->simulation) { | 589 | if (config_eval->simulation) { |
| 590 | sp_log_msg("eval", SP_LOG_SIMULATION, | 590 | sp_log_msg("eval", SP_LOG_SIMULATION, |
| 591 | "A call to %s was tried in eval, in %s:%d, logging it.", | 591 | "A call to %s was tried in eval, in %s:%d, logging it.", |
| 592 | current_function_name, ZSTR_VAL(filename), line_number); | 592 | current_function_name, ZSTR_VAL(filename), line_number); |
diff --git a/src/sp_execute.c b/src/sp_execute.c index 5447ea1..60d63ab 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c | |||
| @@ -13,14 +13,15 @@ static int (*orig_zend_stream_open)(const char *filename, | |||
| 13 | 13 | ||
| 14 | // FIXME handle symlink | 14 | // FIXME handle symlink |
| 15 | ZEND_COLD static inline void terminate_if_writable(const char *filename) { | 15 | ZEND_COLD static inline void terminate_if_writable(const char *filename) { |
| 16 | const sp_config_readonly_exec* config_ro_exec = | ||
| 17 | SNUFFLEUPAGUS_G(config).config_readonly_exec; | ||
| 18 | |||
| 16 | if (0 == access(filename, W_OK)) { | 19 | if (0 == access(filename, W_OK)) { |
| 17 | if (SNUFFLEUPAGUS_G(config).config_readonly_exec->dump) { | 20 | if (config_ro_exec->dump) { |
| 18 | sp_log_request( | 21 | sp_log_request(config_ro_exec->dump, config_ro_exec->textual_representation, |
| 19 | SNUFFLEUPAGUS_G(config).config_readonly_exec->dump, | ||
| 20 | SNUFFLEUPAGUS_G(config).config_readonly_exec->textual_representation, | ||
| 21 | SP_TOKEN_READONLY_EXEC); | 22 | SP_TOKEN_READONLY_EXEC); |
| 22 | } | 23 | } |
| 23 | if (true == SNUFFLEUPAGUS_G(config).config_readonly_exec->simulation) { | 24 | if (true == config_ro_exec->simulation) { |
| 24 | sp_log_msg("readonly_exec", SP_LOG_SIMULATION, | 25 | sp_log_msg("readonly_exec", SP_LOG_SIMULATION, |
| 25 | "Attempted execution of a writable file (%s).", filename); | 26 | "Attempted execution of a writable file (%s).", filename); |
| 26 | } else { | 27 | } else { |
| @@ -57,7 +58,7 @@ inline static void is_builtin_matching( | |||
| 57 | 58 | ||
| 58 | static void ZEND_HOT | 59 | static void ZEND_HOT |
| 59 | is_in_eval_and_whitelisted(const zend_execute_data *execute_data) { | 60 | is_in_eval_and_whitelisted(const zend_execute_data *execute_data) { |
| 60 | sp_config_eval *eval = SNUFFLEUPAGUS_G(config).config_eval; | 61 | const sp_config_eval *config_eval = SNUFFLEUPAGUS_G(config).config_eval; |
| 61 | 62 | ||
| 62 | if (EXPECTED(0 == SNUFFLEUPAGUS_G(in_eval))) { | 63 | if (EXPECTED(0 == SNUFFLEUPAGUS_G(in_eval))) { |
| 63 | return; | 64 | return; |
| @@ -79,13 +80,11 @@ is_in_eval_and_whitelisted(const zend_execute_data *execute_data) { | |||
| 79 | 80 | ||
| 80 | if (EXPECTED(NULL != current_function)) { | 81 | if (EXPECTED(NULL != current_function)) { |
| 81 | if (UNEXPECTED(false == check_is_in_eval_whitelist(current_function))) { | 82 | if (UNEXPECTED(false == check_is_in_eval_whitelist(current_function))) { |
| 82 | if (eval->dump) { | 83 | if (config_eval->dump) { |
| 83 | sp_log_request( | 84 | sp_log_request(config_eval->dump, config_eval->textual_representation, |
| 84 | SNUFFLEUPAGUS_G(config).config_eval->dump, | ||
| 85 | SNUFFLEUPAGUS_G(config).config_eval->textual_representation, | ||
| 86 | SP_TOKEN_EVAL_WHITELIST); | 85 | SP_TOKEN_EVAL_WHITELIST); |
| 87 | } | 86 | } |
| 88 | if (eval->simulation) { | 87 | if (config_eval->simulation) { |
| 89 | sp_log_msg( | 88 | sp_log_msg( |
| 90 | "Eval_whitelist", SP_LOG_SIMULATION, | 89 | "Eval_whitelist", SP_LOG_SIMULATION, |
| 91 | "The function '%s' isn't in the eval whitelist, logging its call.", | 90 | "The function '%s' isn't in the eval whitelist, logging its call.", |
| @@ -124,17 +123,19 @@ zend_string *get_eval_filename(const char *const filename) { | |||
| 124 | 123 | ||
| 125 | static void sp_execute_ex(zend_execute_data *execute_data) { | 124 | static void sp_execute_ex(zend_execute_data *execute_data) { |
| 126 | is_in_eval_and_whitelisted(execute_data); | 125 | is_in_eval_and_whitelisted(execute_data); |
| 126 | const HashTable* config_disabled_functions = | ||
| 127 | SNUFFLEUPAGUS_G(config).config_disabled_functions; | ||
| 127 | 128 | ||
| 128 | if (!execute_data) { | 129 | if (!execute_data) { |
| 129 | return; | 130 | return; |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | if (UNEXPECTED(EX(func)->op_array.type == ZEND_EVAL_CODE)) { | 133 | if (UNEXPECTED(EX(func)->op_array.type == ZEND_EVAL_CODE)) { |
| 133 | const sp_list_node *config = zend_hash_str_find_ptr( | 134 | const sp_list_node * config = zend_hash_str_find_ptr( |
| 134 | SNUFFLEUPAGUS_G(config).config_disabled_functions, "eval", 4); | 135 | config_disabled_functions, "eval", sizeof("eval") - 1); |
| 136 | |||
| 135 | zend_string *filename = get_eval_filename(zend_get_executed_filename()); | 137 | zend_string *filename = get_eval_filename(zend_get_executed_filename()); |
| 136 | is_builtin_matching(filename, "eval", NULL, config, | 138 | is_builtin_matching(filename, "eval", NULL, config, config_disabled_functions); |
| 137 | SNUFFLEUPAGUS_G(config).config_disabled_functions); | ||
| 138 | zend_string_release(filename); | 139 | zend_string_release(filename); |
| 139 | 140 | ||
| 140 | SNUFFLEUPAGUS_G(in_eval)++; | 141 | SNUFFLEUPAGUS_G(in_eval)++; |
| @@ -152,6 +153,9 @@ static void sp_execute_ex(zend_execute_data *execute_data) { | |||
| 152 | if (SNUFFLEUPAGUS_G(config).hook_execute) { | 153 | if (SNUFFLEUPAGUS_G(config).hook_execute) { |
| 153 | char *function_name = get_complete_function_path(execute_data); | 154 | char *function_name = get_complete_function_path(execute_data); |
| 154 | zval ret_val; | 155 | zval ret_val; |
| 156 | const sp_list_node* config_disabled_functions_reg = | ||
| 157 | SNUFFLEUPAGUS_G(config).config_disabled_functions_reg | ||
| 158 | ->disabled_functions; | ||
| 155 | 159 | ||
| 156 | if (!function_name) { | 160 | if (!function_name) { |
| 157 | orig_execute_ex(execute_data); | 161 | orig_execute_ex(execute_data); |
| @@ -163,11 +167,9 @@ static void sp_execute_ex(zend_execute_data *execute_data) { | |||
| 163 | !ZEND_USER_CODE(execute_data->prev_execute_data->func->type) || | 167 | !ZEND_USER_CODE(execute_data->prev_execute_data->func->type) || |
| 164 | !execute_data->prev_execute_data->opline) { | 168 | !execute_data->prev_execute_data->opline) { |
| 165 | if (UNEXPECTED(true == | 169 | if (UNEXPECTED(true == |
| 166 | should_disable_ht( | 170 | should_disable_ht(execute_data, function_name, NULL, NULL, |
| 167 | execute_data, function_name, NULL, NULL, | 171 | config_disabled_functions_reg, |
| 168 | SNUFFLEUPAGUS_G(config) | 172 | config_disabled_functions))) { |
| 169 | .config_disabled_functions_reg->disabled_functions, | ||
| 170 | SNUFFLEUPAGUS_G(config).config_disabled_functions))) { | ||
| 171 | sp_terminate(); | 173 | sp_terminate(); |
| 172 | } | 174 | } |
| 173 | } else if ((execute_data->prev_execute_data->opline->opcode == | 175 | } else if ((execute_data->prev_execute_data->opline->opcode == |
| @@ -177,11 +179,9 @@ static void sp_execute_ex(zend_execute_data *execute_data) { | |||
| 177 | execute_data->prev_execute_data->opline->opcode == | 179 | execute_data->prev_execute_data->opline->opcode == |
| 178 | ZEND_DO_FCALL_BY_NAME)) { | 180 | ZEND_DO_FCALL_BY_NAME)) { |
| 179 | if (UNEXPECTED(true == | 181 | if (UNEXPECTED(true == |
| 180 | should_disable_ht( | 182 | should_disable_ht(execute_data, function_name, NULL, NULL, |
| 181 | execute_data, function_name, NULL, NULL, | 183 | config_disabled_functions_reg, |
| 182 | SNUFFLEUPAGUS_G(config) | 184 | config_disabled_functions))) { |
| 183 | .config_disabled_functions_reg->disabled_functions, | ||
| 184 | SNUFFLEUPAGUS_G(config).config_disabled_functions))) { | ||
| 185 | sp_terminate(); | 185 | sp_terminate(); |
| 186 | } | 186 | } |
| 187 | } | 187 | } |
| @@ -235,6 +235,9 @@ static int sp_stream_open(const char *filename, zend_file_handle *handle) { | |||
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | zend_string *zend_filename = zend_string_init(filename, strlen(filename), 0); | 237 | zend_string *zend_filename = zend_string_init(filename, strlen(filename), 0); |
| 238 | const HashTable* disabled_functions_hooked = | ||
| 239 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked; | ||
| 240 | |||
| 238 | switch (data->opline->opcode) { | 241 | switch (data->opline->opcode) { |
| 239 | case ZEND_INCLUDE_OR_EVAL: | 242 | case ZEND_INCLUDE_OR_EVAL: |
| 240 | if (true == SNUFFLEUPAGUS_G(config).config_readonly_exec->enable) { | 243 | if (true == SNUFFLEUPAGUS_G(config).config_readonly_exec->enable) { |
| @@ -244,34 +247,30 @@ static int sp_stream_open(const char *filename, zend_file_handle *handle) { | |||
| 244 | case ZEND_INCLUDE: | 247 | case ZEND_INCLUDE: |
| 245 | is_builtin_matching( | 248 | is_builtin_matching( |
| 246 | zend_filename, "include", "inclusion path", | 249 | zend_filename, "include", "inclusion path", |
| 247 | zend_hash_str_find_ptr( | 250 | zend_hash_str_find_ptr(disabled_functions_hooked, |
| 248 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked, | 251 | "include", sizeof("include") - 1), |
| 249 | "include", 7), | 252 | disabled_functions_hooked); |
| 250 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 251 | break; | 253 | break; |
| 252 | case ZEND_REQUIRE: | 254 | case ZEND_REQUIRE: |
| 253 | is_builtin_matching( | 255 | is_builtin_matching( |
| 254 | zend_filename, "require", "inclusion path", | 256 | zend_filename, "require", "inclusion path", |
| 255 | zend_hash_str_find_ptr( | 257 | zend_hash_str_find_ptr(disabled_functions_hooked, |
| 256 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked, | 258 | "require", sizeof("require") - 1), |
| 257 | "require", 7), | 259 | disabled_functions_hooked); |
| 258 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 259 | break; | 260 | break; |
| 260 | case ZEND_REQUIRE_ONCE: | 261 | case ZEND_REQUIRE_ONCE: |
| 261 | is_builtin_matching( | 262 | is_builtin_matching( |
| 262 | zend_filename, "require_once", "inclusion path", | 263 | zend_filename, "require_once", "inclusion path", |
| 263 | zend_hash_str_find_ptr( | 264 | zend_hash_str_find_ptr(disabled_functions_hooked, |
| 264 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked, | 265 | "require_once", sizeof("require_once") - 1), |
| 265 | "require_once", 12), | 266 | disabled_functions_hooked); |
| 266 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 267 | break; | 267 | break; |
| 268 | case ZEND_INCLUDE_ONCE: | 268 | case ZEND_INCLUDE_ONCE: |
| 269 | is_builtin_matching( | 269 | is_builtin_matching( |
| 270 | zend_filename, "include_once", "inclusion path", | 270 | zend_filename, "include_once", "inclusion path", |
| 271 | zend_hash_str_find_ptr( | 271 | zend_hash_str_find_ptr(disabled_functions_hooked, |
| 272 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked, | 272 | "include_once", sizeof("include_once") - 1), |
| 273 | "include_once", 12), | 273 | disabled_functions_hooked); |
| 274 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 275 | break; | 274 | break; |
| 276 | EMPTY_SWITCH_DEFAULT_CASE(); | 275 | EMPTY_SWITCH_DEFAULT_CASE(); |
| 277 | } | 276 | } |
diff --git a/src/sp_harden_rand.c b/src/sp_harden_rand.c index ca0503b..7b4e958 100644 --- a/src/sp_harden_rand.c +++ b/src/sp_harden_rand.c | |||
| @@ -57,7 +57,7 @@ PHP_FUNCTION(sp_rand) { | |||
| 57 | /* call the original `rand` function, | 57 | /* call the original `rand` function, |
| 58 | * since we might no be the only ones to hook it*/ | 58 | * since we might no be the only ones to hook it*/ |
| 59 | orig_handler = zend_hash_str_find_ptr( | 59 | orig_handler = zend_hash_str_find_ptr( |
| 60 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "rand", strlen("rand")); | 60 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "rand", sizeof("rand") - 1); |
| 61 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 61 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 62 | 62 | ||
| 63 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 63 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| @@ -70,7 +70,7 @@ PHP_FUNCTION(sp_mt_rand) { | |||
| 70 | * since we might no be the only ones to hook it*/ | 70 | * since we might no be the only ones to hook it*/ |
| 71 | orig_handler = | 71 | orig_handler = |
| 72 | zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), | 72 | zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), |
| 73 | "mt_rand", strlen("mt_rand")); | 73 | "mt_rand", sizeof("mt_rand") - 1); |
| 74 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 74 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 75 | 75 | ||
| 76 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 76 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
diff --git a/src/sp_session.c b/src/sp_session.c index 35866a1..8aad624 100644 --- a/src/sp_session.c +++ b/src/sp_session.c | |||
| @@ -23,16 +23,17 @@ static ZEND_INI_MH((*old_OnUpdateSaveHandler)) = NULL; | |||
| 23 | 23 | ||
| 24 | static int sp_hook_s_read(PS_READ_ARGS) { | 24 | static int sp_hook_s_read(PS_READ_ARGS) { |
| 25 | int r = old_s_read(mod_data, key, val, maxlifetime); | 25 | int r = old_s_read(mod_data, key, val, maxlifetime); |
| 26 | if (r == SUCCESS && SNUFFLEUPAGUS_G(config).config_session->encrypt && | 26 | const sp_config_session* config_session = SNUFFLEUPAGUS_G(config).config_session; |
| 27 | |||
| 28 | if (r == SUCCESS && config_session->encrypt && | ||
| 27 | val != NULL && *val != NULL && ZSTR_LEN(*val)) { | 29 | val != NULL && *val != NULL && ZSTR_LEN(*val)) { |
| 28 | zend_string *orig_val = *val; | 30 | zend_string *orig_val = *val; |
| 29 | zval val_zval; | 31 | zval val_zval; |
| 30 | ZVAL_PSTRINGL(&val_zval, ZSTR_VAL(*val), ZSTR_LEN(*val)); | 32 | ZVAL_PSTRINGL(&val_zval, ZSTR_VAL(*val), ZSTR_LEN(*val)); |
| 31 | 33 | ||
| 32 | int ret = decrypt_zval( | 34 | int ret = decrypt_zval(&val_zval, config_session->simulation, NULL); |
| 33 | &val_zval, SNUFFLEUPAGUS_G(config).config_session->simulation, NULL); | ||
| 34 | if (0 != ret) { | 35 | if (0 != ret) { |
| 35 | if (SNUFFLEUPAGUS_G(config).config_session->simulation) { | 36 | if (config_session->simulation) { |
| 36 | return ret; | 37 | return ret; |
| 37 | } else { | 38 | } else { |
| 38 | sp_terminate(); | 39 | sp_terminate(); |
diff --git a/src/sp_unserialize.c b/src/sp_unserialize.c index 9ed1c55..ab0139a 100644 --- a/src/sp_unserialize.c +++ b/src/sp_unserialize.c | |||
| @@ -7,7 +7,8 @@ PHP_FUNCTION(sp_serialize) { | |||
| 7 | 7 | ||
| 8 | /* Call the original `serialize` function. */ | 8 | /* Call the original `serialize` function. */ |
| 9 | orig_handler = zend_hash_str_find_ptr( | 9 | orig_handler = zend_hash_str_find_ptr( |
| 10 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "serialize", 9); | 10 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "serialize", |
| 11 | sizeof("serialize") - 1); | ||
| 11 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 12 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 12 | 13 | ||
| 13 | /* Compute the HMAC of the textual representation of the serialized data*/ | 14 | /* Compute the HMAC of the textual representation of the serialized data*/ |
| @@ -50,6 +51,9 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 50 | size_t buf_len = 0; | 51 | size_t buf_len = 0; |
| 51 | zval *opts = NULL; | 52 | zval *opts = NULL; |
| 52 | 53 | ||
| 54 | const sp_config_unserialize* config_unserialize = | ||
| 55 | SNUFFLEUPAGUS_G(config).config_unserialize; | ||
| 56 | |||
| 53 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a", &buf, &buf_len, &opts) == | 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a", &buf, &buf_len, &opts) == |
| 54 | FAILURE) { | 58 | FAILURE) { |
| 55 | RETURN_FALSE; | 59 | RETURN_FALSE; |
| @@ -85,16 +89,17 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 85 | 89 | ||
| 86 | if (0 == status) { | 90 | if (0 == status) { |
| 87 | if ((orig_handler = zend_hash_str_find_ptr( | 91 | if ((orig_handler = zend_hash_str_find_ptr( |
| 88 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "unserialize", 11))) { | 92 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "unserialize", |
| 93 | sizeof("unserialize") - 1))) { | ||
| 89 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 94 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 90 | } | 95 | } |
| 91 | } else { | 96 | } else { |
| 92 | if (true == SNUFFLEUPAGUS_G(config).config_unserialize->simulation) { | 97 | if (true == config_unserialize->simulation) { |
| 93 | sp_log_msg("unserialize", SP_LOG_SIMULATION, "Invalid HMAC for %s", | 98 | sp_log_msg("unserialize", SP_LOG_SIMULATION, "Invalid HMAC for %s", |
| 94 | serialized_str); | 99 | serialized_str); |
| 95 | if ((orig_handler = zend_hash_str_find_ptr( | 100 | if ((orig_handler = zend_hash_str_find_ptr( |
| 96 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "unserialize", | 101 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "unserialize", |
| 97 | 11))) { | 102 | sizeof("unserialize") - 1))) { |
| 98 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 103 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 99 | } | 104 | } |
| 100 | } else { | 105 | } else { |
| @@ -102,10 +107,9 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 102 | serialized_str); | 107 | serialized_str); |
| 103 | } | 108 | } |
| 104 | } | 109 | } |
| 105 | if (SNUFFLEUPAGUS_G(config).config_unserialize->dump) { | 110 | if (config_unserialize->dump) { |
| 106 | sp_log_request( | 111 | sp_log_request(config_unserialize->dump, |
| 107 | SNUFFLEUPAGUS_G(config).config_unserialize->dump, | 112 | config_unserialize->textual_representation, |
| 108 | SNUFFLEUPAGUS_G(config).config_unserialize->textual_representation, | ||
| 109 | SP_TOKEN_UNSERIALIZE_HMAC); | 113 | SP_TOKEN_UNSERIALIZE_HMAC); |
| 110 | } | 114 | } |
| 111 | efree(serialized_str); | 115 | efree(serialized_str); |
diff --git a/src/sp_upload_validation.c b/src/sp_upload_validation.c index c079e41..6fa721e 100644 --- a/src/sp_upload_validation.c +++ b/src/sp_upload_validation.c | |||
| @@ -21,22 +21,23 @@ int sp_rfc1867_callback(unsigned int event, void *event_data, void **extra) { | |||
| 21 | 21 | ||
| 22 | if (event == MULTIPART_EVENT_END) { | 22 | if (event == MULTIPART_EVENT_END) { |
| 23 | zend_string *file_key __attribute__((unused)) = NULL; | 23 | zend_string *file_key __attribute__((unused)) = NULL; |
| 24 | const sp_config_upload_validation* config_upload = | ||
| 25 | SNUFFLEUPAGUS_G(config).config_upload_validation; | ||
| 24 | zval *file; | 26 | zval *file; |
| 25 | pid_t pid; | 27 | pid_t pid; |
| 26 | 28 | ||
| 27 | sp_log_debug( | 29 | sp_log_debug("Got %d files", |
| 28 | "Got %d files", | ||
| 29 | zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_FILES]))); | 30 | zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_FILES]))); |
| 30 | 31 | ||
| 31 | ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL(PG(http_globals)[TRACK_VARS_FILES]), | 32 | ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL(PG(http_globals)[TRACK_VARS_FILES]), |
| 32 | file_key, file) { // for each uploaded file | 33 | file_key, file) { // for each uploaded file |
| 33 | 34 | ||
| 34 | char *filename = | 35 | char *filename = |
| 35 | Z_STRVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "name", 4)); | 36 | Z_STRVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "name", sizeof("name") - 1)); |
| 36 | char *tmp_name = | 37 | char *tmp_name = |
| 37 | Z_STRVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "tmp_name", 8)); | 38 | Z_STRVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "tmp_name", sizeof("tmp_name") - 1)); |
| 38 | size_t filesize = | 39 | size_t filesize = |
| 39 | Z_LVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "size", 4)); | 40 | Z_LVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "size", sizeof("size") - 1)); |
| 40 | char *cmd[3] = {0}; | 41 | char *cmd[3] = {0}; |
| 41 | char *env[5] = {0}; | 42 | char *env[5] = {0}; |
| 42 | 43 | ||
| @@ -44,10 +45,9 @@ int sp_rfc1867_callback(unsigned int event, void *event_data, void **extra) { | |||
| 44 | "Filename: %s\nTmpname: %s\nSize: %d\nError: %d\nScript: %s", | 45 | "Filename: %s\nTmpname: %s\nSize: %d\nError: %d\nScript: %s", |
| 45 | filename, tmp_name, filesize, | 46 | filename, tmp_name, filesize, |
| 46 | Z_LVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "error", 5)), | 47 | Z_LVAL_P(zend_hash_str_find(Z_ARRVAL_P(file), "error", 5)), |
| 47 | ZSTR_VAL(SNUFFLEUPAGUS_G(config).config_upload_validation->script)); | 48 | ZSTR_VAL(config_upload->script)); |
| 48 | 49 | ||
| 49 | cmd[0] = | 50 | cmd[0] = ZSTR_VAL(config_upload->script); |
| 50 | ZSTR_VAL(SNUFFLEUPAGUS_G(config).config_upload_validation->script); | ||
| 51 | cmd[1] = tmp_name; | 51 | cmd[1] = tmp_name; |
| 52 | cmd[2] = NULL; | 52 | cmd[2] = NULL; |
| 53 | 53 | ||
| @@ -59,14 +59,10 @@ int sp_rfc1867_callback(unsigned int event, void *event_data, void **extra) { | |||
| 59 | env[4] = NULL; | 59 | env[4] = NULL; |
| 60 | 60 | ||
| 61 | if ((pid = fork()) == 0) { | 61 | if ((pid = fork()) == 0) { |
| 62 | if (execve( | 62 | if (execve(ZSTR_VAL(config_upload->script), cmd, env) == -1) { |
| 63 | ZSTR_VAL( | ||
| 64 | SNUFFLEUPAGUS_G(config).config_upload_validation->script), | ||
| 65 | cmd, env) == -1) { | ||
| 66 | sp_log_warn( | 63 | sp_log_warn( |
| 67 | "upload_validation", "Could not call '%s' : %s", | 64 | "upload_validation", "Could not call '%s' : %s", |
| 68 | ZSTR_VAL( | 65 | ZSTR_VAL(config_upload->script), |
| 69 | SNUFFLEUPAGUS_G(config).config_upload_validation->script), | ||
| 70 | strerror(errno)); | 66 | strerror(errno)); |
| 71 | EFREE_3(env); | 67 | EFREE_3(env); |
| 72 | exit(1); | 68 | exit(1); |
| @@ -85,11 +81,11 @@ int sp_rfc1867_callback(unsigned int event, void *event_data, void **extra) { | |||
| 85 | wait(&waitstatus); | 81 | wait(&waitstatus); |
| 86 | if (WEXITSTATUS(waitstatus) != 0) { // Nope | 82 | if (WEXITSTATUS(waitstatus) != 0) { // Nope |
| 87 | char *uri = getenv("REQUEST_URI"); | 83 | char *uri = getenv("REQUEST_URI"); |
| 88 | int sim = SNUFFLEUPAGUS_G(config).config_upload_validation->simulation; | 84 | int sim = config_upload->simulation; |
| 89 | sp_log_msg("upload_validation", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, | 85 | sp_log_msg("upload_validation", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, |
| 90 | "The upload of %s on %s was rejected.", filename, | 86 | "The upload of %s on %s was rejected.", filename, |
| 91 | uri ? uri : "?"); | 87 | uri ? uri : "?"); |
| 92 | if (!SNUFFLEUPAGUS_G(config).config_upload_validation->simulation) { | 88 | if (!config_upload->simulation) { |
| 93 | sp_terminate(); | 89 | sp_terminate(); |
| 94 | } | 90 | } |
| 95 | } | 91 | } |
diff --git a/src/sp_utils.c b/src/sp_utils.c index e872abd..970f314 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -126,7 +126,6 @@ int sp_log_request(const zend_string* folder, const zend_string* text_repr, | |||
| 126 | } | 126 | } |
| 127 | fclose(file); | 127 | fclose(file); |
| 128 | 128 | ||
| 129 | #undef CAT_AND_DEC | ||
| 130 | return 0; | 129 | return 0; |
| 131 | } | 130 | } |
| 132 | 131 | ||
| @@ -171,17 +170,17 @@ const zend_string* sp_zval_to_zend_string(const zval* zv) { | |||
| 171 | return Z_STR_P(zv); | 170 | return Z_STR_P(zv); |
| 172 | } | 171 | } |
| 173 | case IS_FALSE: | 172 | case IS_FALSE: |
| 174 | return zend_string_init("FALSE", 5, 0); | 173 | return zend_string_init("FALSE", sizeof("FALSE") - 1, 0); |
| 175 | case IS_TRUE: | 174 | case IS_TRUE: |
| 176 | return zend_string_init("TRUE", 4, 0); | 175 | return zend_string_init("TRUE", sizeof("TRUE") - 1, 0); |
| 177 | case IS_NULL: | 176 | case IS_NULL: |
| 178 | return zend_string_init("NULL", 4, 0); | 177 | return zend_string_init("NULL", sizeof("NULL") - 1, 0); |
| 179 | case IS_OBJECT: | 178 | case IS_OBJECT: |
| 180 | return zend_string_init("OBJECT", 6, 0); | 179 | return zend_string_init("OBJECT", sizeof("OBJECT") - 1, 0); |
| 181 | case IS_ARRAY: | 180 | case IS_ARRAY: |
| 182 | return zend_string_init("ARRAY", 5, 0); | 181 | return zend_string_init("ARRAY", sizeof("ARRAY") - 1, 0); |
| 183 | case IS_RESOURCE: | 182 | case IS_RESOURCE: |
| 184 | return zend_string_init("RESOURCE", 8, 0); | 183 | return zend_string_init("RESOURCE", sizeof("RESOURCE") - 1, 0); |
| 185 | } | 184 | } |
| 186 | return zend_string_init("", 0, 0); | 185 | return zend_string_init("", 0, 0); |
| 187 | } | 186 | } |
| @@ -353,7 +352,7 @@ int hook_function(const char* original_name, HashTable* hook_table, | |||
| 353 | } else { // TODO this can be moved somewhere else to gain some marginal perfs | 352 | } else { // TODO this can be moved somewhere else to gain some marginal perfs |
| 354 | CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; | 353 | CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; |
| 355 | char* mb_name = ecalloc(strlen(original_name) + 3 + 1, 1); | 354 | char* mb_name = ecalloc(strlen(original_name) + 3 + 1, 1); |
| 356 | memcpy(mb_name, "mb_", 3); | 355 | memcpy(mb_name, "mb_", sizeof("mb_") - 1); |
| 357 | memcpy(mb_name + 3, VAR_AND_LEN(original_name)); | 356 | memcpy(mb_name + 3, VAR_AND_LEN(original_name)); |
| 358 | if (zend_hash_str_find(CG(function_table), VAR_AND_LEN(mb_name))) { | 357 | if (zend_hash_str_find(CG(function_table), VAR_AND_LEN(mb_name))) { |
| 359 | return hook_function(mb_name, hook_table, new_function); | 358 | return hook_function(mb_name, hook_table, new_function); |
