1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include "request_hooks.h"
#include "compat_zend_string.h"
#include <Zend/zend.h>
#include <Zend/zend_compile.h>
#include <php_main.h>
#if PHP_VERSION_ID < 70000
int dd_execute_php_file(const char *filename TSRMLS_DC) {
int filename_len = strlen(filename);
if (filename_len == 0) {
return FAILURE;
}
int dummy = 1;
zend_file_handle file_handle;
zend_op_array *new_op_array;
zval *result = NULL;
int ret;
ret = php_stream_open_for_zend_ex(filename, &file_handle, USE_PATH | STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
if (ret == SUCCESS) {
if (!file_handle.opened_path) {
file_handle.opened_path = estrndup(filename, filename_len);
}
if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path) + 1,
(void *)&dummy, sizeof(int), NULL) == SUCCESS) {
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC);
zend_destroy_file_handle(&file_handle TSRMLS_CC);
} else {
new_op_array = NULL;
zend_file_handle_dtor(&file_handle TSRMLS_CC);
}
if (new_op_array) {
EG(return_value_ptr_ptr) = &result;
EG(active_op_array) = new_op_array;
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
zend_execute(new_op_array TSRMLS_CC);
destroy_op_array(new_op_array TSRMLS_CC);
efree(new_op_array);
if (!EG(exception)) {
if (EG(return_value_ptr_ptr)) {
zval_ptr_dtor(EG(return_value_ptr_ptr));
}
}
return 1;
}
}
return 0;
}
#else
int dd_execute_php_file(const char *filename TSRMLS_DC) {
int filename_len = strlen(filename);
if (filename_len == 0) {
return FAILURE;
}
zval dummy;
zend_file_handle file_handle;
zend_op_array *new_op_array;
zval result;
int ret;
ret = php_stream_open_for_zend_ex(filename, &file_handle, USE_PATH | STREAM_OPEN_FOR_INCLUDE);
if (ret == SUCCESS) {
zend_string *opened_path;
if (!file_handle.opened_path) {
file_handle.opened_path = zend_string_init(filename, filename_len, 0);
}
opened_path = zend_string_copy(file_handle.opened_path);
ZVAL_NULL(&dummy);
if (zend_hash_add(&EG(included_files), opened_path, &dummy)) {
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE);
zend_destroy_file_handle(&file_handle);
} else {
new_op_array = NULL;
zend_file_handle_dtor(&file_handle);
}
zend_string_release(opened_path);
if (new_op_array) {
ZVAL_UNDEF(&result);
zend_execute(new_op_array, &result);
destroy_op_array(new_op_array);
efree(new_op_array);
if (!EG(exception)) {
zval_ptr_dtor(&result);
}
return 1;
}
}
return 0;
}
#endif
|