summaryrefslogtreecommitdiff
path: root/src/sp_execute.c
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-11-30 19:38:34 +0100
committerBen Fuhrmannek2021-11-30 19:38:34 +0100
commit6095651e2caa729ff56ae5a53c908b09e5f7dc29 (patch)
tree0bb9907ea7142701c206b00a135c0c0d96c9ca39 /src/sp_execute.c
parenta870b1547fceb5f58d56f1a1646ab1e897d28238 (diff)
PHP 8.1 compatibility with streams/includes + fix for ticks
Diffstat (limited to 'src/sp_execute.c')
-rw-r--r--src/sp_execute.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/sp_execute.c b/src/sp_execute.c
index ccb7508..f540119 100644
--- a/src/sp_execute.c
+++ b/src/sp_execute.c
@@ -3,8 +3,11 @@
3static void (*orig_execute_ex)(zend_execute_data *execute_data) = NULL; 3static void (*orig_execute_ex)(zend_execute_data *execute_data) = NULL;
4static void (*orig_zend_execute_internal)(zend_execute_data *execute_data, 4static void (*orig_zend_execute_internal)(zend_execute_data *execute_data,
5 zval *return_value) = NULL; 5 zval *return_value) = NULL;
6static int (*orig_zend_stream_open)(const char *filename, 6#if PHP_VERSION_ID < 80100
7 zend_file_handle *handle) = NULL; 7static int (*orig_zend_stream_open)(const char *filename, zend_file_handle *handle) = NULL;
8#else
9static zend_result (*orig_zend_stream_open)(zend_file_handle *handle) = NULL;
10#endif
8 11
9// FIXME handle symlink 12// FIXME handle symlink
10ZEND_COLD static inline void terminate_if_writable(const char *filename) { 13ZEND_COLD static inline void terminate_if_writable(const char *filename) {
@@ -168,6 +171,7 @@ static void sp_execute_ex(zend_execute_data *execute_data) {
168 case ZEND_DO_FCALL_BY_NAME: 171 case ZEND_DO_FCALL_BY_NAME:
169 case ZEND_DO_ICALL: 172 case ZEND_DO_ICALL:
170 case ZEND_DO_UCALL: 173 case ZEND_DO_UCALL:
174 case ZEND_TICKS:
171 should_disable_ht(execute_data, function_name, NULL, NULL, 175 should_disable_ht(execute_data, function_name, NULL, NULL,
172 config_disabled_functions_reg, 176 config_disabled_functions_reg,
173 config_disabled_functions); 177 config_disabled_functions);
@@ -209,21 +213,21 @@ static void sp_zend_execute_internal(INTERNAL_FUNCTION_PARAMETERS) {
209 } 213 }
210} 214}
211 215
212static int sp_stream_open(const char *filename, zend_file_handle *handle) { 216static inline void sp_stream_open_checks(zend_string *zend_filename, zend_file_handle *handle) {
213 zend_execute_data const *const data = EG(current_execute_data); 217 zend_execute_data const *const data = EG(current_execute_data);
214 218
215 if ((NULL == data) || (NULL == data->opline) || 219 if ((NULL == data) || (NULL == data->opline) ||
216 (data->func->type != ZEND_USER_FUNCTION)) { 220 (data->func->type != ZEND_USER_FUNCTION)) {
217 goto end; 221 return;
218 } 222 }
219 223
220 zend_string *zend_filename = zend_string_init(filename, strlen(filename), 0); 224 // zend_string *zend_filename = zend_string_init(filename, strlen(filename), 0);
221 const HashTable *disabled_functions_hooked = SPCFG(disabled_functions_hooked); 225 const HashTable *disabled_functions_hooked = SPCFG(disabled_functions_hooked);
222 226
223 switch (data->opline->opcode) { 227 switch (data->opline->opcode) {
224 case ZEND_INCLUDE_OR_EVAL: 228 case ZEND_INCLUDE_OR_EVAL:
225 if (SPCFG(readonly_exec).enable) { 229 if (SPCFG(readonly_exec).enable) {
226 terminate_if_writable(filename); 230 terminate_if_writable(ZSTR_VAL(zend_filename));
227 } 231 }
228 switch (data->opline->extended_value) { 232 switch (data->opline->extended_value) {
229 case ZEND_INCLUDE: 233 case ZEND_INCLUDE:
@@ -253,12 +257,32 @@ static int sp_stream_open(const char *filename, zend_file_handle *handle) {
253 EMPTY_SWITCH_DEFAULT_CASE(); // LCOV_EXCL_LINE 257 EMPTY_SWITCH_DEFAULT_CASE(); // LCOV_EXCL_LINE
254 } 258 }
255 } 259 }
256 efree(zend_filename); 260 // efree(zend_filename);
261
262// end:
263 // return orig_zend_stream_open(filename, handle);
264}
265
266#if PHP_VERSION_ID < 80100
267
268static int sp_stream_open(const char *filename, zend_file_handle *handle) {
269 zend_string *zend_filename = zend_string_init(filename, strlen(filename), 0);
257 270
258end: 271 sp_stream_open_checks(zend_filename, handle);
272
273 zend_string_release_ex(zend_filename, 0);
259 return orig_zend_stream_open(filename, handle); 274 return orig_zend_stream_open(filename, handle);
260} 275}
261 276
277#else // PHP >= 8.1
278
279static zend_result sp_stream_open(zend_file_handle *handle) {
280 sp_stream_open_checks(handle->filename, handle);
281 return orig_zend_stream_open(handle);
282}
283
284#endif
285
262int hook_execute(void) { 286int hook_execute(void) {
263 TSRMLS_FETCH(); 287 TSRMLS_FETCH();
264 288