summaryrefslogtreecommitdiff
path: root/src/snuffleupagus.c
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-08-02 19:19:23 +0200
committerBen Fuhrmannek2021-08-02 19:19:23 +0200
commitae4ac9f69de3120004557824e0d766fe8140b27d (patch)
treeef97751ab54357d5d74859b870ce84f4c6d044df /src/snuffleupagus.c
parent4cda0120313dfd5d71236f6faf87416e93f5f89c (diff)
properly free memory on shutdown
Diffstat (limited to 'src/snuffleupagus.c')
-rw-r--r--src/snuffleupagus.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c
index 7bf3649..d8a86b5 100644
--- a/src/snuffleupagus.c
+++ b/src/snuffleupagus.c
@@ -69,7 +69,7 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = {
69 NULL, /* op_array_dtor_func_t */ 69 NULL, /* op_array_dtor_func_t */
70 STANDARD_ZEND_EXTENSION_PROPERTIES}; 70 STANDARD_ZEND_EXTENSION_PROPERTIES};
71 71
72PHP_GINIT_FUNCTION(snuffleupagus) { 72static PHP_GINIT_FUNCTION(snuffleupagus) {
73 snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; 73 snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE;
74 snuffleupagus_globals->in_eval = 0; 74 snuffleupagus_globals->in_eval = 0;
75 75
@@ -88,21 +88,21 @@ PHP_GINIT_FUNCTION(snuffleupagus) {
88#define SP_INIT(F) \ 88#define SP_INIT(F) \
89 snuffleupagus_globals->config.F = \ 89 snuffleupagus_globals->config.F = \
90 pecalloc(sizeof(*(snuffleupagus_globals->config.F)), 1, 1); 90 pecalloc(sizeof(*(snuffleupagus_globals->config.F)), 1, 1);
91 SP_INIT(config_unserialize);
92 SP_INIT(config_random); 91 SP_INIT(config_random);
93 SP_INIT(config_sloppy); 92 SP_INIT(config_sloppy);
93 SP_INIT(config_unserialize);
94 SP_INIT(config_readonly_exec); 94 SP_INIT(config_readonly_exec);
95 SP_INIT(config_global_strict);
96 SP_INIT(config_auto_cookie_secure);
97 SP_INIT(config_snuffleupagus);
98 SP_INIT(config_disable_xxe);
99 SP_INIT(config_upload_validation); 95 SP_INIT(config_upload_validation);
100 SP_INIT(config_disabled_functions_reg);
101 SP_INIT(config_disabled_functions_reg_ret);
102 SP_INIT(config_cookie); 96 SP_INIT(config_cookie);
103 SP_INIT(config_session); 97 SP_INIT(config_snuffleupagus);
98 SP_INIT(config_auto_cookie_secure);
99 SP_INIT(config_global_strict);
100 SP_INIT(config_disable_xxe);
104 SP_INIT(config_eval); 101 SP_INIT(config_eval);
105 SP_INIT(config_wrapper); 102 SP_INIT(config_wrapper);
103 SP_INIT(config_session);
104 SP_INIT(config_disabled_functions_reg);
105 SP_INIT(config_disabled_functions_reg_ret);
106#undef SP_INIT 106#undef SP_INIT
107 107
108#define SP_INIT_NULL(F) snuffleupagus_globals->config.F = NULL; 108#define SP_INIT_NULL(F) snuffleupagus_globals->config.F = NULL;
@@ -121,21 +121,27 @@ PHP_MINIT_FUNCTION(snuffleupagus) {
121 return SUCCESS; 121 return SUCCESS;
122} 122}
123 123
124static void free_disabled_functions_hashtable(HashTable *const ht) { 124PHP_MSHUTDOWN_FUNCTION(snuffleupagus) {
125 UNREGISTER_INI_ENTRIES();
126
127 return SUCCESS;
128}
129
130static inline void free_disabled_functions_hashtable(HashTable *const ht) {
125 void *ptr = NULL; 131 void *ptr = NULL;
126 ZEND_HASH_FOREACH_PTR(ht, ptr) { sp_list_free(ptr); } 132 ZEND_HASH_FOREACH_PTR(ht, ptr) { sp_list_free(ptr, sp_free_disabled_function); }
127 ZEND_HASH_FOREACH_END(); 133 ZEND_HASH_FOREACH_END();
128} 134}
129 135
130PHP_MSHUTDOWN_FUNCTION(snuffleupagus) { 136static PHP_GSHUTDOWN_FUNCTION(snuffleupagus) {
131#define FREE_HT(F) \ 137#define FREE_HT(F) \
132 zend_hash_destroy(SNUFFLEUPAGUS_G(F)); \ 138 zend_hash_destroy(snuffleupagus_globals->F); \
133 pefree(SNUFFLEUPAGUS_G(F), 1); 139 pefree(snuffleupagus_globals->F, 1);
134 FREE_HT(disabled_functions_hook); 140 FREE_HT(disabled_functions_hook);
135 FREE_HT(sp_eval_blacklist_functions_hook); 141 FREE_HT(sp_eval_blacklist_functions_hook);
136 142
137#define FREE_HT_LIST(F) \ 143#define FREE_HT_LIST(F) \
138 free_disabled_functions_hashtable(SNUFFLEUPAGUS_G(config).F); \ 144 free_disabled_functions_hashtable(snuffleupagus_globals->config.F); \
139 FREE_HT(config.F); 145 FREE_HT(config.F);
140 FREE_HT_LIST(config_disabled_functions); 146 FREE_HT_LIST(config_disabled_functions);
141 FREE_HT_LIST(config_disabled_functions_hooked); 147 FREE_HT_LIST(config_disabled_functions_hooked);
@@ -145,44 +151,43 @@ PHP_MSHUTDOWN_FUNCTION(snuffleupagus) {
145#undef FREE_HT 151#undef FREE_HT
146 152
147#define FREE_LST_DISABLE(L) \ 153#define FREE_LST_DISABLE(L) \
148 do { \ 154 sp_list_free(snuffleupagus_globals->config.L, sp_free_disabled_function);
149 sp_list_node *_n = SNUFFLEUPAGUS_G(config).L; \
150 sp_disabled_function_list_free(_n); \
151 sp_list_free(_n); \
152 } while (0)
153 FREE_LST_DISABLE(config_disabled_functions_reg->disabled_functions); 155 FREE_LST_DISABLE(config_disabled_functions_reg->disabled_functions);
154 FREE_LST_DISABLE(config_disabled_functions_reg_ret->disabled_functions); 156 FREE_LST_DISABLE(config_disabled_functions_reg_ret->disabled_functions);
155#undef FREE_LST_DISABLE 157#undef FREE_LST_DISABLE
156 158
157 sp_list_node *_n = SNUFFLEUPAGUS_G(config).config_cookie->cookies; 159 sp_list_free(snuffleupagus_globals->config.config_cookie->cookies, sp_free_cookie);
158 sp_cookie_list_free(_n);
159 sp_list_free(_n);
160 160
161#define FREE_LST(L) sp_list_free(SNUFFLEUPAGUS_G(config).L); 161#define FREE_LST(L) sp_list_free(snuffleupagus_globals->config.L, sp_free_zstr);
162 FREE_LST(config_eval->blacklist); 162 FREE_LST(config_eval->blacklist);
163 FREE_LST(config_eval->whitelist); 163 FREE_LST(config_eval->whitelist);
164 FREE_LST(config_wrapper->whitelist); 164 FREE_LST(config_wrapper->whitelist);
165#undef FREE_LST 165#undef FREE_LST
166 166
167#define FREE_CFG(C) pefree(SNUFFLEUPAGUS_G(config).C, 1); 167#define FREE_CFG(C) pefree(snuffleupagus_globals->config.C, 1);
168 FREE_CFG(config_unserialize); 168#define FREE_CFG_ZSTR(C) sp_free_zstr(snuffleupagus_globals->config.C);
169 FREE_CFG(config_random); 169 FREE_CFG(config_random);
170 FREE_CFG(config_sloppy);
171 FREE_CFG_ZSTR(config_unserialize->dump);
172 FREE_CFG_ZSTR(config_unserialize->textual_representation);
173 FREE_CFG(config_unserialize);
170 FREE_CFG(config_readonly_exec); 174 FREE_CFG(config_readonly_exec);
171 FREE_CFG(config_global_strict); 175 FREE_CFG_ZSTR(config_upload_validation->script);
172 FREE_CFG(config_auto_cookie_secure); 176 FREE_CFG(config_upload_validation);
177 FREE_CFG(config_cookie);
173 FREE_CFG(config_snuffleupagus); 178 FREE_CFG(config_snuffleupagus);
179 FREE_CFG(config_auto_cookie_secure);
180 FREE_CFG(config_global_strict);
174 FREE_CFG(config_disable_xxe); 181 FREE_CFG(config_disable_xxe);
175 FREE_CFG(config_upload_validation); 182 FREE_CFG_ZSTR(config_eval->dump);
183 FREE_CFG_ZSTR(config_eval->textual_representation);
184 FREE_CFG(config_eval);
185 FREE_CFG(config_wrapper);
176 FREE_CFG(config_session); 186 FREE_CFG(config_session);
177 FREE_CFG(config_disabled_functions_reg); 187 FREE_CFG(config_disabled_functions_reg);
178 FREE_CFG(config_disabled_functions_reg_ret); 188 FREE_CFG(config_disabled_functions_reg_ret);
179 FREE_CFG(config_cookie);
180 FREE_CFG(config_wrapper);
181#undef FREE_CFG 189#undef FREE_CFG
182 190#undef FREE_CFG_ZSTR
183 UNREGISTER_INI_ENTRIES();
184
185 return SUCCESS;
186} 191}
187 192
188PHP_RINIT_FUNCTION(snuffleupagus) { 193PHP_RINIT_FUNCTION(snuffleupagus) {
@@ -358,7 +363,7 @@ zend_module_entry snuffleupagus_module_entry = {
358 PHP_SNUFFLEUPAGUS_VERSION, 363 PHP_SNUFFLEUPAGUS_VERSION,
359 PHP_MODULE_GLOBALS(snuffleupagus), 364 PHP_MODULE_GLOBALS(snuffleupagus),
360 PHP_GINIT(snuffleupagus), 365 PHP_GINIT(snuffleupagus),
361 NULL, 366 PHP_GSHUTDOWN(snuffleupagus),
362 NULL, 367 NULL,
363 STANDARD_MODULE_PROPERTIES_EX}; 368 STANDARD_MODULE_PROPERTIES_EX};
364 369