/src/php-src/Zend/zend_execute.c
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Zend Engine | |
4 | | +----------------------------------------------------------------------+ |
5 | | | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | |
6 | | +----------------------------------------------------------------------+ |
7 | | | This source file is subject to version 2.00 of the Zend license, | |
8 | | | that is bundled with this package in the file LICENSE, and is | |
9 | | | available through the world-wide-web at the following url: | |
10 | | | http://www.zend.com/license/2_00.txt. | |
11 | | | If you did not receive a copy of the Zend license and are unable to | |
12 | | | obtain it through the world-wide-web, please send a note to | |
13 | | | license@zend.com so we can mail you a copy immediately. | |
14 | | +----------------------------------------------------------------------+ |
15 | | | Authors: Andi Gutmans <andi@php.net> | |
16 | | | Zeev Suraski <zeev@php.net> | |
17 | | | Dmitry Stogov <dmitry@php.net> | |
18 | | +----------------------------------------------------------------------+ |
19 | | */ |
20 | | |
21 | | #define ZEND_INTENSIVE_DEBUGGING 0 |
22 | | |
23 | | #include <stdio.h> |
24 | | #include <signal.h> |
25 | | |
26 | | #include "zend.h" |
27 | | #include "zend_compile.h" |
28 | | #include "zend_execute.h" |
29 | | #include "zend_API.h" |
30 | | #include "zend_ptr_stack.h" |
31 | | #include "zend_constants.h" |
32 | | #include "zend_extensions.h" |
33 | | #include "zend_ini.h" |
34 | | #include "zend_exceptions.h" |
35 | | #include "zend_interfaces.h" |
36 | | #include "zend_closures.h" |
37 | | #include "zend_generators.h" |
38 | | #include "zend_vm.h" |
39 | | #include "zend_dtrace.h" |
40 | | #include "zend_inheritance.h" |
41 | | #include "zend_type_info.h" |
42 | | #include "zend_smart_str.h" |
43 | | #include "zend_observer.h" |
44 | | #include "zend_system_id.h" |
45 | | #include "zend_call_stack.h" |
46 | | #include "zend_attributes.h" |
47 | | #include "Optimizer/zend_func_info.h" |
48 | | |
49 | | /* Virtual current working directory support */ |
50 | | #include "zend_virtual_cwd.h" |
51 | | |
52 | | #ifdef HAVE_GCC_GLOBAL_REGS |
53 | | # if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386) |
54 | | # define ZEND_VM_FP_GLOBAL_REG "%esi" |
55 | | # define ZEND_VM_IP_GLOBAL_REG "%edi" |
56 | | # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__) |
57 | | # define ZEND_VM_FP_GLOBAL_REG "%r14" |
58 | | # define ZEND_VM_IP_GLOBAL_REG "%r15" |
59 | | # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__) |
60 | | # define ZEND_VM_FP_GLOBAL_REG "r14" |
61 | | # define ZEND_VM_IP_GLOBAL_REG "r15" |
62 | | # elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__) |
63 | | # define ZEND_VM_FP_GLOBAL_REG "r14" |
64 | | # define ZEND_VM_IP_GLOBAL_REG "r15" |
65 | | # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__) |
66 | | # define ZEND_VM_FP_GLOBAL_REG "x27" |
67 | | # define ZEND_VM_IP_GLOBAL_REG "x28" |
68 | | #elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__riscv) && __riscv_xlen == 64 |
69 | | # define ZEND_VM_FP_GLOBAL_REG "x18" |
70 | | # define ZEND_VM_IP_GLOBAL_REG "x19" |
71 | | # endif |
72 | | #endif |
73 | | |
74 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
75 | | # pragma GCC diagnostic ignored "-Wvolatile-register-var" |
76 | | register zend_execute_data* volatile execute_data __asm__(ZEND_VM_FP_GLOBAL_REG); |
77 | | # pragma GCC diagnostic warning "-Wvolatile-register-var" |
78 | | #endif |
79 | | |
80 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
81 | | # define EXECUTE_DATA_D void |
82 | | # define EXECUTE_DATA_C |
83 | | # define EXECUTE_DATA_DC |
84 | | # define EXECUTE_DATA_CC |
85 | | # define NO_EXECUTE_DATA_CC |
86 | | #else |
87 | | # define EXECUTE_DATA_D zend_execute_data* execute_data |
88 | 4.32M | # define EXECUTE_DATA_C execute_data |
89 | | # define EXECUTE_DATA_DC , EXECUTE_DATA_D |
90 | 3.73M | # define EXECUTE_DATA_CC , EXECUTE_DATA_C |
91 | 12 | # define NO_EXECUTE_DATA_CC , NULL |
92 | | #endif |
93 | | |
94 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
95 | | # define OPLINE_D void |
96 | | # define OPLINE_C |
97 | | # define OPLINE_DC |
98 | | # define OPLINE_CC |
99 | | #else |
100 | | # define OPLINE_D const zend_op* opline |
101 | 884k | # define OPLINE_C opline |
102 | | # define OPLINE_DC , OPLINE_D |
103 | 884k | # define OPLINE_CC , OPLINE_C |
104 | | #endif |
105 | | |
106 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
107 | | # pragma GCC diagnostic ignored "-Wvolatile-register-var" |
108 | | register const zend_op* volatile opline __asm__(ZEND_VM_IP_GLOBAL_REG); |
109 | | # pragma GCC diagnostic warning "-Wvolatile-register-var" |
110 | | #else |
111 | | #endif |
112 | | |
113 | 73.1M | #define _CONST_CODE 0 |
114 | 73.1M | #define _TMP_CODE 1 |
115 | 73.1M | #define _VAR_CODE 2 |
116 | 365M | #define _UNUSED_CODE 3 |
117 | 73.1M | #define _CV_CODE 4 |
118 | | |
119 | | typedef int (ZEND_FASTCALL *incdec_t)(zval *); |
120 | | |
121 | 179 | #define get_zval_ptr(op_type, node, type) _get_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
122 | 0 | #define get_zval_ptr_deref(op_type, node, type) _get_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
123 | 91 | #define get_zval_ptr_undef(op_type, node, type) _get_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
124 | 2.25k | #define get_op_data_zval_ptr_r(op_type, node) _get_op_data_zval_ptr_r(op_type, node EXECUTE_DATA_CC OPLINE_CC) |
125 | 0 | #define get_op_data_zval_ptr_deref_r(op_type, node) _get_op_data_zval_ptr_deref_r(op_type, node EXECUTE_DATA_CC OPLINE_CC) |
126 | 9 | #define get_zval_ptr_ptr(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC) |
127 | | #define get_zval_ptr_ptr_undef(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC) |
128 | | #define get_obj_zval_ptr(op_type, node, type) _get_obj_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
129 | | #define get_obj_zval_ptr_deref(op_type, node, type) _get_obj_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
130 | | #define get_obj_zval_ptr_undef(op_type, node, type) _get_obj_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
131 | | #define get_obj_zval_ptr_ptr(op_type, node, type) _get_obj_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC) |
132 | | |
133 | 325k | #define RETURN_VALUE_USED(opline) ((opline)->result_type != IS_UNUSED) |
134 | | |
135 | | static ZEND_FUNCTION(pass) |
136 | 52 | { |
137 | 52 | } |
138 | | |
139 | | static zend_arg_info zend_pass_function_arg_info[1] = {0}; |
140 | | |
141 | | ZEND_API const zend_internal_function zend_pass_function = { |
142 | | ZEND_INTERNAL_FUNCTION, /* type */ |
143 | | {0, 0, 0}, /* arg_flags */ |
144 | | 0, /* fn_flags */ |
145 | | NULL, /* name */ |
146 | | NULL, /* scope */ |
147 | | NULL, /* prototype */ |
148 | | 0, /* num_args */ |
149 | | 0, /* required_num_args */ |
150 | | zend_pass_function_arg_info + 1, /* arg_info */ |
151 | | NULL, /* attributes */ |
152 | | NULL, /* run_time_cache */ |
153 | | NULL, /* doc_comment */ |
154 | | 0, /* T */ |
155 | | 0, /* fn_flags2 */ |
156 | | NULL, /* prop_info */ |
157 | | ZEND_FN(pass), /* handler */ |
158 | | NULL, /* module */ |
159 | | NULL, /* frameless_function_infos */ |
160 | | {NULL,NULL,NULL,NULL} /* reserved */ |
161 | | }; |
162 | | |
163 | 590 | #define FREE_VAR_PTR_AND_EXTRACT_RESULT_IF_NECESSARY(free_var) do { \ |
164 | 590 | zval *__container_to_free = EX_VAR(free_var); \ |
165 | 590 | if (UNEXPECTED(Z_REFCOUNTED_P(__container_to_free))) { \ |
166 | 25 | zend_refcounted *__ref = Z_COUNTED_P(__container_to_free); \ |
167 | 25 | if (UNEXPECTED(!GC_DELREF(__ref))) { \ |
168 | 12 | zval *__zv = EX_VAR(opline->result.var); \ |
169 | 12 | if (EXPECTED(Z_TYPE_P(__zv) == IS_INDIRECT)) { \ |
170 | 11 | ZVAL_COPY(__zv, Z_INDIRECT_P(__zv)); \ |
171 | 11 | } \ |
172 | 12 | rc_dtor_func(__ref); \ |
173 | 12 | } \ |
174 | 25 | } \ |
175 | 590 | } while (0) |
176 | | |
177 | | #define FREE_OP(type, var) \ |
178 | 5.40k | if ((type) & (IS_TMP_VAR|IS_VAR)) { \ |
179 | 3.16k | zval_ptr_dtor_nogc(EX_VAR(var)); \ |
180 | 3.16k | } |
181 | | |
182 | 643k | #define CV_DEF_OF(i) (EX(func)->op_array.vars[i]) |
183 | | |
184 | 445k | #define ZEND_VM_STACK_PAGE_SLOTS (16 * 1024) /* should be a power of 2 */ |
185 | | |
186 | 445k | #define ZEND_VM_STACK_PAGE_SIZE (ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval)) |
187 | | |
188 | | #define ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, page_size) \ |
189 | 4 | (((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \ |
190 | 4 | + ((page_size) - 1)) & ~((page_size) - 1)) |
191 | | |
192 | | ZEND_API void zend_vm_stack_init(void) |
193 | 222k | { |
194 | 222k | EG(vm_stack_page_size) = ZEND_VM_STACK_PAGE_SIZE; |
195 | 222k | EG(vm_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE, NULL); |
196 | 222k | EG(vm_stack_top) = EG(vm_stack)->top; |
197 | 222k | EG(vm_stack_end) = EG(vm_stack)->end; |
198 | 222k | } |
199 | | |
200 | | ZEND_API void zend_vm_stack_init_ex(size_t page_size) |
201 | 0 | { |
202 | | /* page_size must be a power of 2 */ |
203 | 0 | ZEND_ASSERT(page_size > 0 && (page_size & (page_size - 1)) == 0); |
204 | 0 | EG(vm_stack_page_size) = page_size; |
205 | 0 | EG(vm_stack) = zend_vm_stack_new_page(page_size, NULL); |
206 | 0 | EG(vm_stack_top) = EG(vm_stack)->top; |
207 | 0 | EG(vm_stack_end) = EG(vm_stack)->end; |
208 | 0 | } |
209 | | |
210 | | ZEND_API void zend_vm_stack_destroy(void) |
211 | 222k | { |
212 | 222k | zend_vm_stack stack = EG(vm_stack); |
213 | | |
214 | 445k | while (stack != NULL) { |
215 | 222k | zend_vm_stack p = stack->prev; |
216 | 222k | efree(stack); |
217 | 222k | stack = p; |
218 | 222k | } |
219 | 222k | } |
220 | | |
221 | | ZEND_API void* zend_vm_stack_extend(size_t size) |
222 | 4 | { |
223 | 4 | zend_vm_stack stack; |
224 | 4 | void *ptr; |
225 | | |
226 | 4 | stack = EG(vm_stack); |
227 | 4 | stack->top = EG(vm_stack_top); |
228 | 4 | EG(vm_stack) = stack = zend_vm_stack_new_page( |
229 | 4 | EXPECTED(size < EG(vm_stack_page_size) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval))) ? |
230 | 4 | EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, EG(vm_stack_page_size)), |
231 | 4 | stack); |
232 | 4 | ptr = stack->top; |
233 | 4 | EG(vm_stack_top) = (void*)(((char*)ptr) + size); |
234 | 4 | EG(vm_stack_end) = stack->end; |
235 | 4 | return ptr; |
236 | 4 | } |
237 | | |
238 | | ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data, uint32_t var) |
239 | 0 | { |
240 | 0 | return EX_VAR(var); |
241 | 0 | } |
242 | | |
243 | | ZEND_API bool zend_gcc_global_regs(void) |
244 | 0 | { |
245 | | #if defined(HAVE_GCC_GLOBAL_REGS) |
246 | | return 1; |
247 | | #else |
248 | 0 | return 0; |
249 | 0 | #endif |
250 | 0 | } |
251 | | |
252 | | static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var EXECUTE_DATA_DC) |
253 | 443k | { |
254 | 443k | zval *ret = EX_VAR(var); |
255 | | |
256 | 443k | ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE); |
257 | | |
258 | 443k | return ret; |
259 | 443k | } |
260 | | |
261 | | static zend_always_inline zval *_get_zval_ptr_var(uint32_t var EXECUTE_DATA_DC) |
262 | 1.55M | { |
263 | 1.55M | zval *ret = EX_VAR(var); |
264 | | |
265 | 1.55M | return ret; |
266 | 1.55M | } |
267 | | |
268 | | static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var EXECUTE_DATA_DC) |
269 | 230 | { |
270 | 230 | zval *ret = EX_VAR(var); |
271 | | |
272 | 230 | ZVAL_DEREF(ret); |
273 | 230 | return ret; |
274 | 230 | } |
275 | | |
276 | | static zend_never_inline ZEND_COLD zval* zval_undefined_cv(uint32_t var EXECUTE_DATA_DC) |
277 | 643k | { |
278 | 643k | if (EXPECTED(EG(exception) == NULL)) { |
279 | 643k | zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var)); |
280 | 643k | zend_error_unchecked(E_WARNING, "Undefined variable $%S", cv); |
281 | 643k | } |
282 | 643k | return &EG(uninitialized_zval); |
283 | 643k | } |
284 | | |
285 | | static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op1(EXECUTE_DATA_D) |
286 | 428k | { |
287 | 428k | return zval_undefined_cv(EX(opline)->op1.var EXECUTE_DATA_CC); |
288 | 428k | } |
289 | | |
290 | | static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op2(EXECUTE_DATA_D) |
291 | 154k | { |
292 | 154k | return zval_undefined_cv(EX(opline)->op2.var EXECUTE_DATA_CC); |
293 | 154k | } |
294 | | |
295 | 428k | #define ZVAL_UNDEFINED_OP1() _zval_undefined_op1(EXECUTE_DATA_C) |
296 | 154k | #define ZVAL_UNDEFINED_OP2() _zval_undefined_op2(EXECUTE_DATA_C) |
297 | | |
298 | | static zend_never_inline ZEND_COLD zval *_get_zval_cv_lookup(zval *ptr, uint32_t var, int type EXECUTE_DATA_DC) |
299 | 5 | { |
300 | 5 | switch (type) { |
301 | 5 | case BP_VAR_R: |
302 | 5 | case BP_VAR_UNSET: |
303 | 5 | ptr = zval_undefined_cv(var EXECUTE_DATA_CC); |
304 | 5 | break; |
305 | 0 | case BP_VAR_IS: |
306 | 0 | ptr = &EG(uninitialized_zval); |
307 | 0 | break; |
308 | 0 | case BP_VAR_RW: |
309 | 0 | zval_undefined_cv(var EXECUTE_DATA_CC); |
310 | 0 | ZEND_FALLTHROUGH; |
311 | 0 | case BP_VAR_W: |
312 | 0 | ZVAL_NULL(ptr); |
313 | 0 | break; |
314 | 5 | } |
315 | 5 | return ptr; |
316 | 5 | } |
317 | | |
318 | | static zend_always_inline zval *_get_zval_ptr_cv(uint32_t var, int type EXECUTE_DATA_DC) |
319 | 70 | { |
320 | 70 | zval *ret = EX_VAR(var); |
321 | | |
322 | 70 | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
323 | 7 | if (type == BP_VAR_W) { |
324 | 2 | ZVAL_NULL(ret); |
325 | 5 | } else { |
326 | 5 | return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC); |
327 | 5 | } |
328 | 7 | } |
329 | 65 | return ret; |
330 | 70 | } |
331 | | |
332 | | static zend_always_inline zval *_get_zval_ptr_cv_deref(uint32_t var, int type EXECUTE_DATA_DC) |
333 | 1 | { |
334 | 1 | zval *ret = EX_VAR(var); |
335 | | |
336 | 1 | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
337 | 0 | if (type == BP_VAR_W) { |
338 | 0 | ZVAL_NULL(ret); |
339 | 0 | return ret; |
340 | 0 | } else { |
341 | 0 | return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC); |
342 | 0 | } |
343 | 0 | } |
344 | 1 | ZVAL_DEREF(ret); |
345 | 1 | return ret; |
346 | 1 | } |
347 | | |
348 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(uint32_t var EXECUTE_DATA_DC) |
349 | 29.7k | { |
350 | 29.7k | zval *ret = EX_VAR(var); |
351 | | |
352 | 29.7k | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
353 | 3.05k | return zval_undefined_cv(var EXECUTE_DATA_CC); |
354 | 3.05k | } |
355 | 26.6k | return ret; |
356 | 29.7k | } |
357 | | |
358 | | static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_R(uint32_t var EXECUTE_DATA_DC) |
359 | 11.4k | { |
360 | 11.4k | zval *ret = EX_VAR(var); |
361 | | |
362 | 11.4k | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
363 | 702 | return zval_undefined_cv(var EXECUTE_DATA_CC); |
364 | 702 | } |
365 | 10.7k | ZVAL_DEREF(ret); |
366 | 10.7k | return ret; |
367 | 11.4k | } |
368 | | |
369 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_IS(uint32_t var EXECUTE_DATA_DC) |
370 | 339 | { |
371 | 339 | zval *ret = EX_VAR(var); |
372 | | |
373 | 339 | return ret; |
374 | 339 | } |
375 | | |
376 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(uint32_t var EXECUTE_DATA_DC) |
377 | 858k | { |
378 | 858k | zval *ret = EX_VAR(var); |
379 | | |
380 | 858k | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
381 | 57.4k | zval_undefined_cv(var EXECUTE_DATA_CC); |
382 | 57.4k | ZVAL_NULL(ret); |
383 | 57.4k | return ret; |
384 | 57.4k | } |
385 | 801k | return ret; |
386 | 858k | } |
387 | | |
388 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(uint32_t var EXECUTE_DATA_DC) |
389 | 4.08k | { |
390 | 4.08k | zval *ret = EX_VAR(var); |
391 | | |
392 | 4.08k | if (Z_TYPE_P(ret) == IS_UNDEF) { |
393 | 206 | ZVAL_NULL(ret); |
394 | 206 | } |
395 | 4.08k | return ret; |
396 | 4.08k | } |
397 | | |
398 | | static zend_always_inline zval *_get_zval_ptr_tmpvarcv(int op_type, znode_op node, int type EXECUTE_DATA_DC) |
399 | 0 | { |
400 | 0 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
401 | 0 | if (op_type == IS_TMP_VAR) { |
402 | 0 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
403 | 0 | } else { |
404 | 0 | ZEND_ASSERT(op_type == IS_VAR); |
405 | 0 | return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC); |
406 | 0 | } |
407 | 0 | } else { |
408 | 0 | ZEND_ASSERT(op_type == IS_CV); |
409 | 0 | return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC); |
410 | 0 | } |
411 | 0 | } |
412 | | |
413 | | static zend_always_inline zval *_get_zval_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC) |
414 | 179 | { |
415 | 179 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
416 | 32 | if (!ZEND_DEBUG || op_type == IS_VAR) { |
417 | 4 | return _get_zval_ptr_var(node.var EXECUTE_DATA_CC); |
418 | 28 | } else { |
419 | 28 | ZEND_ASSERT(op_type == IS_TMP_VAR); |
420 | 28 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
421 | 28 | } |
422 | 147 | } else { |
423 | 147 | if (op_type == IS_CONST) { |
424 | 84 | return RT_CONSTANT(opline, node); |
425 | 84 | } else if (op_type == IS_CV) { |
426 | 63 | return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC); |
427 | 63 | } else { |
428 | 0 | return NULL; |
429 | 0 | } |
430 | 147 | } |
431 | 179 | } |
432 | | |
433 | | static zend_always_inline zval *_get_op_data_zval_ptr_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC) |
434 | 2.28k | { |
435 | 2.28k | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
436 | 411 | if (!ZEND_DEBUG || op_type == IS_VAR) { |
437 | 0 | return _get_zval_ptr_var(node.var EXECUTE_DATA_CC); |
438 | 411 | } else { |
439 | 411 | ZEND_ASSERT(op_type == IS_TMP_VAR); |
440 | 411 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
441 | 411 | } |
442 | 1.87k | } else { |
443 | 1.87k | if (op_type == IS_CONST) { |
444 | 1.39k | return RT_CONSTANT(opline + 1, node); |
445 | 1.39k | } else if (op_type == IS_CV) { |
446 | 475 | return _get_zval_ptr_cv_BP_VAR_R(node.var EXECUTE_DATA_CC); |
447 | 475 | } else { |
448 | 0 | return NULL; |
449 | 0 | } |
450 | 1.87k | } |
451 | 2.28k | } |
452 | | |
453 | | static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_zval_ptr_deref(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC) |
454 | 15 | { |
455 | 15 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
456 | 14 | if (op_type == IS_TMP_VAR) { |
457 | 7 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
458 | 7 | } else { |
459 | 7 | ZEND_ASSERT(op_type == IS_VAR); |
460 | 7 | return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC); |
461 | 7 | } |
462 | 14 | } else { |
463 | 1 | if (op_type == IS_CONST) { |
464 | 0 | return RT_CONSTANT(opline, node); |
465 | 1 | } else if (op_type == IS_CV) { |
466 | 1 | return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC); |
467 | 1 | } else { |
468 | 0 | return NULL; |
469 | 0 | } |
470 | 1 | } |
471 | 15 | } |
472 | | |
473 | | static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_op_data_zval_ptr_deref_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC) |
474 | 0 | { |
475 | 0 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
476 | 0 | if (op_type == IS_TMP_VAR) { |
477 | 0 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
478 | 0 | } else { |
479 | 0 | ZEND_ASSERT(op_type == IS_VAR); |
480 | 0 | return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC); |
481 | 0 | } |
482 | 0 | } else { |
483 | 0 | if (op_type == IS_CONST) { |
484 | 0 | return RT_CONSTANT(opline + 1, node); |
485 | 0 | } else if (op_type == IS_CV) { |
486 | 0 | return _get_zval_ptr_cv_deref_BP_VAR_R(node.var EXECUTE_DATA_CC); |
487 | 0 | } else { |
488 | 0 | return NULL; |
489 | 0 | } |
490 | 0 | } |
491 | 0 | } |
492 | | |
493 | | static zend_always_inline zval *_get_zval_ptr_undef(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC) |
494 | 91 | { |
495 | 91 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
496 | 34 | if (!ZEND_DEBUG || op_type == IS_VAR) { |
497 | 34 | return _get_zval_ptr_var(node.var EXECUTE_DATA_CC); |
498 | 34 | } else { |
499 | 0 | ZEND_ASSERT(op_type == IS_TMP_VAR); |
500 | 0 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
501 | 0 | } |
502 | 57 | } else { |
503 | 57 | if (op_type == IS_CONST) { |
504 | 26 | return RT_CONSTANT(opline, node); |
505 | 31 | } else if (op_type == IS_CV) { |
506 | 31 | return EX_VAR(node.var); |
507 | 31 | } else { |
508 | 0 | return NULL; |
509 | 0 | } |
510 | 57 | } |
511 | 91 | } |
512 | | |
513 | | static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var EXECUTE_DATA_DC) |
514 | 19.5k | { |
515 | 19.5k | zval *ret = EX_VAR(var); |
516 | | |
517 | 19.5k | if (EXPECTED(Z_TYPE_P(ret) == IS_INDIRECT)) { |
518 | 18.6k | ret = Z_INDIRECT_P(ret); |
519 | 18.6k | } |
520 | 19.5k | return ret; |
521 | 19.5k | } |
522 | | |
523 | | static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC) |
524 | 9 | { |
525 | 9 | if (op_type == IS_CV) { |
526 | 7 | return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC); |
527 | 7 | } else /* if (op_type == IS_VAR) */ { |
528 | 2 | ZEND_ASSERT(op_type == IS_VAR); |
529 | 2 | return _get_zval_ptr_ptr_var(node.var EXECUTE_DATA_CC); |
530 | 2 | } |
531 | 9 | } |
532 | | |
533 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC) |
534 | 0 | { |
535 | 0 | if (op_type == IS_UNUSED) { |
536 | 0 | return &EX(This); |
537 | 0 | } |
538 | 0 | return get_zval_ptr(op_type, op, type); |
539 | 0 | } |
540 | | |
541 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_deref(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC) |
542 | 0 | { |
543 | 0 | if (op_type == IS_UNUSED) { |
544 | 0 | return &EX(This); |
545 | 0 | } |
546 | 0 | return get_zval_ptr_deref(op_type, op, type); |
547 | 0 | } |
548 | | |
549 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_undef(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC) |
550 | 0 | { |
551 | 0 | if (op_type == IS_UNUSED) { |
552 | 0 | return &EX(This); |
553 | 0 | } |
554 | 0 | return get_zval_ptr_undef(op_type, op, type); |
555 | 0 | } |
556 | | |
557 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC) |
558 | 0 | { |
559 | 0 | if (op_type == IS_UNUSED) { |
560 | 0 | return &EX(This); |
561 | 0 | } |
562 | 0 | return get_zval_ptr_ptr(op_type, node, type); |
563 | 0 | } |
564 | | |
565 | | static inline void zend_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr, zend_refcounted **garbage_ptr) |
566 | 3.20k | { |
567 | 3.20k | zend_reference *ref; |
568 | | |
569 | 3.20k | if (EXPECTED(!Z_ISREF_P(value_ptr))) { |
570 | 540 | ZVAL_NEW_REF(value_ptr, value_ptr); |
571 | 2.66k | } else if (UNEXPECTED(variable_ptr == value_ptr)) { |
572 | 708 | return; |
573 | 708 | } |
574 | | |
575 | 2.50k | ref = Z_REF_P(value_ptr); |
576 | 2.50k | GC_ADDREF(ref); |
577 | 2.50k | if (Z_REFCOUNTED_P(variable_ptr)) { |
578 | 1.54k | *garbage_ptr = Z_COUNTED_P(variable_ptr); |
579 | 1.54k | } |
580 | 2.50k | ZVAL_REF(variable_ptr, ref); |
581 | 2.50k | } |
582 | | |
583 | | static zend_never_inline zval* zend_assign_to_typed_property_reference(zend_property_info *prop_info, zval *prop, zval *value_ptr, zend_refcounted **garbage_ptr EXECUTE_DATA_DC) |
584 | 145 | { |
585 | 145 | if (!zend_verify_prop_assignable_by_ref(prop_info, value_ptr, EX_USES_STRICT_TYPES())) { |
586 | 21 | return &EG(uninitialized_zval); |
587 | 21 | } |
588 | 124 | if (Z_ISREF_P(prop)) { |
589 | 102 | ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(prop), prop_info); |
590 | 102 | } |
591 | 124 | zend_assign_to_variable_reference(prop, value_ptr, garbage_ptr); |
592 | 124 | ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(prop), prop_info); |
593 | 124 | return prop; |
594 | 145 | } |
595 | | |
596 | | static zend_never_inline ZEND_COLD zval *zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr, zend_refcounted **garbage_ptr OPLINE_DC EXECUTE_DATA_DC) |
597 | 13 | { |
598 | 13 | zend_error(E_NOTICE, "Only variables should be assigned by reference"); |
599 | 13 | if (UNEXPECTED(EG(exception) != NULL)) { |
600 | 0 | return &EG(uninitialized_zval); |
601 | 0 | } |
602 | | |
603 | | /* Use IS_TMP_VAR instead of IS_VAR to avoid ISREF check */ |
604 | 13 | Z_TRY_ADDREF_P(value_ptr); |
605 | 13 | return zend_assign_to_variable_ex(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr); |
606 | 13 | } |
607 | | |
608 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num) |
609 | 9 | { |
610 | 9 | const zend_execute_data *execute_data = EG(current_execute_data); |
611 | 9 | zend_string *func_name = get_function_or_method_name(EX(call)->func); |
612 | 9 | const char *param_name = get_function_arg_name(EX(call)->func, arg_num); |
613 | | |
614 | 9 | zend_throw_error(NULL, "%s(): Argument #%d%s%s%s could not be passed by reference", |
615 | 9 | ZSTR_VAL(func_name), arg_num, param_name ? " ($" : "", param_name ? param_name : "", param_name ? ")" : "" |
616 | 9 | ); |
617 | | |
618 | 9 | zend_string_release(func_name); |
619 | 9 | } |
620 | | |
621 | 0 | static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(const zend_property_info *prop) { |
622 | 0 | zend_string *type_str = zend_type_to_string(prop->type); |
623 | 0 | zend_type_error( |
624 | 0 | "Cannot auto-initialize an array inside property %s::$%s of type %s", |
625 | 0 | ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name), |
626 | 0 | ZSTR_VAL(type_str) |
627 | 0 | ); |
628 | 0 | zend_string_release(type_str); |
629 | 0 | } |
630 | | |
631 | 0 | static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_ref_error(const zend_property_info *prop) { |
632 | 0 | zend_string *type_str = zend_type_to_string(prop->type); |
633 | 0 | zend_type_error( |
634 | 0 | "Cannot auto-initialize an array inside a reference held by property %s::$%s of type %s", |
635 | 0 | ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name), |
636 | 0 | ZSTR_VAL(type_str) |
637 | 0 | ); |
638 | 0 | zend_string_release(type_str); |
639 | 0 | } |
640 | | |
641 | | static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error( |
642 | 1 | const zend_property_info *prop) { |
643 | 1 | zend_throw_error(NULL, |
644 | 1 | "Cannot access uninitialized non-nullable property %s::$%s by reference", |
645 | 1 | ZSTR_VAL(prop->ce->name), |
646 | 1 | zend_get_unmangled_property_name(prop->name)); |
647 | 1 | } |
648 | | |
649 | | /* this should modify object only if it's empty */ |
650 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_error(const zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC) |
651 | 87 | { |
652 | 87 | zend_string *tmp_property_name; |
653 | 87 | zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name); |
654 | | |
655 | 87 | if (opline->opcode == ZEND_PRE_INC_OBJ |
656 | 86 | || opline->opcode == ZEND_PRE_DEC_OBJ |
657 | 86 | || opline->opcode == ZEND_POST_INC_OBJ |
658 | 84 | || opline->opcode == ZEND_POST_DEC_OBJ) { |
659 | 3 | zend_throw_error(NULL, |
660 | 3 | "Attempt to increment/decrement property \"%s\" on %s", |
661 | 3 | ZSTR_VAL(property_name), zend_zval_value_name(object) |
662 | 3 | ); |
663 | 84 | } else if (opline->opcode == ZEND_FETCH_OBJ_W |
664 | 66 | || opline->opcode == ZEND_FETCH_OBJ_RW |
665 | 63 | || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG |
666 | 63 | || opline->opcode == ZEND_ASSIGN_OBJ_REF) { |
667 | 29 | zend_throw_error(NULL, |
668 | 29 | "Attempt to modify property \"%s\" on %s", |
669 | 29 | ZSTR_VAL(property_name), zend_zval_value_name(object) |
670 | 29 | ); |
671 | 55 | } else { |
672 | 55 | zend_throw_error(NULL, |
673 | 55 | "Attempt to assign property \"%s\" on %s", |
674 | 55 | ZSTR_VAL(property_name), zend_zval_value_name(object) |
675 | 55 | ); |
676 | 55 | } |
677 | 87 | zend_tmp_string_release(tmp_property_name); |
678 | | |
679 | 87 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
680 | 56 | ZVAL_NULL(EX_VAR(opline->result.var)); |
681 | 56 | } |
682 | 87 | } |
683 | | |
684 | | static ZEND_COLD void zend_verify_type_error_common( |
685 | | const zend_function *zf, const zend_arg_info *arg_info, const zval *value, |
686 | | const char **fname, const char **fsep, const char **fclass, |
687 | | zend_string **need_msg, const char **given_kind) |
688 | 210 | { |
689 | 210 | *fname = ZSTR_VAL(zf->common.function_name); |
690 | 210 | if (zf->common.scope) { |
691 | 52 | *fsep = "::"; |
692 | 52 | *fclass = ZSTR_VAL(zf->common.scope->name); |
693 | 158 | } else { |
694 | 158 | *fsep = ""; |
695 | 158 | *fclass = ""; |
696 | 158 | } |
697 | | |
698 | 210 | *need_msg = zend_type_to_string_resolved(arg_info->type, zf->common.scope); |
699 | | |
700 | 210 | if (value) { |
701 | 190 | *given_kind = zend_zval_value_name(value); |
702 | 190 | } else { |
703 | 20 | *given_kind = "none"; |
704 | 20 | } |
705 | 210 | } |
706 | | |
707 | | ZEND_API ZEND_COLD void zend_verify_arg_error( |
708 | | const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, const zval *value) |
709 | 154 | { |
710 | 154 | const zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data; |
711 | 154 | const char *fname, *fsep, *fclass; |
712 | 154 | zend_string *need_msg; |
713 | 154 | const char *given_msg; |
714 | | |
715 | 154 | zend_verify_type_error_common( |
716 | 154 | zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg); |
717 | | |
718 | 154 | ZEND_ASSERT(zf->common.type == ZEND_USER_FUNCTION |
719 | 154 | && "Arginfo verification is not performed for internal functions"); |
720 | 154 | if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) { |
721 | 153 | zend_argument_type_error(arg_num, "must be of type %s, %s given, called in %s on line %d", |
722 | 153 | ZSTR_VAL(need_msg), given_msg, |
723 | 153 | ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno |
724 | 153 | ); |
725 | 153 | } else { |
726 | 1 | zend_argument_type_error(arg_num, |
727 | 1 | "must be of type %s, %s given", ZSTR_VAL(need_msg), given_msg); |
728 | 1 | } |
729 | | |
730 | 154 | zend_string_release(need_msg); |
731 | 154 | } |
732 | | |
733 | | static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg) |
734 | 571 | { |
735 | 571 | zend_long lval; |
736 | 571 | double dval; |
737 | 571 | zend_string *str; |
738 | 571 | bool bval; |
739 | | |
740 | | /* Type preference order: int -> float -> string -> bool */ |
741 | 571 | if (type_mask & MAY_BE_LONG) { |
742 | | /* For an int|float union type and string value, |
743 | | * determine chosen type by is_numeric_string() semantics. */ |
744 | 235 | if ((type_mask & MAY_BE_DOUBLE) && Z_TYPE_P(arg) == IS_STRING) { |
745 | 21 | uint8_t type = is_numeric_str_function(Z_STR_P(arg), &lval, &dval); |
746 | 21 | if (type == IS_LONG) { |
747 | 2 | zend_string_release(Z_STR_P(arg)); |
748 | 2 | ZVAL_LONG(arg, lval); |
749 | 2 | return true; |
750 | 2 | } |
751 | 19 | if (type == IS_DOUBLE) { |
752 | 6 | zend_string_release(Z_STR_P(arg)); |
753 | 6 | ZVAL_DOUBLE(arg, dval); |
754 | 6 | return true; |
755 | 6 | } |
756 | 214 | } else if (zend_parse_arg_long_weak(arg, &lval, 0)) { |
757 | 180 | zval_ptr_dtor(arg); |
758 | 180 | ZVAL_LONG(arg, lval); |
759 | 180 | return true; |
760 | 180 | } else if (UNEXPECTED(EG(exception))) { |
761 | 0 | return false; |
762 | 0 | } |
763 | 235 | } |
764 | 383 | if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) { |
765 | 11 | zval_ptr_dtor(arg); |
766 | 11 | ZVAL_DOUBLE(arg, dval); |
767 | 11 | return true; |
768 | 11 | } |
769 | 372 | if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str, 0)) { |
770 | | /* on success "arg" is converted to IS_STRING */ |
771 | 167 | return true; |
772 | 167 | } |
773 | 205 | if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) { |
774 | 0 | zval_ptr_dtor(arg); |
775 | 0 | ZVAL_BOOL(arg, bval); |
776 | 0 | return true; |
777 | 0 | } |
778 | 205 | return false; |
779 | 205 | } |
780 | | |
781 | | #if ZEND_DEBUG |
782 | 1.25k | static bool can_convert_to_string(const zval *zv) { |
783 | | /* We don't call cast_object here, because this check must be side-effect free. As this |
784 | | * is only used for a sanity check of arginfo/zpp consistency, it's okay if we accept |
785 | | * more than actually allowed here. */ |
786 | 1.25k | if (Z_TYPE_P(zv) == IS_OBJECT) { |
787 | 196 | return Z_OBJ_HT_P(zv)->cast_object != zend_std_cast_object_tostring |
788 | 196 | || Z_OBJCE_P(zv)->__tostring; |
789 | 196 | } |
790 | 1.06k | return Z_TYPE_P(zv) <= IS_STRING; |
791 | 1.25k | } |
792 | | |
793 | | /* Used to sanity-check internal arginfo types without performing any actual type conversions. */ |
794 | | static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask, const zval *arg) |
795 | 1.85k | { |
796 | 1.85k | zend_long lval; |
797 | 1.85k | double dval; |
798 | 1.85k | bool bval; |
799 | | |
800 | | /* Pass (uint32_t)-1 as arg_num to indicate to ZPP not to emit any deprecation notice, |
801 | | * this is needed because the version with side effects also uses 0 (e.g. for typed properties) */ |
802 | 1.85k | if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) { |
803 | 90 | return true; |
804 | 90 | } |
805 | 1.76k | if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) { |
806 | 7 | return true; |
807 | 7 | } |
808 | 1.75k | if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) { |
809 | 1.25k | return true; |
810 | 1.25k | } |
811 | 508 | if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) { |
812 | 423 | return true; |
813 | 423 | } |
814 | 85 | return false; |
815 | 508 | } |
816 | | #endif |
817 | | |
818 | | ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool strict, bool is_internal_arg) |
819 | 4.84k | { |
820 | 4.84k | if (UNEXPECTED(strict)) { |
821 | | /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */ |
822 | 65 | if (!(type_mask & MAY_BE_DOUBLE) || Z_TYPE_P(arg) != IS_LONG) { |
823 | 65 | return 0; |
824 | 65 | } |
825 | 4.77k | } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) { |
826 | | /* NULL may be accepted only by nullable hints (this is already checked). |
827 | | * As an exception for internal functions, null is allowed for scalar types in weak mode. */ |
828 | 2.38k | return is_internal_arg |
829 | 2.34k | && (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING)); |
830 | 2.38k | } |
831 | 2.39k | #if ZEND_DEBUG |
832 | 2.39k | if (is_internal_arg) { |
833 | 1.85k | return zend_verify_weak_scalar_type_hint_no_sideeffect(type_mask, arg); |
834 | 1.85k | } |
835 | 540 | #endif |
836 | 540 | return zend_verify_weak_scalar_type_hint(type_mask, arg); |
837 | 2.39k | } |
838 | | |
839 | | ZEND_COLD zend_never_inline void zend_verify_class_constant_type_error(const zend_class_constant *c, const zend_string *name, const zval *constant) |
840 | 2 | { |
841 | 2 | zend_string *type_str = zend_type_to_string(c->type); |
842 | | |
843 | 2 | zend_type_error("Cannot assign %s to class constant %s::%s of type %s", |
844 | 2 | zend_zval_type_name(constant), ZSTR_VAL(c->ce->name), ZSTR_VAL(name), ZSTR_VAL(type_str)); |
845 | | |
846 | 2 | zend_string_release(type_str); |
847 | 2 | } |
848 | | |
849 | | ZEND_COLD zend_never_inline void zend_verify_property_type_error(const zend_property_info *info, const zval *property) |
850 | 110 | { |
851 | 110 | zend_string *type_str; |
852 | | |
853 | | /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */ |
854 | 110 | if (EG(exception)) { |
855 | 1 | return; |
856 | 1 | } |
857 | | |
858 | 109 | type_str = zend_type_to_string(info->type); |
859 | 109 | zend_type_error("Cannot assign %s to property %s::$%s of type %s", |
860 | 109 | zend_zval_value_name(property), |
861 | 109 | ZSTR_VAL(info->ce->name), |
862 | 109 | zend_get_unmangled_property_name(info->name), |
863 | 109 | ZSTR_VAL(type_str)); |
864 | 109 | zend_string_release(type_str); |
865 | 109 | } |
866 | | |
867 | | ZEND_COLD zend_never_inline void zend_magic_get_property_type_inconsistency_error(const zend_property_info *info, const zval *property) |
868 | 1 | { |
869 | | /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */ |
870 | 1 | if (EG(exception)) { |
871 | 0 | return; |
872 | 0 | } |
873 | | |
874 | 1 | zend_string *type_str = zend_type_to_string(info->type); |
875 | 1 | zend_type_error("Value of type %s returned from %s::__get() must be compatible with unset property %s::$%s of type %s", |
876 | 1 | zend_zval_type_name(property), |
877 | 1 | ZSTR_VAL(info->ce->name), |
878 | 1 | ZSTR_VAL(info->ce->name), |
879 | 1 | zend_get_unmangled_property_name(info->name), |
880 | 1 | ZSTR_VAL(type_str)); |
881 | 1 | zend_string_release(type_str); |
882 | 1 | } |
883 | | |
884 | | ZEND_COLD void zend_match_unhandled_error(const zval *value) |
885 | 6 | { |
886 | 6 | zend_long max_len = EG(exception_string_param_max_len); |
887 | 6 | smart_str msg = {0}; |
888 | 6 | if ( |
889 | 6 | EG(exception_ignore_args) |
890 | 6 | || (Z_TYPE_P(value) == IS_STRING && max_len == 0) |
891 | 6 | || smart_str_append_zval(&msg, value, max_len) != SUCCESS |
892 | 6 | ) { |
893 | 0 | smart_str_appendl(&msg, "of type ", sizeof("of type ")-1); |
894 | 0 | smart_str_appends(&msg, zend_zval_type_name(value)); |
895 | 0 | } |
896 | 6 | smart_str_0(&msg); |
897 | | |
898 | 6 | zend_throw_exception_ex( |
899 | 6 | zend_ce_unhandled_match_error, 0, "Unhandled match case %s", ZSTR_VAL(msg.s)); |
900 | | |
901 | 6 | smart_str_free(&msg); |
902 | 6 | } |
903 | | |
904 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error( |
905 | 23 | const zend_property_info *info) { |
906 | 23 | zend_readonly_property_modification_error_ex( |
907 | 23 | ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name)); |
908 | 23 | } |
909 | | |
910 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex( |
911 | 23 | const char *class_name, const char *prop_name) { |
912 | 23 | zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", class_name, prop_name); |
913 | 23 | } |
914 | | |
915 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info) |
916 | 28 | { |
917 | 28 | zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s", |
918 | 28 | ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name)); |
919 | 28 | } |
920 | | |
921 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_invalid_class_constant_type_error(const uint8_t type) |
922 | 0 | { |
923 | 0 | zend_type_error("Cannot use value of type %s as class constant name", zend_get_type_by_const(type)); |
924 | 0 | } |
925 | | |
926 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_object_released_while_assigning_to_property_error(const zend_property_info *info) |
927 | 2 | { |
928 | 2 | zend_throw_error(NULL, "Object was released while assigning to property %s::$%s", |
929 | 2 | ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name)); |
930 | 2 | } |
931 | | |
932 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modification_error( |
933 | | const zend_property_info *prop_info, const char *operation |
934 | 105 | ) { |
935 | 105 | const zend_class_entry *scope; |
936 | 105 | if (EG(fake_scope)) { |
937 | 6 | scope = EG(fake_scope); |
938 | 99 | } else { |
939 | 99 | scope = zend_get_called_scope(EG(current_execute_data)); |
940 | 99 | } |
941 | | |
942 | 105 | const char *visibility; |
943 | 105 | if (prop_info->flags & ZEND_ACC_PRIVATE_SET) { |
944 | 99 | visibility = "private(set)"; |
945 | 99 | } else { |
946 | 6 | ZEND_ASSERT(prop_info->flags & ZEND_ACC_PROTECTED_SET); |
947 | 6 | if (prop_info->flags & ZEND_ACC_READONLY) { |
948 | 6 | visibility = "protected(set) readonly"; |
949 | 6 | } else { |
950 | 0 | visibility = "protected(set)"; |
951 | 0 | } |
952 | 6 | } |
953 | | |
954 | 105 | zend_throw_error(NULL, "Cannot %s %s property %s::$%s from %s%s", |
955 | 105 | operation, |
956 | 105 | visibility, |
957 | 105 | ZSTR_VAL(prop_info->ce->name), |
958 | 105 | ZSTR_VAL(prop_info->name), |
959 | 105 | scope ? "scope " : "global scope", scope ? ZSTR_VAL(scope->name) : ""); |
960 | 105 | } |
961 | | |
962 | 16 | static const zend_class_entry *resolve_single_class_type(zend_string *name, const zend_class_entry *self_ce) { |
963 | 16 | if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) { |
964 | 0 | return self_ce; |
965 | 16 | } else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT))) { |
966 | 0 | return self_ce->parent; |
967 | 16 | } else { |
968 | 16 | return zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); |
969 | 16 | } |
970 | 16 | } |
971 | | |
972 | | static zend_always_inline const zend_class_entry *zend_ce_from_type( |
973 | 104k | const zend_class_entry *scope, const zend_type *type) { |
974 | 104k | ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type)); |
975 | 104k | zend_string *name = ZEND_TYPE_NAME(*type); |
976 | 104k | if (ZSTR_HAS_CE_CACHE(name)) { |
977 | 104k | zend_class_entry *ce = ZSTR_GET_CE_CACHE(name); |
978 | 104k | if (!ce) { |
979 | 960 | ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); |
980 | 960 | } |
981 | 104k | return ce; |
982 | 104k | } |
983 | 16 | return resolve_single_class_type(name, scope); |
984 | 104k | } |
985 | | |
986 | | static bool zend_check_intersection_for_property_or_class_constant_class_type( |
987 | | const zend_class_entry *scope, const zend_type_list *intersection_type_list, const zend_class_entry *value_ce) |
988 | 24 | { |
989 | 24 | const zend_type *list_type; |
990 | | |
991 | 60 | ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) { |
992 | 60 | ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type)); |
993 | 60 | const zend_class_entry *ce = zend_ce_from_type(scope, list_type); |
994 | 36 | if (!ce || !instanceof_function(value_ce, ce)) { |
995 | 12 | return false; |
996 | 12 | } |
997 | 36 | } ZEND_TYPE_LIST_FOREACH_END(); |
998 | 12 | return true; |
999 | 24 | } |
1000 | | |
1001 | | static bool zend_check_and_resolve_property_or_class_constant_class_type( |
1002 | 104k | const zend_class_entry *scope, const zend_type member_type, const zend_class_entry *value_ce) { |
1003 | 104k | if (ZEND_TYPE_HAS_LIST(member_type)) { |
1004 | 31 | if (ZEND_TYPE_IS_INTERSECTION(member_type)) { |
1005 | 0 | return zend_check_intersection_for_property_or_class_constant_class_type( |
1006 | 0 | scope, ZEND_TYPE_LIST(member_type), value_ce); |
1007 | 31 | } else { |
1008 | 31 | const zend_type *list_type; |
1009 | 69 | ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(member_type), list_type) { |
1010 | 69 | if (ZEND_TYPE_IS_INTERSECTION(*list_type)) { |
1011 | 24 | if (zend_check_intersection_for_property_or_class_constant_class_type( |
1012 | 24 | scope, ZEND_TYPE_LIST(*list_type), value_ce)) { |
1013 | 12 | return true; |
1014 | 12 | } |
1015 | 12 | continue; |
1016 | 24 | } |
1017 | 14 | ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type)); |
1018 | 14 | const zend_class_entry *ce = zend_ce_from_type(scope, list_type); |
1019 | 14 | if (ce && instanceof_function(value_ce, ce)) { |
1020 | 7 | return true; |
1021 | 7 | } |
1022 | 14 | } ZEND_TYPE_LIST_FOREACH_END(); |
1023 | | |
1024 | 12 | if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC)) { |
1025 | 0 | return value_ce == scope; |
1026 | 0 | } |
1027 | | |
1028 | 12 | return false; |
1029 | 12 | } |
1030 | 104k | } else if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC) && value_ce == scope) { |
1031 | 0 | return true; |
1032 | 104k | } else if (ZEND_TYPE_HAS_NAME(member_type)) { |
1033 | 104k | const zend_class_entry *ce = zend_ce_from_type(scope, &member_type); |
1034 | 104k | return ce && instanceof_function(value_ce, ce); |
1035 | 104k | } |
1036 | | |
1037 | 1 | return false; |
1038 | 104k | } |
1039 | | |
1040 | | static zend_always_inline bool i_zend_check_property_type(const zend_property_info *info, zval *property, bool strict) |
1041 | 146k | { |
1042 | 146k | ZEND_ASSERT(!Z_ISREF_P(property)); |
1043 | 146k | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) { |
1044 | 54.9k | return 1; |
1045 | 54.9k | } |
1046 | | |
1047 | 91.4k | if (ZEND_TYPE_IS_COMPLEX(info->type) && Z_TYPE_P(property) == IS_OBJECT |
1048 | 91.0k | && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(property))) { |
1049 | 91.0k | return 1; |
1050 | 91.0k | } |
1051 | | |
1052 | 410 | uint32_t type_mask = ZEND_TYPE_FULL_MASK(info->type); |
1053 | 410 | ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC|MAY_BE_NEVER|MAY_BE_VOID))); |
1054 | 410 | return zend_verify_scalar_type_hint(type_mask, property, strict, false); |
1055 | 410 | } |
1056 | | |
1057 | | static zend_always_inline bool i_zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) |
1058 | 15.1k | { |
1059 | 15.1k | if (i_zend_check_property_type(info, property, strict)) { |
1060 | 15.0k | return 1; |
1061 | 15.0k | } |
1062 | | |
1063 | 79 | zend_verify_property_type_error(info, property); |
1064 | 79 | return 0; |
1065 | 15.1k | } |
1066 | | |
1067 | 14.7k | ZEND_API bool zend_never_inline zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) { |
1068 | 14.7k | return i_zend_verify_property_type(info, property, strict); |
1069 | 14.7k | } |
1070 | | |
1071 | | static zend_never_inline zval* zend_assign_to_typed_prop(const zend_property_info *info, zval *property_val, zval *value, zend_refcounted **garbage_ptr EXECUTE_DATA_DC) |
1072 | 406 | { |
1073 | 406 | zval tmp; |
1074 | | |
1075 | 406 | if (UNEXPECTED(info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) { |
1076 | 36 | if ((info->flags & ZEND_ACC_READONLY) && !(Z_PROP_FLAG_P(property_val) & IS_PROP_REINITABLE)) { |
1077 | 6 | zend_readonly_property_modification_error(info); |
1078 | 6 | return &EG(uninitialized_zval); |
1079 | 6 | } |
1080 | 30 | if (info->flags & ZEND_ACC_PPP_SET_MASK && !zend_asymmetric_property_has_set_access(info)) { |
1081 | 6 | zend_asymmetric_visibility_property_modification_error(info, "modify"); |
1082 | 6 | return &EG(uninitialized_zval); |
1083 | 6 | } |
1084 | 30 | } |
1085 | | |
1086 | 394 | ZVAL_DEREF(value); |
1087 | 394 | ZVAL_COPY(&tmp, value); |
1088 | | |
1089 | 394 | if (UNEXPECTED(!i_zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) { |
1090 | 1 | zval_ptr_dtor(&tmp); |
1091 | 1 | return &EG(uninitialized_zval); |
1092 | 1 | } |
1093 | | |
1094 | 393 | Z_PROP_FLAG_P(property_val) &= ~IS_PROP_REINITABLE; |
1095 | | |
1096 | 393 | return zend_assign_to_variable_ex(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr); |
1097 | 394 | } |
1098 | | |
1099 | 10 | static zend_always_inline bool zend_value_instanceof_static(const zval *zv) { |
1100 | 10 | if (Z_TYPE_P(zv) != IS_OBJECT) { |
1101 | 0 | return 0; |
1102 | 0 | } |
1103 | | |
1104 | 10 | zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data)); |
1105 | 10 | if (!called_scope) { |
1106 | 0 | return 0; |
1107 | 0 | } |
1108 | 10 | return instanceof_function(Z_OBJCE_P(zv), called_scope); |
1109 | 10 | } |
1110 | | |
1111 | | static zend_always_inline zend_class_entry *zend_fetch_ce_from_type( |
1112 | | const zend_type *type) |
1113 | 11.4k | { |
1114 | 11.4k | zend_string *name = ZEND_TYPE_NAME(*type); |
1115 | 11.4k | zend_class_entry *ce; |
1116 | 11.4k | if (ZSTR_HAS_CE_CACHE(name)) { |
1117 | 11.4k | ce = ZSTR_GET_CE_CACHE(name); |
1118 | 11.4k | if (!ce) { |
1119 | 2.38k | ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); |
1120 | 2.38k | if (UNEXPECTED(!ce)) { |
1121 | | /* Cannot resolve */ |
1122 | 12 | return NULL; |
1123 | 12 | } |
1124 | 2.38k | } |
1125 | 11.4k | } else { |
1126 | 18 | ce = zend_fetch_class(name, |
1127 | 18 | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT); |
1128 | 18 | if (UNEXPECTED(!ce)) { |
1129 | 0 | return NULL; |
1130 | 0 | } |
1131 | 18 | } |
1132 | 11.4k | return ce; |
1133 | 11.4k | } |
1134 | | |
1135 | | static bool zend_check_intersection_type_from_list( |
1136 | | const zend_type_list *intersection_type_list, |
1137 | | zend_class_entry *arg_ce) |
1138 | 84 | { |
1139 | 84 | zend_class_entry *ce; |
1140 | 84 | const zend_type *list_type; |
1141 | 216 | ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) { |
1142 | 216 | ce = zend_fetch_ce_from_type(list_type); |
1143 | | /* If type is not an instance of one of the types taking part in the |
1144 | | * intersection it cannot be a valid instance of the whole intersection type. */ |
1145 | 216 | if (!ce || !instanceof_function(arg_ce, ce)) { |
1146 | 48 | return false; |
1147 | 48 | } |
1148 | 216 | } ZEND_TYPE_LIST_FOREACH_END(); |
1149 | 36 | return true; |
1150 | 84 | } |
1151 | | |
1152 | | static zend_always_inline bool zend_check_type_slow( |
1153 | | const zend_type *type, zval *arg, const zend_reference *ref, |
1154 | | bool is_return_type, bool is_internal) |
1155 | 17.3k | { |
1156 | 17.3k | if (ZEND_TYPE_IS_COMPLEX(*type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) { |
1157 | 11.3k | zend_class_entry *ce; |
1158 | 11.3k | if (UNEXPECTED(ZEND_TYPE_HAS_LIST(*type))) { |
1159 | 96 | if (ZEND_TYPE_IS_INTERSECTION(*type)) { |
1160 | 0 | return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), Z_OBJCE_P(arg)); |
1161 | 96 | } else { |
1162 | 96 | const zend_type *list_type; |
1163 | 246 | ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) { |
1164 | 246 | if (ZEND_TYPE_IS_INTERSECTION(*list_type)) { |
1165 | 84 | if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), Z_OBJCE_P(arg))) { |
1166 | 36 | return true; |
1167 | 36 | } |
1168 | 84 | } else { |
1169 | 66 | ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type)); |
1170 | 66 | ce = zend_fetch_ce_from_type(list_type); |
1171 | | /* Instance of a single type part of a union is sufficient to pass the type check */ |
1172 | 66 | if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) { |
1173 | 24 | return true; |
1174 | 24 | } |
1175 | 66 | } |
1176 | 246 | } ZEND_TYPE_LIST_FOREACH_END(); |
1177 | 96 | } |
1178 | 11.2k | } else { |
1179 | 11.2k | ce = zend_fetch_ce_from_type(type); |
1180 | | /* If we have a CE we check if it satisfies the type constraint, |
1181 | | * otherwise it will check if a standard type satisfies it. */ |
1182 | 11.2k | if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) { |
1183 | 11.2k | return true; |
1184 | 11.2k | } |
1185 | 11.2k | } |
1186 | 11.3k | } |
1187 | | |
1188 | 6.08k | const uint32_t type_mask = ZEND_TYPE_FULL_MASK(*type); |
1189 | 6.08k | if ((type_mask & MAY_BE_CALLABLE) && |
1190 | 1.72k | zend_is_callable(arg, is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0, NULL)) { |
1191 | 1.64k | return 1; |
1192 | 1.64k | } |
1193 | 4.43k | if ((type_mask & MAY_BE_STATIC) && zend_value_instanceof_static(arg)) { |
1194 | 10 | return 1; |
1195 | 10 | } |
1196 | 4.42k | if (ref && ZEND_REF_HAS_TYPE_SOURCES(ref)) { |
1197 | | /* We cannot have conversions for typed refs. */ |
1198 | 0 | return 0; |
1199 | 0 | } |
1200 | 4.42k | if (is_internal && is_return_type) { |
1201 | | /* For internal returns, the type has to match exactly, because we're not |
1202 | | * going to check it for non-debug builds, and there will be no chance to |
1203 | | * apply coercions. */ |
1204 | 0 | return 0; |
1205 | 0 | } |
1206 | | |
1207 | 4.42k | return zend_verify_scalar_type_hint(type_mask, arg, |
1208 | 4.42k | is_return_type ? ZEND_RET_USES_STRICT_TYPES() : ZEND_ARG_USES_STRICT_TYPES(), |
1209 | 4.42k | is_internal); |
1210 | | |
1211 | | /* Special handling for IS_VOID is not necessary (for return types), |
1212 | | * because this case is already checked at compile-time. */ |
1213 | 4.42k | } |
1214 | | |
1215 | | static zend_always_inline bool zend_check_type( |
1216 | | const zend_type *type, zval *arg, zend_class_entry *scope, |
1217 | | bool is_return_type, bool is_internal) |
1218 | 1.33M | { |
1219 | 1.33M | const zend_reference *ref = NULL; |
1220 | 1.33M | ZEND_ASSERT(ZEND_TYPE_IS_SET(*type)); |
1221 | | |
1222 | 1.33M | if (UNEXPECTED(Z_ISREF_P(arg))) { |
1223 | 1.19k | ref = Z_REF_P(arg); |
1224 | 1.19k | arg = Z_REFVAL_P(arg); |
1225 | 1.19k | } |
1226 | | |
1227 | 1.33M | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(*type, Z_TYPE_P(arg)))) { |
1228 | 1.31M | return 1; |
1229 | 1.31M | } |
1230 | | |
1231 | 17.2k | return zend_check_type_slow(type, arg, ref, is_return_type, is_internal); |
1232 | 1.33M | } |
1233 | | |
1234 | | ZEND_API bool zend_check_user_type_slow( |
1235 | | const zend_type *type, zval *arg, const zend_reference *ref, bool is_return_type) |
1236 | 0 | { |
1237 | 0 | return zend_check_type_slow( |
1238 | 0 | type, arg, ref, is_return_type, /* is_internal */ false); |
1239 | 0 | } |
1240 | | |
1241 | | static zend_always_inline bool zend_verify_recv_arg_type(const zend_function *zf, uint32_t arg_num, zval *arg) |
1242 | 767 | { |
1243 | 767 | const zend_arg_info *cur_arg_info; |
1244 | | |
1245 | 767 | ZEND_ASSERT(arg_num <= zf->common.num_args); |
1246 | 767 | cur_arg_info = &zf->common.arg_info[arg_num-1]; |
1247 | | |
1248 | 767 | if (ZEND_TYPE_IS_SET(cur_arg_info->type) |
1249 | 767 | && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, zf->common.scope, false, false))) { |
1250 | 150 | zend_verify_arg_error(zf, cur_arg_info, arg_num, arg); |
1251 | 150 | return 0; |
1252 | 150 | } |
1253 | | |
1254 | 617 | return 1; |
1255 | 767 | } |
1256 | | |
1257 | | static zend_always_inline bool zend_verify_variadic_arg_type( |
1258 | | const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, zval *arg) |
1259 | 14 | { |
1260 | 14 | ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type)); |
1261 | 14 | if (UNEXPECTED(!zend_check_type(&arg_info->type, arg, zf->common.scope, false, false))) { |
1262 | 4 | zend_verify_arg_error(zf, arg_info, arg_num, arg); |
1263 | 4 | return 0; |
1264 | 4 | } |
1265 | | |
1266 | 10 | return 1; |
1267 | 14 | } |
1268 | | |
1269 | | static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_types(const zend_function *fbc, zend_execute_data *call) |
1270 | 989k | { |
1271 | 989k | uint32_t i; |
1272 | 989k | uint32_t num_args = ZEND_CALL_NUM_ARGS(call); |
1273 | 989k | zval *arg = ZEND_CALL_ARG(call, 1); |
1274 | | |
1275 | 2.19M | for (i = 0; i < num_args; ++i) { |
1276 | 1.20M | zend_arg_info *cur_arg_info; |
1277 | 1.20M | if (EXPECTED(i < fbc->common.num_args)) { |
1278 | 1.20M | cur_arg_info = &fbc->common.arg_info[i]; |
1279 | 1.20M | } else if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) { |
1280 | 1.02k | cur_arg_info = &fbc->common.arg_info[fbc->common.num_args]; |
1281 | 1.02k | } else { |
1282 | 0 | break; |
1283 | 0 | } |
1284 | | |
1285 | 1.20M | if (ZEND_TYPE_IS_SET(cur_arg_info->type) |
1286 | 1.20M | && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, fbc->common.scope, false, /* is_internal */ true))) { |
1287 | 108 | return 0; |
1288 | 108 | } |
1289 | 1.20M | arg++; |
1290 | 1.20M | } |
1291 | 989k | return 1; |
1292 | 989k | } |
1293 | | |
1294 | | #if ZEND_DEBUG |
1295 | | /* Determine whether an internal call should throw, because the passed arguments violate |
1296 | | * an arginfo constraint. This is only checked in debug builds. In release builds, we |
1297 | | * trust that arginfo matches what is enforced by zend_parse_parameters. */ |
1298 | | ZEND_API bool zend_internal_call_should_throw(const zend_function *fbc, zend_execute_data *call) |
1299 | 1.07M | { |
1300 | 1.07M | if (fbc->internal_function.handler == ZEND_FN(pass) || (fbc->internal_function.fn_flags & ZEND_ACC_FAKE_CLOSURE)) { |
1301 | | /* Be lenient about the special pass function and about fake closures. */ |
1302 | 75 | return 0; |
1303 | 75 | } |
1304 | | |
1305 | 1.07M | if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) { |
1306 | | /* Required argument not passed. */ |
1307 | 137 | return 1; |
1308 | 137 | } |
1309 | | |
1310 | 1.06M | if (fbc->common.num_args < ZEND_CALL_NUM_ARGS(call) |
1311 | 777 | && !(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) { |
1312 | | /* Too many arguments passed. For internal functions (unlike userland functions), |
1313 | | * this should always throw. */ |
1314 | 19 | return 1; |
1315 | 19 | } |
1316 | | |
1317 | 1.06M | if ((fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && |
1318 | 989k | !zend_verify_internal_arg_types(fbc, call)) { |
1319 | 108 | return 1; |
1320 | 108 | } |
1321 | | |
1322 | 1.06M | return 0; |
1323 | 1.06M | } |
1324 | | |
1325 | | ZEND_API ZEND_COLD void zend_internal_call_arginfo_violation(const zend_function *fbc) |
1326 | 0 | { |
1327 | 0 | zend_error_noreturn(E_ERROR, "Arginfo / zpp mismatch during call of %s%s%s()", |
1328 | 0 | fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "", |
1329 | 0 | fbc->common.scope ? "::" : "", |
1330 | 0 | ZSTR_VAL(fbc->common.function_name)); |
1331 | 0 | } |
1332 | | |
1333 | | #ifndef ZEND_VERIFY_FUNC_INFO |
1334 | | # define ZEND_VERIFY_FUNC_INFO 0 |
1335 | | #endif |
1336 | | |
1337 | 217k | static void zend_verify_internal_func_info(const zend_function *fn, const zval *retval) { |
1338 | | #if ZEND_VERIFY_FUNC_INFO |
1339 | | zend_string *name = fn->common.function_name; |
1340 | | const uint32_t type_mask = zend_get_internal_func_info(fn, NULL, NULL); |
1341 | | if (!type_mask) { |
1342 | | return; |
1343 | | } |
1344 | | |
1345 | | /* Always check refcount of arrays, as immutable arrays are RCN. */ |
1346 | | if (Z_REFCOUNTED_P(retval) || Z_TYPE_P(retval) == IS_ARRAY) { |
1347 | | if (!(type_mask & MAY_BE_RC1)) { |
1348 | | zend_error_noreturn(E_CORE_ERROR, "%s() missing rc1", ZSTR_VAL(name)); |
1349 | | } |
1350 | | if (Z_REFCOUNT_P(retval) > 1 && !(type_mask & MAY_BE_RCN)) { |
1351 | | zend_error_noreturn(E_CORE_ERROR, "%s() missing rcn", ZSTR_VAL(name)); |
1352 | | } |
1353 | | } |
1354 | | |
1355 | | const uint32_t type = 1u << Z_TYPE_P(retval); |
1356 | | if (!(type_mask & type)) { |
1357 | | zend_error_noreturn(E_CORE_ERROR, "%s() missing type %s", |
1358 | | ZSTR_VAL(name), zend_get_type_by_const(Z_TYPE_P(retval))); |
1359 | | } |
1360 | | |
1361 | | if (Z_TYPE_P(retval) == IS_ARRAY) { |
1362 | | const HashTable *ht = Z_ARRVAL_P(retval); |
1363 | | uint32_t num_checked = 0; |
1364 | | zend_string *str; |
1365 | | zval *val; |
1366 | | ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) { |
1367 | | if (str) { |
1368 | | if (!(type_mask & MAY_BE_ARRAY_KEY_STRING)) { |
1369 | | zend_error_noreturn(E_CORE_ERROR, |
1370 | | "%s() missing array_key_string", ZSTR_VAL(name)); |
1371 | | } |
1372 | | } else { |
1373 | | if (!(type_mask & MAY_BE_ARRAY_KEY_LONG)) { |
1374 | | zend_error_noreturn(E_CORE_ERROR, |
1375 | | "%s() missing array_key_long", ZSTR_VAL(name)); |
1376 | | } |
1377 | | } |
1378 | | |
1379 | | const uint32_t array_type = 1u << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT); |
1380 | | if (!(type_mask & array_type)) { |
1381 | | zend_error_noreturn(E_CORE_ERROR, |
1382 | | "%s() missing array element type %s", |
1383 | | ZSTR_VAL(name), zend_get_type_by_const(Z_TYPE_P(retval))); |
1384 | | } |
1385 | | |
1386 | | /* Don't check all elements of large arrays. */ |
1387 | | if (++num_checked > 16) { |
1388 | | break; |
1389 | | } |
1390 | | } ZEND_HASH_FOREACH_END(); |
1391 | | } |
1392 | | #endif |
1393 | 217k | } |
1394 | | #endif |
1395 | | |
1396 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(const zend_execute_data *execute_data) |
1397 | 12 | { |
1398 | 12 | const zend_execute_data *ptr = EX(prev_execute_data); |
1399 | | |
1400 | 12 | if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) { |
1401 | 12 | zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed in %s on line %d and %s %d expected", |
1402 | 12 | EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "", |
1403 | 12 | EX(func)->common.scope ? "::" : "", |
1404 | 12 | ZSTR_VAL(EX(func)->common.function_name), |
1405 | 12 | EX_NUM_ARGS(), |
1406 | 12 | ZSTR_VAL(ptr->func->op_array.filename), |
1407 | 12 | ptr->opline->lineno, |
1408 | 12 | EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least", |
1409 | 12 | EX(func)->common.required_num_args); |
1410 | 12 | } else { |
1411 | 0 | zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed and %s %d expected", |
1412 | 0 | EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "", |
1413 | 0 | EX(func)->common.scope ? "::" : "", |
1414 | 0 | ZSTR_VAL(EX(func)->common.function_name), |
1415 | 0 | EX_NUM_ARGS(), |
1416 | 0 | EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least", |
1417 | 0 | EX(func)->common.required_num_args); |
1418 | 0 | } |
1419 | 12 | } |
1420 | | |
1421 | | ZEND_API ZEND_COLD void zend_verify_return_error(const zend_function *zf, const zval *value) |
1422 | 56 | { |
1423 | 56 | const zend_arg_info *arg_info = &zf->common.arg_info[-1]; |
1424 | 56 | const char *fname, *fsep, *fclass; |
1425 | 56 | zend_string *need_msg; |
1426 | 56 | const char *given_msg; |
1427 | | |
1428 | 56 | zend_verify_type_error_common( |
1429 | 56 | zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg); |
1430 | | |
1431 | 56 | zend_type_error("%s%s%s(): Return value must be of type %s, %s returned", |
1432 | 56 | fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg); |
1433 | | |
1434 | 56 | zend_string_release(need_msg); |
1435 | 56 | } |
1436 | | |
1437 | | ZEND_API ZEND_COLD void zend_verify_never_error(const zend_function *zf) |
1438 | 1 | { |
1439 | 1 | zend_string *func_name = get_function_or_method_name(zf); |
1440 | | |
1441 | 1 | zend_type_error("%s(): never-returning %s must not implicitly return", |
1442 | 1 | ZSTR_VAL(func_name), zf->common.scope ? "method" : "function"); |
1443 | | |
1444 | 1 | zend_string_release(func_name); |
1445 | 1 | } |
1446 | | |
1447 | | #if ZEND_DEBUG |
1448 | | static ZEND_COLD void zend_verify_internal_return_error(const zend_function *zf, const zval *value) |
1449 | 0 | { |
1450 | 0 | const zend_arg_info *arg_info = &zf->common.arg_info[-1]; |
1451 | 0 | const char *fname, *fsep, *fclass; |
1452 | 0 | zend_string *need_msg; |
1453 | 0 | const char *given_msg; |
1454 | |
|
1455 | 0 | zend_verify_type_error_common( |
1456 | 0 | zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg); |
1457 | |
|
1458 | 0 | zend_error_noreturn(E_CORE_ERROR, "%s%s%s(): Return value must be of type %s, %s returned", |
1459 | 0 | fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg); |
1460 | 0 | } |
1461 | | |
1462 | | static ZEND_COLD void zend_verify_void_return_error(const zend_function *zf, const char *returned_msg, const char *returned_kind) |
1463 | 0 | { |
1464 | 0 | const char *fname = ZSTR_VAL(zf->common.function_name); |
1465 | 0 | const char *fsep; |
1466 | 0 | const char *fclass; |
1467 | |
|
1468 | 0 | if (zf->common.scope) { |
1469 | 0 | fsep = "::"; |
1470 | 0 | fclass = ZSTR_VAL(zf->common.scope->name); |
1471 | 0 | } else { |
1472 | 0 | fsep = ""; |
1473 | 0 | fclass = ""; |
1474 | 0 | } |
1475 | |
|
1476 | 0 | zend_type_error("%s%s%s() must not return a value, %s%s returned", |
1477 | 0 | fclass, fsep, fname, returned_msg, returned_kind); |
1478 | 0 | } |
1479 | | |
1480 | | ZEND_API bool zend_verify_internal_return_type(const zend_function *zf, zval *ret) |
1481 | 753k | { |
1482 | 753k | const zend_arg_info *ret_info = zf->internal_function.arg_info - 1; |
1483 | | |
1484 | 753k | if (ZEND_TYPE_FULL_MASK(ret_info->type) & MAY_BE_VOID) { |
1485 | 625k | if (UNEXPECTED(Z_TYPE_P(ret) != IS_NULL)) { |
1486 | 0 | zend_verify_void_return_error(zf, zend_zval_value_name(ret), ""); |
1487 | 0 | return 0; |
1488 | 0 | } |
1489 | 625k | return 1; |
1490 | 625k | } |
1491 | | |
1492 | 128k | if (UNEXPECTED(!zend_check_type(&ret_info->type, ret, NULL, true, /* is_internal */ true))) { |
1493 | 0 | zend_verify_internal_return_error(zf, ret); |
1494 | 0 | return 0; |
1495 | 0 | } |
1496 | | |
1497 | 128k | return 1; |
1498 | 128k | } |
1499 | | #endif |
1500 | | |
1501 | | static ZEND_COLD void zend_verify_missing_return_type(const zend_function *zf) |
1502 | 20 | { |
1503 | | /* VERIFY_RETURN_TYPE is not emitted for "void" functions, so this is always an error. */ |
1504 | 20 | zend_verify_return_error(zf, NULL); |
1505 | 20 | } |
1506 | | |
1507 | | static zend_always_inline bool zend_check_class_constant_type(const zend_class_constant *c, zval *constant) |
1508 | 4 | { |
1509 | 4 | ZEND_ASSERT(!Z_ISREF_P(constant)); |
1510 | 4 | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(c->type, Z_TYPE_P(constant)))) { |
1511 | 0 | return 1; |
1512 | 0 | } |
1513 | | |
1514 | 4 | if (((ZEND_TYPE_PURE_MASK(c->type) & MAY_BE_STATIC) || ZEND_TYPE_IS_COMPLEX(c->type)) && Z_TYPE_P(constant) == IS_OBJECT |
1515 | 3 | && zend_check_and_resolve_property_or_class_constant_class_type(c->ce, c->type, Z_OBJCE_P(constant))) { |
1516 | 2 | return 1; |
1517 | 2 | } |
1518 | | |
1519 | 2 | uint32_t type_mask = ZEND_TYPE_FULL_MASK(c->type); |
1520 | 2 | ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_NEVER|MAY_BE_VOID))); |
1521 | 2 | return zend_verify_scalar_type_hint(type_mask, constant, true, false); |
1522 | 2 | } |
1523 | | |
1524 | | ZEND_API bool zend_never_inline zend_verify_class_constant_type(const zend_class_constant *c, const zend_string *name, zval *constant) |
1525 | 4 | { |
1526 | 4 | if (!zend_check_class_constant_type(c, constant)) { |
1527 | 2 | zend_verify_class_constant_type_error(c, name, constant); |
1528 | 2 | return 0; |
1529 | 2 | } |
1530 | | |
1531 | 2 | return 1; |
1532 | 4 | } |
1533 | | |
1534 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(const zend_object *object) |
1535 | 0 | { |
1536 | 0 | zend_throw_error(NULL, "Cannot use object of type %s as array", ZSTR_VAL(object->ce->name)); |
1537 | 0 | } |
1538 | | |
1539 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_access(const zval *offset) |
1540 | 45 | { |
1541 | 45 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_RW); |
1542 | 45 | } |
1543 | | |
1544 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_isset(const zval *offset) |
1545 | 0 | { |
1546 | 0 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_IS); |
1547 | 0 | } |
1548 | | |
1549 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_unset(const zval *offset) |
1550 | 0 | { |
1551 | 0 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); |
1552 | 0 | } |
1553 | | |
1554 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset, int type) |
1555 | 47 | { |
1556 | 47 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, type); |
1557 | 47 | } |
1558 | | |
1559 | | static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) |
1560 | 487 | { |
1561 | 487 | obj->handlers->write_dimension(obj, dim, value); |
1562 | | |
1563 | 487 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
1564 | 15 | ZVAL_COPY(EX_VAR(opline->result.var), value); |
1565 | 15 | } |
1566 | 487 | } |
1567 | | |
1568 | | static void frameless_observed_call_copy(zend_execute_data *call, uint32_t arg, zval *zv) |
1569 | 0 | { |
1570 | 0 | if (Z_ISUNDEF_P(zv)) { |
1571 | 0 | ZVAL_NULL(ZEND_CALL_VAR_NUM(call, arg)); |
1572 | 0 | } else { |
1573 | 0 | ZVAL_COPY_DEREF(ZEND_CALL_VAR_NUM(call, arg), zv); |
1574 | 0 | } |
1575 | 0 | } |
1576 | | |
1577 | | ZEND_API void zend_frameless_observed_call(zend_execute_data *execute_data) |
1578 | 0 | { |
1579 | 0 | const zend_op *opline = EX(opline); |
1580 | 0 | uint8_t num_args = ZEND_FLF_NUM_ARGS(opline->opcode); |
1581 | 0 | zend_function *fbc = ZEND_FLF_FUNC(opline); |
1582 | 0 | zval *result = EX_VAR(opline->result.var); |
1583 | |
|
1584 | 0 | zend_execute_data *call = zend_vm_stack_push_call_frame_ex(zend_vm_calc_used_stack(num_args, fbc), ZEND_CALL_NESTED_FUNCTION, fbc, num_args, NULL); |
1585 | 0 | call->prev_execute_data = execute_data; |
1586 | |
|
1587 | 0 | switch (num_args) { |
1588 | 0 | case 3: frameless_observed_call_copy(call, 2, zend_get_zval_ptr(opline+1, (opline+1)->op1_type, &(opline+1)->op1, execute_data)); ZEND_FALLTHROUGH; |
1589 | 0 | case 2: frameless_observed_call_copy(call, 1, zend_get_zval_ptr(opline, opline->op2_type, &opline->op2, execute_data)); ZEND_FALLTHROUGH; |
1590 | 0 | case 1: frameless_observed_call_copy(call, 0, zend_get_zval_ptr(opline, opline->op1_type, &opline->op1, execute_data)); |
1591 | 0 | } |
1592 | |
|
1593 | 0 | EG(current_execute_data) = call; |
1594 | |
|
1595 | 0 | zend_observer_fcall_begin_prechecked(call, ZEND_OBSERVER_DATA(fbc)); |
1596 | 0 | fbc->internal_function.handler(call, result); |
1597 | 0 | zend_observer_fcall_end(call, result); |
1598 | |
|
1599 | 0 | EG(current_execute_data) = execute_data; |
1600 | |
|
1601 | 0 | if (UNEXPECTED(EG(exception) != NULL)) { |
1602 | 0 | zend_rethrow_exception(execute_data); |
1603 | 0 | } |
1604 | |
|
1605 | 0 | zend_vm_stack_free_args(call); |
1606 | |
|
1607 | 0 | uint32_t call_info = ZEND_CALL_INFO(call); |
1608 | 0 | if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) { |
1609 | 0 | zend_vm_stack_free_call_frame_ex(call_info, call); |
1610 | 0 | } else { |
1611 | 0 | EG(vm_stack_top) = (zval*)call; |
1612 | 0 | } |
1613 | 0 | } |
1614 | | |
1615 | | |
1616 | | static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPLINE_DC) |
1617 | 867k | { |
1618 | 867k | static const binary_op_type zend_binary_ops[] = { |
1619 | 867k | add_function, |
1620 | 867k | sub_function, |
1621 | 867k | mul_function, |
1622 | 867k | div_function, |
1623 | 867k | mod_function, |
1624 | 867k | shift_left_function, |
1625 | 867k | shift_right_function, |
1626 | 867k | concat_function, |
1627 | 867k | bitwise_or_function, |
1628 | 867k | bitwise_and_function, |
1629 | 867k | bitwise_xor_function, |
1630 | 867k | pow_function |
1631 | 867k | }; |
1632 | | /* size_t cast makes GCC to better optimize 64-bit PIC code */ |
1633 | 867k | size_t opcode = (size_t)opline->extended_value; |
1634 | | |
1635 | 867k | return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2); |
1636 | 867k | } |
1637 | | |
1638 | | static zend_never_inline void zend_binary_assign_op_obj_dim(zend_object *obj, zval *property OPLINE_DC EXECUTE_DATA_DC) |
1639 | 0 | { |
1640 | 0 | zval *value; |
1641 | 0 | zval *z; |
1642 | 0 | zval rv, res; |
1643 | |
|
1644 | 0 | GC_ADDREF(obj); |
1645 | 0 | if (property && UNEXPECTED(Z_ISUNDEF_P(property))) { |
1646 | 0 | property = ZVAL_UNDEFINED_OP2(); |
1647 | 0 | } |
1648 | 0 | value = get_op_data_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1); |
1649 | 0 | if ((z = obj->handlers->read_dimension(obj, property, BP_VAR_R, &rv)) != NULL) { |
1650 | |
|
1651 | 0 | if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) { |
1652 | 0 | obj->handlers->write_dimension(obj, property, &res); |
1653 | 0 | } |
1654 | 0 | if (z == &rv) { |
1655 | 0 | zval_ptr_dtor(&rv); |
1656 | 0 | } |
1657 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
1658 | 0 | ZVAL_COPY(EX_VAR(opline->result.var), &res); |
1659 | 0 | } |
1660 | 0 | zval_ptr_dtor(&res); |
1661 | 0 | } else { |
1662 | 0 | zend_use_object_as_array(obj); |
1663 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
1664 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
1665 | 0 | } |
1666 | 0 | } |
1667 | 0 | FREE_OP((opline+1)->op1_type, (opline+1)->op1.var); |
1668 | 0 | if (UNEXPECTED(GC_DELREF(obj) == 0)) { |
1669 | 0 | zend_objects_store_del(obj); |
1670 | 0 | } |
1671 | 0 | } |
1672 | | |
1673 | | static zend_never_inline void zend_binary_assign_op_typed_ref(zend_reference *ref, zval *value OPLINE_DC EXECUTE_DATA_DC) |
1674 | 13 | { |
1675 | 13 | zval z_copy; |
1676 | | |
1677 | | /* Make sure that in-place concatenation is used if the LHS is a string. */ |
1678 | 13 | if (opline->extended_value == ZEND_CONCAT && Z_TYPE(ref->val) == IS_STRING) { |
1679 | 12 | concat_function(&ref->val, &ref->val, value); |
1680 | 12 | ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string"); |
1681 | 12 | return; |
1682 | 12 | } |
1683 | | |
1684 | 1 | zend_binary_op(&z_copy, &ref->val, value OPLINE_CC); |
1685 | 1 | if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, EX_USES_STRICT_TYPES()))) { |
1686 | 0 | zval_ptr_dtor(&ref->val); |
1687 | 0 | ZVAL_COPY_VALUE(&ref->val, &z_copy); |
1688 | 1 | } else { |
1689 | 1 | zval_ptr_dtor(&z_copy); |
1690 | 1 | } |
1691 | 1 | } |
1692 | | |
1693 | | static zend_never_inline void zend_binary_assign_op_typed_prop(const zend_property_info *prop_info, zval *zptr, zval *value OPLINE_DC EXECUTE_DATA_DC) |
1694 | 60 | { |
1695 | 60 | zval z_copy; |
1696 | | |
1697 | | /* Make sure that in-place concatenation is used if the LHS is a string. */ |
1698 | 60 | if (opline->extended_value == ZEND_CONCAT && Z_TYPE_P(zptr) == IS_STRING) { |
1699 | 54 | concat_function(zptr, zptr, value); |
1700 | 54 | ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string"); |
1701 | 54 | return; |
1702 | 54 | } |
1703 | | |
1704 | 6 | zend_binary_op(&z_copy, zptr, value OPLINE_CC); |
1705 | 6 | if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) { |
1706 | 6 | zval_ptr_dtor(zptr); |
1707 | 6 | ZVAL_COPY_VALUE(zptr, &z_copy); |
1708 | 6 | } else { |
1709 | 0 | zval_ptr_dtor(&z_copy); |
1710 | 0 | } |
1711 | 6 | } |
1712 | | |
1713 | | static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type EXECUTE_DATA_DC) |
1714 | 134 | { |
1715 | 134 | zend_long offset; |
1716 | | |
1717 | 134 | try_again: |
1718 | 134 | switch(Z_TYPE_P(dim)) { |
1719 | 7 | case IS_LONG: |
1720 | 7 | return Z_LVAL_P(dim); |
1721 | 41 | case IS_STRING: |
1722 | 41 | { |
1723 | 41 | bool trailing_data = false; |
1724 | | /* For BC reasons we allow errors so that we can warn on leading numeric string */ |
1725 | 41 | if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, |
1726 | 41 | /* allow errors */ true, NULL, &trailing_data)) { |
1727 | 3 | if (UNEXPECTED(trailing_data) && type != BP_VAR_UNSET) { |
1728 | 3 | zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim)); |
1729 | 3 | } |
1730 | 3 | return offset; |
1731 | 3 | } |
1732 | 38 | zend_illegal_string_offset(dim, type); |
1733 | 38 | return 0; |
1734 | 41 | } |
1735 | 10 | case IS_DOUBLE: |
1736 | | /* Suppress potential double warning */ |
1737 | 10 | zend_error(E_WARNING, "String offset cast occurred"); |
1738 | 10 | return zend_dval_to_lval_silent(Z_DVAL_P(dim)); |
1739 | 0 | case IS_UNDEF: |
1740 | 0 | ZVAL_UNDEFINED_OP2(); |
1741 | 0 | ZEND_FALLTHROUGH; |
1742 | 74 | case IS_NULL: |
1743 | 75 | case IS_FALSE: |
1744 | 76 | case IS_TRUE: |
1745 | 76 | zend_error(E_WARNING, "String offset cast occurred"); |
1746 | 76 | break; |
1747 | 0 | case IS_REFERENCE: |
1748 | 0 | dim = Z_REFVAL_P(dim); |
1749 | 0 | goto try_again; |
1750 | 0 | default: |
1751 | 0 | zend_illegal_string_offset(dim, type); |
1752 | 0 | return 0; |
1753 | 134 | } |
1754 | | |
1755 | 76 | return zval_get_long_func(dim, /* is_strict */ false); |
1756 | 134 | } |
1757 | | |
1758 | | ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void) |
1759 | 15 | { |
1760 | 15 | const char *msg = NULL; |
1761 | 15 | const zend_execute_data *execute_data = EG(current_execute_data); |
1762 | 15 | const zend_op *opline = execute_data->opline; |
1763 | | |
1764 | 15 | if (UNEXPECTED(EG(exception) != NULL)) { |
1765 | 2 | return; |
1766 | 2 | } |
1767 | | |
1768 | 13 | switch (opline->opcode) { |
1769 | 0 | case ZEND_ASSIGN_DIM_OP: |
1770 | 0 | msg = "Cannot use assign-op operators with string offsets"; |
1771 | 0 | break; |
1772 | 3 | case ZEND_FETCH_LIST_W: |
1773 | 3 | msg = "Cannot create references to/from string offsets"; |
1774 | 3 | break; |
1775 | 5 | case ZEND_FETCH_DIM_W: |
1776 | 7 | case ZEND_FETCH_DIM_RW: |
1777 | 7 | case ZEND_FETCH_DIM_FUNC_ARG: |
1778 | 10 | case ZEND_FETCH_DIM_UNSET: |
1779 | 10 | switch (opline->extended_value) { |
1780 | 5 | case ZEND_FETCH_DIM_REF: |
1781 | 5 | msg = "Cannot create references to/from string offsets"; |
1782 | 5 | break; |
1783 | 5 | case ZEND_FETCH_DIM_DIM: |
1784 | 5 | msg = "Cannot use string offset as an array"; |
1785 | 5 | break; |
1786 | 0 | case ZEND_FETCH_DIM_OBJ: |
1787 | 0 | msg = "Cannot use string offset as an object"; |
1788 | 0 | break; |
1789 | 0 | case ZEND_FETCH_DIM_INCDEC: |
1790 | 0 | msg = "Cannot increment/decrement string offsets"; |
1791 | 0 | break; |
1792 | 0 | EMPTY_SWITCH_DEFAULT_CASE(); |
1793 | 10 | } |
1794 | 10 | break; |
1795 | 10 | EMPTY_SWITCH_DEFAULT_CASE(); |
1796 | 13 | } |
1797 | 13 | ZEND_ASSERT(msg != NULL); |
1798 | 13 | zend_throw_error(NULL, "%s", msg); |
1799 | 13 | } |
1800 | | |
1801 | | ZEND_COLD static zend_result ZEND_FASTCALL get_deprecation_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix) |
1802 | 79 | { |
1803 | 79 | *message_suffix = ZSTR_EMPTY_ALLOC(); |
1804 | | |
1805 | 79 | if (!attributes) { |
1806 | 0 | return SUCCESS; |
1807 | 0 | } |
1808 | | |
1809 | 79 | zend_attribute *deprecated = zend_get_attribute_str(attributes, "deprecated", sizeof("deprecated")-1); |
1810 | | |
1811 | 79 | if (!deprecated) { |
1812 | 0 | return SUCCESS; |
1813 | 0 | } |
1814 | | |
1815 | 79 | if (deprecated->argc == 0) { |
1816 | 30 | return SUCCESS; |
1817 | 30 | } |
1818 | | |
1819 | 49 | zend_result result = FAILURE; |
1820 | | |
1821 | 49 | zend_string *message = ZSTR_EMPTY_ALLOC(); |
1822 | 49 | zend_string *since = ZSTR_EMPTY_ALLOC(); |
1823 | | |
1824 | 49 | zval obj; |
1825 | 49 | ZVAL_UNDEF(&obj); |
1826 | 49 | zval *z; |
1827 | | |
1828 | | /* Construct the Deprecated object to correctly handle parameter processing. */ |
1829 | 49 | if (FAILURE == zend_get_attribute_object(&obj, zend_ce_deprecated, deprecated, scope, NULL)) { |
1830 | 3 | goto out; |
1831 | 3 | } |
1832 | | |
1833 | | /* Extract the $message property. */ |
1834 | 46 | z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL); |
1835 | 46 | ZEND_ASSERT(z != &EG(uninitialized_zval)); |
1836 | 46 | if (Z_TYPE_P(z) == IS_STRING) { |
1837 | 30 | message = Z_STR_P(z); |
1838 | 30 | } |
1839 | | |
1840 | | /* Extract the $since property. */ |
1841 | 46 | z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_SINCE), false, NULL); |
1842 | 46 | ZEND_ASSERT(z != &EG(uninitialized_zval)); |
1843 | 46 | if (Z_TYPE_P(z) == IS_STRING) { |
1844 | 36 | since = Z_STR_P(z); |
1845 | 36 | } |
1846 | | |
1847 | | /* Construct the suffix. */ |
1848 | 46 | *message_suffix = zend_strpprintf_unchecked( |
1849 | 46 | 0, |
1850 | 46 | "%s%S%s%S", |
1851 | 46 | ZSTR_LEN(since) > 0 ? " since " : "", |
1852 | 46 | since, |
1853 | 46 | ZSTR_LEN(message) > 0 ? ", " : "", |
1854 | 46 | message |
1855 | 46 | ); |
1856 | | |
1857 | 46 | result = SUCCESS; |
1858 | | |
1859 | 49 | out: |
1860 | | |
1861 | 49 | zval_ptr_dtor(&obj); |
1862 | | |
1863 | 49 | return result; |
1864 | 46 | } |
1865 | | |
1866 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc) |
1867 | 40 | { |
1868 | 40 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1869 | | |
1870 | 40 | if (get_deprecation_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) { |
1871 | 3 | return; |
1872 | 3 | } |
1873 | | |
1874 | 37 | int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_DEPRECATED : E_USER_DEPRECATED; |
1875 | | |
1876 | 37 | if (fbc->common.scope) { |
1877 | 12 | zend_error_unchecked(code, "Method %s::%s() is deprecated%S", |
1878 | 12 | ZSTR_VAL(fbc->common.scope->name), |
1879 | 12 | ZSTR_VAL(fbc->common.function_name), |
1880 | 12 | message_suffix |
1881 | 12 | ); |
1882 | 25 | } else { |
1883 | 25 | zend_error_unchecked(code, "Function %s() is deprecated%S", |
1884 | 25 | ZSTR_VAL(fbc->common.function_name), |
1885 | 25 | message_suffix |
1886 | 25 | ); |
1887 | 25 | } |
1888 | | |
1889 | 37 | zend_string_release(message_suffix); |
1890 | 37 | } |
1891 | | |
1892 | | ZEND_COLD static zend_result ZEND_FASTCALL get_nodiscard_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix) |
1893 | 10 | { |
1894 | 10 | *message_suffix = ZSTR_EMPTY_ALLOC(); |
1895 | | |
1896 | 10 | if (!attributes) { |
1897 | 0 | return SUCCESS; |
1898 | 0 | } |
1899 | | |
1900 | 10 | zend_attribute *nodiscard = zend_get_attribute_str(attributes, "nodiscard", sizeof("nodiscard")-1); |
1901 | | |
1902 | 10 | if (!nodiscard) { |
1903 | 0 | return SUCCESS; |
1904 | 0 | } |
1905 | | |
1906 | 10 | if (nodiscard->argc == 0) { |
1907 | 8 | return SUCCESS; |
1908 | 8 | } |
1909 | | |
1910 | 2 | zend_result result = FAILURE; |
1911 | | |
1912 | 2 | zend_string *message = ZSTR_EMPTY_ALLOC(); |
1913 | | |
1914 | 2 | zval obj; |
1915 | 2 | ZVAL_UNDEF(&obj); |
1916 | 2 | zval *z; |
1917 | | |
1918 | | /* Construct the NoDiscard object to correctly handle parameter processing. */ |
1919 | 2 | if (FAILURE == zend_get_attribute_object(&obj, zend_ce_nodiscard, nodiscard, scope, NULL)) { |
1920 | 1 | goto out; |
1921 | 1 | } |
1922 | | |
1923 | | /* Extract the $message property. */ |
1924 | 1 | z = zend_read_property_ex(zend_ce_nodiscard, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL); |
1925 | 1 | ZEND_ASSERT(z != &EG(uninitialized_zval)); |
1926 | 1 | if (Z_TYPE_P(z) == IS_STRING) { |
1927 | 1 | message = Z_STR_P(z); |
1928 | 1 | } |
1929 | | |
1930 | | /* Construct the suffix. */ |
1931 | 1 | *message_suffix = zend_strpprintf_unchecked( |
1932 | 1 | 0, |
1933 | 1 | "%s%S", |
1934 | 1 | ZSTR_LEN(message) > 0 ? ", " : "", |
1935 | 1 | message |
1936 | 1 | ); |
1937 | | |
1938 | 1 | result = SUCCESS; |
1939 | | |
1940 | 2 | out: |
1941 | | |
1942 | 2 | zval_ptr_dtor(&obj); |
1943 | | |
1944 | 2 | return result; |
1945 | 1 | } |
1946 | | |
1947 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_nodiscard_function(const zend_function *fbc) |
1948 | 10 | { |
1949 | 10 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1950 | | |
1951 | 10 | if (get_nodiscard_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) { |
1952 | 1 | return; |
1953 | 1 | } |
1954 | | |
1955 | 9 | int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_WARNING : E_USER_WARNING; |
1956 | | |
1957 | 9 | if (fbc->common.scope) { |
1958 | 4 | zend_error_unchecked(code, "The return value of method %s::%s() should either be used or intentionally ignored by casting it as (void)%S", |
1959 | 4 | ZSTR_VAL(fbc->common.scope->name), |
1960 | 4 | ZSTR_VAL(fbc->common.function_name), |
1961 | 4 | message_suffix |
1962 | 4 | ); |
1963 | 5 | } else { |
1964 | 5 | zend_error_unchecked(code, "The return value of function %s() should either be used or intentionally ignored by casting it as (void)%S", |
1965 | 5 | ZSTR_VAL(fbc->common.function_name), |
1966 | 5 | message_suffix |
1967 | 5 | ); |
1968 | 5 | } |
1969 | | |
1970 | 9 | zend_string_release(message_suffix); |
1971 | 9 | } |
1972 | | |
1973 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_class_constant(const zend_class_constant *c, const zend_string *constant_name) |
1974 | 5 | { |
1975 | 5 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1976 | | |
1977 | 5 | if (get_deprecation_suffix_from_attribute(c->attributes, c->ce, &message_suffix) == FAILURE) { |
1978 | 0 | return; |
1979 | 0 | } |
1980 | | |
1981 | 5 | int code = c->ce->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED; |
1982 | 5 | char *type = (ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE) ? "Enum case" : "Constant"; |
1983 | | |
1984 | 5 | zend_error_unchecked(code, "%s %s::%s is deprecated%S", |
1985 | 5 | type, |
1986 | 5 | ZSTR_VAL(c->ce->name), |
1987 | 5 | ZSTR_VAL(constant_name), |
1988 | 5 | message_suffix |
1989 | 5 | ); |
1990 | | |
1991 | 5 | zend_string_release(message_suffix); |
1992 | 5 | } |
1993 | | |
1994 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_constant(const zend_constant *c, const zend_string *constant_name) |
1995 | 26 | { |
1996 | 26 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1997 | | |
1998 | 26 | if (get_deprecation_suffix_from_attribute(c->attributes, NULL, &message_suffix) == FAILURE) { |
1999 | 0 | return; |
2000 | 0 | } |
2001 | | |
2002 | 26 | int code = ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT ? E_USER_DEPRECATED : E_DEPRECATED; |
2003 | | |
2004 | 26 | zend_error_unchecked(code, "Constant %s is deprecated%S", |
2005 | 26 | ZSTR_VAL(constant_name), |
2006 | 26 | message_suffix |
2007 | 26 | ); |
2008 | | |
2009 | 26 | zend_string_release(message_suffix); |
2010 | 26 | } |
2011 | | |
2012 | | ZEND_API ZEND_COLD void zend_use_of_deprecated_trait( |
2013 | | zend_class_entry *trait, |
2014 | | const zend_string *used_by |
2015 | 8 | ) { |
2016 | 8 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
2017 | | |
2018 | 8 | if (get_deprecation_suffix_from_attribute(trait->attributes, trait, &message_suffix) == FAILURE) { |
2019 | 0 | return; |
2020 | 0 | } |
2021 | | |
2022 | 8 | int code = trait->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED; |
2023 | | |
2024 | 8 | zend_error_unchecked(code, "Trait %s used by %s is deprecated%S", |
2025 | 8 | ZSTR_VAL(trait->name), |
2026 | 8 | ZSTR_VAL(used_by), |
2027 | 8 | message_suffix |
2028 | 8 | ); |
2029 | | |
2030 | 8 | zend_string_release(message_suffix); |
2031 | 8 | } |
2032 | | |
2033 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void) |
2034 | 292 | { |
2035 | 292 | zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated"); |
2036 | 292 | } |
2037 | | |
2038 | | static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) |
2039 | 171 | { |
2040 | 171 | zend_uchar c; |
2041 | 171 | size_t string_len; |
2042 | 171 | zend_long offset; |
2043 | 171 | zend_string *s; |
2044 | | |
2045 | | /* separate string */ |
2046 | 171 | if (Z_REFCOUNTED_P(str) && Z_REFCOUNT_P(str) == 1) { |
2047 | 76 | s = Z_STR_P(str); |
2048 | 95 | } else { |
2049 | 95 | s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0); |
2050 | 95 | ZSTR_H(s) = ZSTR_H(Z_STR_P(str)); |
2051 | 95 | if (Z_REFCOUNTED_P(str)) { |
2052 | 40 | GC_DELREF(Z_STR_P(str)); |
2053 | 40 | } |
2054 | 95 | ZVAL_NEW_STR(str, s); |
2055 | 95 | } |
2056 | | |
2057 | 171 | if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) { |
2058 | 52 | offset = Z_LVAL_P(dim); |
2059 | 119 | } else { |
2060 | | /* The string may be destroyed while throwing the notice. |
2061 | | * Temporarily increase the refcount to detect this situation. */ |
2062 | 119 | GC_ADDREF(s); |
2063 | 119 | offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC); |
2064 | 119 | if (UNEXPECTED(GC_DELREF(s) == 0)) { |
2065 | 0 | zend_string_efree(s); |
2066 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2067 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2068 | 0 | } |
2069 | 0 | return; |
2070 | 0 | } |
2071 | | /* Illegal offset assignment */ |
2072 | 119 | if (UNEXPECTED(EG(exception) != NULL)) { |
2073 | 36 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2074 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2075 | 0 | } |
2076 | 36 | return; |
2077 | 36 | } |
2078 | 119 | } |
2079 | | |
2080 | 135 | if (UNEXPECTED(offset < -(zend_long)ZSTR_LEN(s))) { |
2081 | | /* Error on negative offset */ |
2082 | 31 | zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset); |
2083 | 31 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2084 | 30 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2085 | 30 | } |
2086 | 31 | return; |
2087 | 31 | } |
2088 | | |
2089 | 104 | if (offset < 0) { /* Handle negative offset */ |
2090 | 0 | offset += (zend_long)ZSTR_LEN(s); |
2091 | 0 | } |
2092 | | |
2093 | 104 | if (UNEXPECTED(Z_TYPE_P(value) != IS_STRING)) { |
2094 | 75 | zend_string *tmp; |
2095 | | |
2096 | | /* The string may be destroyed while throwing the notice. |
2097 | | * Temporarily increase the refcount to detect this situation. */ |
2098 | 75 | GC_ADDREF(s); |
2099 | 75 | if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { |
2100 | 0 | zval_undefined_cv((opline+1)->op1.var EXECUTE_DATA_CC); |
2101 | 0 | } |
2102 | | /* Convert to string, just the time to pick the 1st byte */ |
2103 | 75 | tmp = zval_try_get_string_func(value); |
2104 | 75 | if (UNEXPECTED(GC_DELREF(s) == 0)) { |
2105 | 0 | zend_string_efree(s); |
2106 | 0 | if (tmp) { |
2107 | 0 | zend_string_release_ex(tmp, 0); |
2108 | 0 | } |
2109 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2110 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2111 | 0 | } |
2112 | 0 | return; |
2113 | 0 | } |
2114 | 75 | if (UNEXPECTED(!tmp)) { |
2115 | 3 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2116 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2117 | 0 | } |
2118 | 3 | return; |
2119 | 3 | } |
2120 | | |
2121 | 72 | string_len = ZSTR_LEN(tmp); |
2122 | 72 | c = (zend_uchar)ZSTR_VAL(tmp)[0]; |
2123 | 72 | zend_string_release_ex(tmp, 0); |
2124 | 72 | } else { |
2125 | 29 | string_len = Z_STRLEN_P(value); |
2126 | 29 | c = (zend_uchar)Z_STRVAL_P(value)[0]; |
2127 | 29 | } |
2128 | | |
2129 | 101 | if (UNEXPECTED(string_len != 1)) { |
2130 | 36 | if (string_len == 0) { |
2131 | | /* Error on empty input string */ |
2132 | 0 | zend_throw_error(NULL, "Cannot assign an empty string to a string offset"); |
2133 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2134 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2135 | 0 | } |
2136 | 0 | return; |
2137 | 0 | } |
2138 | | |
2139 | | /* The string may be destroyed while throwing the notice. |
2140 | | * Temporarily increase the refcount to detect this situation. */ |
2141 | 36 | GC_ADDREF(s); |
2142 | 36 | zend_error(E_WARNING, "Only the first byte will be assigned to the string offset"); |
2143 | 36 | if (UNEXPECTED(GC_DELREF(s) == 0)) { |
2144 | 0 | zend_string_efree(s); |
2145 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2146 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2147 | 0 | } |
2148 | 0 | return; |
2149 | 0 | } |
2150 | | /* Illegal offset assignment */ |
2151 | 36 | if (UNEXPECTED(EG(exception) != NULL)) { |
2152 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2153 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2154 | 0 | } |
2155 | 0 | return; |
2156 | 0 | } |
2157 | 36 | } |
2158 | | |
2159 | 101 | if ((size_t)offset >= ZSTR_LEN(s)) { |
2160 | | /* Extend string if needed */ |
2161 | 13 | zend_long old_len = ZSTR_LEN(s); |
2162 | 13 | ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0)); |
2163 | 13 | memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len); |
2164 | 13 | Z_STRVAL_P(str)[offset+1] = 0; |
2165 | 88 | } else { |
2166 | 88 | zend_string_forget_hash_val(Z_STR_P(str)); |
2167 | 88 | } |
2168 | | |
2169 | 101 | Z_STRVAL_P(str)[offset] = c; |
2170 | | |
2171 | 101 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2172 | | /* Return the new character */ |
2173 | 36 | ZVAL_CHAR(EX_VAR(opline->result.var), c); |
2174 | 36 | } |
2175 | 101 | } |
2176 | | |
2177 | | static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *ref) |
2178 | 87 | { |
2179 | 87 | zend_property_info *prop; |
2180 | 261 | ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) { |
2181 | 261 | if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) { |
2182 | 42 | return prop; |
2183 | 42 | } |
2184 | 261 | } ZEND_REF_FOREACH_TYPE_SOURCES_END(); |
2185 | 45 | return NULL; |
2186 | 87 | } |
2187 | | |
2188 | | static ZEND_COLD zend_long zend_throw_incdec_ref_error( |
2189 | | zend_reference *ref, zend_property_info *error_prop OPLINE_DC) |
2190 | 42 | { |
2191 | 42 | zend_string *type_str = zend_type_to_string(error_prop->type); |
2192 | 42 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2193 | 24 | zend_type_error( |
2194 | 24 | "Cannot increment a reference held by property %s::$%s of type %s past its maximal value", |
2195 | 24 | ZSTR_VAL(error_prop->ce->name), |
2196 | 24 | zend_get_unmangled_property_name(error_prop->name), |
2197 | 24 | ZSTR_VAL(type_str)); |
2198 | 24 | zend_string_release(type_str); |
2199 | 24 | return ZEND_LONG_MAX; |
2200 | 24 | } else { |
2201 | 18 | zend_type_error( |
2202 | 18 | "Cannot decrement a reference held by property %s::$%s of type %s past its minimal value", |
2203 | 18 | ZSTR_VAL(error_prop->ce->name), |
2204 | 18 | zend_get_unmangled_property_name(error_prop->name), |
2205 | 18 | ZSTR_VAL(type_str)); |
2206 | 18 | zend_string_release(type_str); |
2207 | 18 | return ZEND_LONG_MIN; |
2208 | 18 | } |
2209 | 42 | } |
2210 | | |
2211 | 45 | static ZEND_COLD zend_long zend_throw_incdec_prop_error(zend_property_info *prop OPLINE_DC) { |
2212 | 45 | zend_string *type_str = zend_type_to_string(prop->type); |
2213 | 45 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2214 | 21 | zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value", |
2215 | 21 | ZSTR_VAL(prop->ce->name), |
2216 | 21 | zend_get_unmangled_property_name(prop->name), |
2217 | 21 | ZSTR_VAL(type_str)); |
2218 | 21 | zend_string_release(type_str); |
2219 | 21 | return ZEND_LONG_MAX; |
2220 | 24 | } else { |
2221 | 24 | zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value", |
2222 | 24 | ZSTR_VAL(prop->ce->name), |
2223 | 24 | zend_get_unmangled_property_name(prop->name), |
2224 | 24 | ZSTR_VAL(type_str)); |
2225 | 24 | zend_string_release(type_str); |
2226 | 24 | return ZEND_LONG_MIN; |
2227 | 24 | } |
2228 | 45 | } |
2229 | | |
2230 | | static void zend_incdec_typed_ref(zend_reference *ref, zval *copy OPLINE_DC EXECUTE_DATA_DC) |
2231 | 90 | { |
2232 | 90 | zval tmp; |
2233 | 90 | zval *var_ptr = &ref->val; |
2234 | | |
2235 | 90 | if (!copy) { |
2236 | 45 | copy = &tmp; |
2237 | 45 | } |
2238 | | |
2239 | 90 | ZVAL_COPY(copy, var_ptr); |
2240 | | |
2241 | 90 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2242 | 48 | increment_function(var_ptr); |
2243 | 48 | } else { |
2244 | 42 | decrement_function(var_ptr); |
2245 | 42 | } |
2246 | | |
2247 | 90 | if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) { |
2248 | 87 | zend_property_info *error_prop = zend_get_prop_not_accepting_double(ref); |
2249 | 87 | if (UNEXPECTED(error_prop)) { |
2250 | 42 | zend_long val = zend_throw_incdec_ref_error(ref, error_prop OPLINE_CC); |
2251 | 42 | ZVAL_LONG(var_ptr, val); |
2252 | 42 | } |
2253 | 87 | } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, EX_USES_STRICT_TYPES()))) { |
2254 | 2 | zval_ptr_dtor(var_ptr); |
2255 | 2 | ZVAL_COPY_VALUE(var_ptr, copy); |
2256 | 2 | ZVAL_UNDEF(copy); |
2257 | 2 | } else if (copy == &tmp) { |
2258 | 1 | zval_ptr_dtor(&tmp); |
2259 | 1 | } |
2260 | 90 | } |
2261 | | |
2262 | | static void zend_incdec_typed_prop(zend_property_info *prop_info, zval *var_ptr, zval *copy OPLINE_DC EXECUTE_DATA_DC) |
2263 | 0 | { |
2264 | 0 | zval tmp; |
2265 | |
|
2266 | 0 | if (!copy) { |
2267 | 0 | copy = &tmp; |
2268 | 0 | } |
2269 | |
|
2270 | 0 | ZVAL_COPY(copy, var_ptr); |
2271 | |
|
2272 | 0 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2273 | 0 | increment_function(var_ptr); |
2274 | 0 | } else { |
2275 | 0 | decrement_function(var_ptr); |
2276 | 0 | } |
2277 | |
|
2278 | 0 | if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) { |
2279 | 0 | if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) { |
2280 | 0 | zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC); |
2281 | 0 | ZVAL_LONG(var_ptr, val); |
2282 | 0 | } |
2283 | 0 | } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) { |
2284 | 0 | zval_ptr_dtor(var_ptr); |
2285 | 0 | ZVAL_COPY_VALUE(var_ptr, copy); |
2286 | 0 | ZVAL_UNDEF(copy); |
2287 | 0 | } else if (copy == &tmp) { |
2288 | 0 | zval_ptr_dtor(&tmp); |
2289 | 0 | } |
2290 | 0 | } |
2291 | | |
2292 | | static void zend_pre_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC) |
2293 | 146 | { |
2294 | 146 | if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) { |
2295 | 102 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2296 | 75 | fast_long_increment_function(prop); |
2297 | 75 | } else { |
2298 | 27 | fast_long_decrement_function(prop); |
2299 | 27 | } |
2300 | 102 | if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info |
2301 | 57 | && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) { |
2302 | 24 | zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC); |
2303 | 24 | ZVAL_LONG(prop, val); |
2304 | 24 | } |
2305 | 102 | } else { |
2306 | 44 | do { |
2307 | 44 | if (Z_ISREF_P(prop)) { |
2308 | 44 | zend_reference *ref = Z_REF_P(prop); |
2309 | 44 | prop = Z_REFVAL_P(prop); |
2310 | 44 | if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { |
2311 | 42 | zend_incdec_typed_ref(ref, NULL OPLINE_CC EXECUTE_DATA_CC); |
2312 | 42 | break; |
2313 | 42 | } |
2314 | 44 | } |
2315 | | |
2316 | 2 | if (prop_info) { |
2317 | 0 | zend_incdec_typed_prop(prop_info, prop, NULL OPLINE_CC EXECUTE_DATA_CC); |
2318 | 2 | } else if (ZEND_IS_INCREMENT(opline->opcode)) { |
2319 | 1 | increment_function(prop); |
2320 | 1 | } else { |
2321 | 1 | decrement_function(prop); |
2322 | 1 | } |
2323 | 2 | } while (0); |
2324 | 44 | } |
2325 | 146 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2326 | 99 | ZVAL_COPY(EX_VAR(opline->result.var), prop); |
2327 | 99 | } |
2328 | 146 | } |
2329 | | |
2330 | | static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC) |
2331 | 403 | { |
2332 | 403 | if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) { |
2333 | 185 | ZVAL_LONG(EX_VAR(opline->result.var), Z_LVAL_P(prop)); |
2334 | 185 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2335 | 28 | fast_long_increment_function(prop); |
2336 | 157 | } else { |
2337 | 157 | fast_long_decrement_function(prop); |
2338 | 157 | } |
2339 | 185 | if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info |
2340 | 51 | && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) { |
2341 | 21 | zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC); |
2342 | 21 | ZVAL_LONG(prop, val); |
2343 | 21 | } |
2344 | 218 | } else { |
2345 | 218 | if (Z_ISREF_P(prop)) { |
2346 | 45 | zend_reference *ref = Z_REF_P(prop); |
2347 | 45 | prop = Z_REFVAL_P(prop); |
2348 | 45 | if (ZEND_REF_HAS_TYPE_SOURCES(ref)) { |
2349 | 45 | zend_incdec_typed_ref(ref, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC); |
2350 | 45 | return; |
2351 | 45 | } |
2352 | 45 | } |
2353 | | |
2354 | 173 | if (prop_info) { |
2355 | 0 | zend_incdec_typed_prop(prop_info, prop, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC); |
2356 | 173 | } else { |
2357 | 173 | ZVAL_COPY(EX_VAR(opline->result.var), prop); |
2358 | 173 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2359 | 6 | increment_function(prop); |
2360 | 167 | } else { |
2361 | 167 | decrement_function(prop); |
2362 | 167 | } |
2363 | 173 | } |
2364 | 173 | } |
2365 | 403 | } |
2366 | | |
2367 | | static zend_never_inline void zend_post_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC) |
2368 | 4 | { |
2369 | 4 | zval rv; |
2370 | 4 | zval *z; |
2371 | 4 | zval z_copy; |
2372 | | |
2373 | 4 | GC_ADDREF(object); |
2374 | 4 | z =object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv); |
2375 | 4 | if (UNEXPECTED(EG(exception))) { |
2376 | 1 | OBJ_RELEASE(object); |
2377 | 1 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2378 | 1 | return; |
2379 | 1 | } |
2380 | | |
2381 | 3 | ZVAL_COPY_DEREF(&z_copy, z); |
2382 | 3 | ZVAL_COPY(EX_VAR(opline->result.var), &z_copy); |
2383 | 3 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2384 | 3 | increment_function(&z_copy); |
2385 | 3 | } else { |
2386 | 0 | decrement_function(&z_copy); |
2387 | 0 | } |
2388 | 3 | object->handlers->write_property(object, name, &z_copy, cache_slot); |
2389 | 3 | OBJ_RELEASE(object); |
2390 | 3 | zval_ptr_dtor(&z_copy); |
2391 | 3 | if (z == &rv) { |
2392 | 3 | zval_ptr_dtor(z); |
2393 | 3 | } |
2394 | 3 | } |
2395 | | |
2396 | | static zend_never_inline void zend_pre_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC) |
2397 | 0 | { |
2398 | 0 | zval rv; |
2399 | 0 | zval *z; |
2400 | 0 | zval z_copy; |
2401 | |
|
2402 | 0 | GC_ADDREF(object); |
2403 | 0 | z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv); |
2404 | 0 | if (UNEXPECTED(EG(exception))) { |
2405 | 0 | OBJ_RELEASE(object); |
2406 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2407 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2408 | 0 | } |
2409 | 0 | return; |
2410 | 0 | } |
2411 | | |
2412 | 0 | ZVAL_COPY_DEREF(&z_copy, z); |
2413 | 0 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2414 | 0 | increment_function(&z_copy); |
2415 | 0 | } else { |
2416 | 0 | decrement_function(&z_copy); |
2417 | 0 | } |
2418 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2419 | 0 | ZVAL_COPY(EX_VAR(opline->result.var), &z_copy); |
2420 | 0 | } |
2421 | 0 | object->handlers->write_property(object, name, &z_copy, cache_slot); |
2422 | 0 | OBJ_RELEASE(object); |
2423 | 0 | zval_ptr_dtor(&z_copy); |
2424 | 0 | if (z == &rv) { |
2425 | 0 | zval_ptr_dtor(z); |
2426 | 0 | } |
2427 | 0 | } |
2428 | | |
2429 | | static zend_never_inline void zend_assign_op_overloaded_property(zend_object *object, zend_string *name, void **cache_slot, zval *value OPLINE_DC EXECUTE_DATA_DC) |
2430 | 14 | { |
2431 | 14 | zval *z; |
2432 | 14 | zval rv, res; |
2433 | | |
2434 | 14 | GC_ADDREF(object); |
2435 | 14 | z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv); |
2436 | 14 | if (UNEXPECTED(EG(exception))) { |
2437 | 1 | OBJ_RELEASE(object); |
2438 | 1 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2439 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2440 | 0 | } |
2441 | 1 | return; |
2442 | 1 | } |
2443 | 13 | if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) { |
2444 | 13 | object->handlers->write_property(object, name, &res, cache_slot); |
2445 | 13 | } |
2446 | 13 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2447 | 0 | ZVAL_COPY(EX_VAR(opline->result.var), &res); |
2448 | 0 | } |
2449 | 13 | if (z == &rv) { |
2450 | 0 | zval_ptr_dtor(z); |
2451 | 0 | } |
2452 | 13 | zval_ptr_dtor(&res); |
2453 | 13 | OBJ_RELEASE(object); |
2454 | 13 | } |
2455 | | |
2456 | | /* Utility Functions for Extensions */ |
2457 | | static void zend_extension_statement_handler(const zend_extension *extension, zend_execute_data *frame) |
2458 | 0 | { |
2459 | 0 | if (extension->statement_handler) { |
2460 | 0 | extension->statement_handler(frame); |
2461 | 0 | } |
2462 | 0 | } |
2463 | | |
2464 | | |
2465 | | static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_execute_data *frame) |
2466 | 0 | { |
2467 | 0 | if (extension->fcall_begin_handler) { |
2468 | 0 | extension->fcall_begin_handler(frame); |
2469 | 0 | } |
2470 | 0 | } |
2471 | | |
2472 | | |
2473 | | static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_execute_data *frame) |
2474 | 0 | { |
2475 | 0 | if (extension->fcall_end_handler) { |
2476 | 0 | extension->fcall_end_handler(frame); |
2477 | 0 | } |
2478 | 0 | } |
2479 | | |
2480 | | |
2481 | | static zend_always_inline HashTable *zend_get_target_symbol_table(int fetch_type EXECUTE_DATA_DC) |
2482 | 36.2k | { |
2483 | 36.2k | HashTable *ht; |
2484 | | |
2485 | 36.2k | if (EXPECTED(fetch_type & (ZEND_FETCH_GLOBAL_LOCK | ZEND_FETCH_GLOBAL))) { |
2486 | 575 | ht = &EG(symbol_table); |
2487 | 35.6k | } else { |
2488 | 35.6k | ZEND_ASSERT(fetch_type & ZEND_FETCH_LOCAL); |
2489 | 35.6k | if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) { |
2490 | 295 | zend_rebuild_symbol_table(); |
2491 | 295 | } |
2492 | 35.6k | ht = EX(symbol_table); |
2493 | 35.6k | } |
2494 | 36.2k | return ht; |
2495 | 36.2k | } |
2496 | | |
2497 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_offset(zend_long lval) |
2498 | 375 | { |
2499 | 375 | zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, lval); |
2500 | 375 | } |
2501 | | |
2502 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_index(const zend_string *offset) |
2503 | 547 | { |
2504 | 547 | zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset)); |
2505 | 547 | } |
2506 | | |
2507 | | ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval) |
2508 | 49 | { |
2509 | | /* The array may be destroyed while throwing the notice. |
2510 | | * Temporarily increase the refcount to detect this situation. */ |
2511 | 49 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2512 | 49 | GC_ADDREF(ht); |
2513 | 49 | } |
2514 | 49 | zend_undefined_offset(lval); |
2515 | 49 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2516 | 0 | if (!GC_REFCOUNT(ht)) { |
2517 | 0 | zend_array_destroy(ht); |
2518 | 0 | } |
2519 | 0 | return NULL; |
2520 | 0 | } |
2521 | 49 | if (EG(exception)) { |
2522 | 0 | return NULL; |
2523 | 0 | } |
2524 | 49 | return zend_hash_index_add_new(ht, lval, &EG(uninitialized_zval)); |
2525 | 49 | } |
2526 | | |
2527 | | ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset) |
2528 | 513 | { |
2529 | 513 | zval *retval; |
2530 | | |
2531 | | /* The array may be destroyed while throwing the notice. |
2532 | | * Temporarily increase the refcount to detect this situation. */ |
2533 | 513 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2534 | 513 | GC_ADDREF(ht); |
2535 | 513 | } |
2536 | | /* Key may be released while throwing the undefined index warning. */ |
2537 | 513 | zend_string_addref(offset); |
2538 | 513 | zend_undefined_index(offset); |
2539 | 513 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2540 | 0 | if (!GC_REFCOUNT(ht)) { |
2541 | 0 | zend_array_destroy(ht); |
2542 | 0 | } |
2543 | 0 | retval = NULL; |
2544 | 513 | } else if (EG(exception)) { |
2545 | 0 | retval = NULL; |
2546 | 513 | } else { |
2547 | 513 | retval = zend_hash_add_new(ht, offset, &EG(uninitialized_zval)); |
2548 | 513 | } |
2549 | 513 | zend_string_release(offset); |
2550 | 513 | return retval; |
2551 | 513 | } |
2552 | | |
2553 | | ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method) |
2554 | 70 | { |
2555 | 70 | zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method)); |
2556 | 70 | } |
2557 | | |
2558 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_invalid_method_call(zval *object, zval *function_name) |
2559 | 36 | { |
2560 | 36 | zend_throw_error(NULL, "Call to a member function %s() on %s", |
2561 | 36 | Z_STRVAL_P(function_name), zend_zval_value_name(object)); |
2562 | 36 | } |
2563 | | |
2564 | | ZEND_API void ZEND_FASTCALL zend_non_static_method_call(const zend_function *fbc) |
2565 | 6 | { |
2566 | 6 | zend_throw_error( |
2567 | 6 | zend_ce_error, |
2568 | 6 | "Non-static method %s::%s() cannot be called statically", |
2569 | 6 | ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name)); |
2570 | 6 | } |
2571 | | |
2572 | | ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num) |
2573 | 41 | { |
2574 | 41 | const char *arg_name = get_function_arg_name(func, arg_num); |
2575 | | |
2576 | 41 | zend_error(E_WARNING, "%s%s%s(): Argument #%d%s%s%s must be passed by reference, value given", |
2577 | 41 | func->common.scope ? ZSTR_VAL(func->common.scope->name) : "", |
2578 | 41 | func->common.scope ? "::" : "", |
2579 | 41 | ZSTR_VAL(func->common.function_name), |
2580 | 41 | arg_num, |
2581 | 41 | arg_name ? " ($" : "", |
2582 | 41 | arg_name ? arg_name : "", |
2583 | 41 | arg_name ? ")" : "" |
2584 | 41 | ); |
2585 | 41 | } |
2586 | | |
2587 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(void) |
2588 | 177 | { |
2589 | 177 | zend_throw_error(NULL, "Cannot use a scalar value as an array"); |
2590 | 177 | } |
2591 | | |
2592 | | ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void) |
2593 | 19 | { |
2594 | 19 | zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied"); |
2595 | 19 | } |
2596 | | |
2597 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim) |
2598 | 0 | { |
2599 | 0 | zend_error(E_WARNING, |
2600 | 0 | "Resource ID#" ZEND_LONG_FMT " used as offset, casting to integer (" ZEND_LONG_FMT ")", |
2601 | 0 | Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim)); |
2602 | 0 | } |
2603 | | |
2604 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_string(void) |
2605 | 5 | { |
2606 | 5 | zend_throw_error(NULL, "[] operator not supported for strings"); |
2607 | 5 | } |
2608 | | |
2609 | | #ifdef ZEND_CHECK_STACK_LIMIT |
2610 | | ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_call_stack_size_error(void) |
2611 | 0 | { |
2612 | 0 | size_t max_stack_size = 0; |
2613 | 0 | if ((uintptr_t) EG(stack_base) > (uintptr_t) EG(stack_limit)) { |
2614 | 0 | max_stack_size = (size_t) ((uintptr_t) EG(stack_base) - (uintptr_t) EG(stack_limit)); |
2615 | 0 | } |
2616 | |
|
2617 | 0 | zend_throw_error(NULL, "Maximum call stack size of %zu bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?", |
2618 | 0 | max_stack_size); |
2619 | 0 | } |
2620 | | #endif /* ZEND_CHECK_STACK_LIMIT */ |
2621 | | |
2622 | | static ZEND_COLD void zend_binary_assign_op_dim_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC) |
2623 | 4 | { |
2624 | 4 | if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) { |
2625 | 1 | if (opline->op2_type == IS_UNUSED) { |
2626 | 1 | zend_use_new_element_for_string(); |
2627 | 1 | } else { |
2628 | 0 | zend_check_string_offset(dim, BP_VAR_RW EXECUTE_DATA_CC); |
2629 | 0 | zend_wrong_string_offset_error(); |
2630 | 0 | } |
2631 | 3 | } else { |
2632 | 3 | zend_use_scalar_as_array(); |
2633 | 3 | } |
2634 | 4 | } |
2635 | | |
2636 | | static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC) |
2637 | 224 | { |
2638 | 224 | switch (Z_TYPE_P(dim)) { |
2639 | 59 | case IS_UNDEF: { |
2640 | | /* The array may be destroyed while throwing the notice. |
2641 | | * Temporarily increase the refcount to detect this situation. */ |
2642 | 59 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2643 | 59 | GC_ADDREF(ht); |
2644 | 59 | } |
2645 | 59 | ZVAL_UNDEFINED_OP2(); |
2646 | 59 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2647 | 0 | zend_array_destroy(ht); |
2648 | 0 | return IS_NULL; |
2649 | 0 | } |
2650 | 59 | if (EG(exception)) { |
2651 | 0 | return IS_NULL; |
2652 | 0 | } |
2653 | 59 | ZEND_FALLTHROUGH; |
2654 | 59 | } |
2655 | 151 | case IS_NULL: |
2656 | | /* The array may be destroyed while throwing the notice. |
2657 | | * Temporarily increase the refcount to detect this situation. */ |
2658 | 151 | GC_TRY_ADDREF(ht); |
2659 | | |
2660 | 151 | zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
2661 | | |
2662 | 151 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2663 | 0 | zend_array_destroy(ht); |
2664 | 0 | return IS_NULL; |
2665 | 0 | } |
2666 | | |
2667 | 151 | if (EG(exception)) { |
2668 | 0 | return IS_NULL; |
2669 | 0 | } |
2670 | | |
2671 | 151 | value->str = ZSTR_EMPTY_ALLOC(); |
2672 | 151 | return IS_STRING; |
2673 | 63 | case IS_DOUBLE: |
2674 | | /* The array may be destroyed while throwing the notice. |
2675 | | * Temporarily increase the refcount to detect this situation. */ |
2676 | 63 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2677 | 62 | GC_ADDREF(ht); |
2678 | 62 | } |
2679 | 63 | value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); |
2680 | 63 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2681 | 0 | zend_array_destroy(ht); |
2682 | 0 | return IS_NULL; |
2683 | 0 | } |
2684 | 63 | if (EG(exception)) { |
2685 | 0 | return IS_NULL; |
2686 | 0 | } |
2687 | 63 | return IS_LONG; |
2688 | 0 | case IS_RESOURCE: |
2689 | | /* The array may be destroyed while throwing the notice. |
2690 | | * Temporarily increase the refcount to detect this situation. */ |
2691 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2692 | 0 | GC_ADDREF(ht); |
2693 | 0 | } |
2694 | 0 | zend_use_resource_as_offset(dim); |
2695 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2696 | 0 | zend_array_destroy(ht); |
2697 | 0 | return IS_NULL; |
2698 | 0 | } |
2699 | 0 | if (EG(exception)) { |
2700 | 0 | return IS_NULL; |
2701 | 0 | } |
2702 | 0 | value->lval = Z_RES_HANDLE_P(dim); |
2703 | 0 | return IS_LONG; |
2704 | 8 | case IS_FALSE: |
2705 | 8 | value->lval = 0; |
2706 | 8 | return IS_LONG; |
2707 | 0 | case IS_TRUE: |
2708 | 0 | value->lval = 1; |
2709 | 0 | return IS_LONG; |
2710 | 2 | default: |
2711 | 2 | zend_illegal_array_offset_access(dim); |
2712 | 2 | return IS_NULL; |
2713 | 224 | } |
2714 | 224 | } |
2715 | | |
2716 | | static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC) |
2717 | 1.27k | { |
2718 | 1.27k | switch (Z_TYPE_P(dim)) { |
2719 | 459 | case IS_UNDEF: { |
2720 | | /* The array may be destroyed while throwing the notice. |
2721 | | * Temporarily increase the refcount to detect this situation. */ |
2722 | 459 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2723 | 459 | GC_ADDREF(ht); |
2724 | 459 | } |
2725 | 459 | ZVAL_UNDEFINED_OP2(); |
2726 | 459 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2727 | 0 | if (!GC_REFCOUNT(ht)) { |
2728 | 0 | zend_array_destroy(ht); |
2729 | 0 | } |
2730 | 0 | return IS_NULL; |
2731 | 0 | } |
2732 | 459 | if (EG(exception)) { |
2733 | 0 | return IS_NULL; |
2734 | 0 | } |
2735 | 459 | ZEND_FALLTHROUGH; |
2736 | 459 | } |
2737 | 1.10k | case IS_NULL: |
2738 | | /* The array may be destroyed while throwing the notice. |
2739 | | * Temporarily increase the refcount to detect this situation. */ |
2740 | 1.10k | GC_TRY_ADDREF(ht); |
2741 | | |
2742 | 1.10k | zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
2743 | | |
2744 | 1.10k | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2745 | 0 | if (!GC_REFCOUNT(ht)) { |
2746 | 0 | zend_array_destroy(ht); |
2747 | 0 | } |
2748 | 0 | return IS_NULL; |
2749 | 0 | } |
2750 | 1.10k | if (EG(exception)) { |
2751 | 0 | return IS_NULL; |
2752 | 0 | } |
2753 | 1.10k | value->str = ZSTR_EMPTY_ALLOC(); |
2754 | 1.10k | return IS_STRING; |
2755 | 3 | case IS_DOUBLE: |
2756 | | /* The array may be destroyed while throwing the notice. |
2757 | | * Temporarily increase the refcount to detect this situation. */ |
2758 | 3 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2759 | 3 | GC_ADDREF(ht); |
2760 | 3 | } |
2761 | 3 | value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); |
2762 | 3 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2763 | 0 | if (!GC_REFCOUNT(ht)) { |
2764 | 0 | zend_array_destroy(ht); |
2765 | 0 | } |
2766 | 0 | return IS_NULL; |
2767 | 0 | } |
2768 | 3 | if (EG(exception)) { |
2769 | 0 | return IS_NULL; |
2770 | 0 | } |
2771 | 3 | return IS_LONG; |
2772 | 0 | case IS_RESOURCE: |
2773 | | /* The array may be destroyed while throwing the notice. |
2774 | | * Temporarily increase the refcount to detect this situation. */ |
2775 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2776 | 0 | GC_ADDREF(ht); |
2777 | 0 | } |
2778 | 0 | zend_use_resource_as_offset(dim); |
2779 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2780 | 0 | if (!GC_REFCOUNT(ht)) { |
2781 | 0 | zend_array_destroy(ht); |
2782 | 0 | } |
2783 | 0 | return IS_NULL; |
2784 | 0 | } |
2785 | 0 | if (EG(exception)) { |
2786 | 0 | return IS_NULL; |
2787 | 0 | } |
2788 | 0 | value->lval = Z_RES_HANDLE_P(dim); |
2789 | 0 | return IS_LONG; |
2790 | 2 | case IS_FALSE: |
2791 | 2 | value->lval = 0; |
2792 | 2 | return IS_LONG; |
2793 | 126 | case IS_TRUE: |
2794 | 126 | value->lval = 1; |
2795 | 126 | return IS_LONG; |
2796 | 42 | default: |
2797 | 42 | zend_illegal_array_offset_access(dim); |
2798 | 42 | return IS_NULL; |
2799 | 1.27k | } |
2800 | 1.27k | } |
2801 | | |
2802 | | static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int dim_type, int type EXECUTE_DATA_DC) |
2803 | 9.99k | { |
2804 | 9.99k | zval *retval = NULL; |
2805 | 9.99k | zend_string *offset_key; |
2806 | 9.99k | zend_ulong hval; |
2807 | | |
2808 | 9.99k | try_again: |
2809 | 9.99k | if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) { |
2810 | 5.27k | hval = Z_LVAL_P(dim); |
2811 | 5.48k | num_index: |
2812 | 5.48k | if (type != BP_VAR_W) { |
2813 | 2.69k | ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef); |
2814 | 2.50k | return retval; |
2815 | 194 | num_undef: |
2816 | 194 | switch (type) { |
2817 | 144 | case BP_VAR_R: |
2818 | 144 | zend_undefined_offset(hval); |
2819 | 144 | ZEND_FALLTHROUGH; |
2820 | 144 | case BP_VAR_UNSET: |
2821 | 145 | case BP_VAR_IS: |
2822 | 145 | retval = &EG(uninitialized_zval); |
2823 | 145 | break; |
2824 | 49 | case BP_VAR_RW: |
2825 | 49 | retval = zend_undefined_offset_write(ht, hval); |
2826 | 49 | break; |
2827 | 194 | } |
2828 | 2.78k | } else { |
2829 | 2.78k | ZEND_HASH_INDEX_LOOKUP(ht, hval, retval); |
2830 | 2.78k | } |
2831 | 5.48k | } else if (EXPECTED(Z_TYPE_P(dim) == IS_STRING)) { |
2832 | 3.22k | offset_key = Z_STR_P(dim); |
2833 | 3.22k | if (ZEND_CONST_COND(dim_type != IS_CONST, 1)) { |
2834 | 3.22k | if (ZEND_HANDLE_NUMERIC(offset_key, hval)) { |
2835 | 6 | goto num_index; |
2836 | 6 | } |
2837 | 3.22k | } |
2838 | 4.46k | str_index: |
2839 | 4.46k | if (type != BP_VAR_W) { |
2840 | 2.41k | retval = zend_hash_find_ex(ht, offset_key, ZEND_CONST_COND(dim_type == IS_CONST, 0)); |
2841 | 2.41k | if (!retval) { |
2842 | 629 | switch (type) { |
2843 | 34 | case BP_VAR_R: |
2844 | 34 | zend_undefined_index(offset_key); |
2845 | 34 | ZEND_FALLTHROUGH; |
2846 | 34 | case BP_VAR_UNSET: |
2847 | 116 | case BP_VAR_IS: |
2848 | 116 | retval = &EG(uninitialized_zval); |
2849 | 116 | break; |
2850 | 513 | case BP_VAR_RW: |
2851 | 513 | retval = zend_undefined_index_write(ht, offset_key); |
2852 | 513 | break; |
2853 | 629 | } |
2854 | 629 | } |
2855 | 2.41k | } else { |
2856 | 2.05k | retval = zend_hash_lookup(ht, offset_key); |
2857 | 2.05k | } |
2858 | 4.46k | } else if (EXPECTED(Z_TYPE_P(dim) == IS_REFERENCE)) { |
2859 | 0 | dim = Z_REFVAL_P(dim); |
2860 | 0 | goto try_again; |
2861 | 1.49k | } else { |
2862 | 1.49k | zend_value val; |
2863 | 1.49k | uint8_t t; |
2864 | | |
2865 | 1.49k | if (type != BP_VAR_W && type != BP_VAR_RW) { |
2866 | 224 | t = slow_index_convert(ht, dim, &val EXECUTE_DATA_CC); |
2867 | 1.27k | } else { |
2868 | 1.27k | t = slow_index_convert_w(ht, dim, &val EXECUTE_DATA_CC); |
2869 | 1.27k | } |
2870 | 1.49k | if (t == IS_STRING) { |
2871 | 1.25k | offset_key = val.str; |
2872 | 1.25k | goto str_index; |
2873 | 1.25k | } else if (t == IS_LONG) { |
2874 | 202 | hval = val.lval; |
2875 | 202 | goto num_index; |
2876 | 202 | } else { |
2877 | 44 | retval = (type == BP_VAR_W || type == BP_VAR_RW) ? |
2878 | 44 | NULL : &EG(uninitialized_zval); |
2879 | 44 | } |
2880 | 1.49k | } |
2881 | 7.48k | return retval; |
2882 | 9.99k | } |
2883 | | |
2884 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2885 | 2.08k | { |
2886 | 2.08k | return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_W EXECUTE_DATA_CC); |
2887 | 2.08k | } |
2888 | | |
2889 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W_CONST(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2890 | 1.07k | { |
2891 | 1.07k | return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_W EXECUTE_DATA_CC); |
2892 | 1.07k | } |
2893 | | |
2894 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2895 | 1.83k | { |
2896 | 1.83k | return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_RW EXECUTE_DATA_CC); |
2897 | 1.83k | } |
2898 | | |
2899 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW_CONST(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2900 | 118 | { |
2901 | 118 | return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_RW EXECUTE_DATA_CC); |
2902 | 118 | } |
2903 | | |
2904 | | static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *container, zval *dim, int dim_type, int type EXECUTE_DATA_DC) |
2905 | 2.67k | { |
2906 | 2.67k | zval *retval; |
2907 | | |
2908 | 2.67k | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
2909 | 1.65k | try_array: |
2910 | 1.65k | SEPARATE_ARRAY(container); |
2911 | 2.25k | fetch_from_array: |
2912 | 2.25k | if (dim == NULL) { |
2913 | 72 | retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval)); |
2914 | 72 | if (UNEXPECTED(retval == NULL)) { |
2915 | 0 | zend_cannot_add_element(); |
2916 | 0 | ZVAL_UNDEF(result); |
2917 | 0 | return; |
2918 | 0 | } |
2919 | 2.17k | } else { |
2920 | 2.17k | retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC); |
2921 | 2.17k | if (UNEXPECTED(!retval)) { |
2922 | | /* This may fail without throwing if the array was modified while throwing an |
2923 | | * undefined index error. */ |
2924 | 9 | ZVAL_NULL(result); |
2925 | 9 | return; |
2926 | 9 | } |
2927 | 2.17k | } |
2928 | 2.24k | ZVAL_INDIRECT(result, retval); |
2929 | 2.24k | return; |
2930 | 2.25k | } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) { |
2931 | 448 | zend_reference *ref = Z_REF_P(container); |
2932 | 448 | container = Z_REFVAL_P(container); |
2933 | 448 | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
2934 | 433 | goto try_array; |
2935 | 433 | } else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) { |
2936 | 12 | if (type != BP_VAR_UNSET) { |
2937 | 12 | if (ZEND_REF_HAS_TYPE_SOURCES(ref)) { |
2938 | 0 | if (UNEXPECTED(!zend_verify_ref_array_assignable(ref))) { |
2939 | 0 | ZVAL_UNDEF(result); |
2940 | 0 | return; |
2941 | 0 | } |
2942 | 0 | } |
2943 | 12 | array_init(container); |
2944 | 12 | goto fetch_from_array; |
2945 | 12 | } else { |
2946 | 0 | goto return_null; |
2947 | 0 | } |
2948 | 12 | } |
2949 | 448 | } |
2950 | 1.01k | if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) { |
2951 | 16 | if (dim == NULL) { |
2952 | 1 | zend_use_new_element_for_string(); |
2953 | 15 | } else { |
2954 | 15 | zend_check_string_offset(dim, type EXECUTE_DATA_CC); |
2955 | 15 | zend_wrong_string_offset_error(); |
2956 | 15 | } |
2957 | 16 | ZVAL_UNDEF(result); |
2958 | 994 | } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
2959 | 309 | zend_object *obj = Z_OBJ_P(container); |
2960 | 309 | GC_ADDREF(obj); |
2961 | 309 | if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
2962 | 0 | dim = ZVAL_UNDEFINED_OP2(); |
2963 | 309 | } else if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) { |
2964 | 0 | dim++; |
2965 | 0 | } |
2966 | 309 | retval = obj->handlers->read_dimension(obj, dim, type, result); |
2967 | | |
2968 | 309 | if (UNEXPECTED(retval == &EG(uninitialized_zval))) { |
2969 | 0 | zend_class_entry *ce = obj->ce; |
2970 | |
|
2971 | 0 | ZVAL_NULL(result); |
2972 | 0 | zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name)); |
2973 | 309 | } else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) { |
2974 | 305 | if (!Z_ISREF_P(retval)) { |
2975 | 297 | if (result != retval) { |
2976 | 297 | ZVAL_COPY(result, retval); |
2977 | 297 | retval = result; |
2978 | 297 | } |
2979 | 297 | if (Z_TYPE_P(retval) != IS_OBJECT) { |
2980 | 163 | zend_class_entry *ce = obj->ce; |
2981 | 163 | zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name)); |
2982 | 163 | } |
2983 | 297 | } else if (UNEXPECTED(Z_REFCOUNT_P(retval) == 1)) { |
2984 | 8 | ZVAL_UNREF(retval); |
2985 | 8 | } |
2986 | 305 | if (result != retval) { |
2987 | 8 | ZVAL_INDIRECT(result, retval); |
2988 | 8 | } |
2989 | 305 | } else { |
2990 | 4 | ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception"); |
2991 | 4 | ZVAL_UNDEF(result); |
2992 | 4 | } |
2993 | 309 | if (UNEXPECTED(GC_DELREF(obj) == 0)) { |
2994 | 0 | zend_objects_store_del(obj); |
2995 | 0 | } |
2996 | 685 | } else { |
2997 | 685 | if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) { |
2998 | 604 | if (type != BP_VAR_W && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) { |
2999 | 85 | ZVAL_UNDEFINED_OP1(); |
3000 | 85 | } |
3001 | 604 | if (type != BP_VAR_UNSET) { |
3002 | 588 | HashTable *ht = zend_new_array(0); |
3003 | 588 | uint8_t old_type = Z_TYPE_P(container); |
3004 | | |
3005 | 588 | ZVAL_ARR(container, ht); |
3006 | 588 | if (UNEXPECTED(old_type == IS_FALSE)) { |
3007 | 48 | GC_ADDREF(ht); |
3008 | 48 | zend_false_to_array_deprecated(); |
3009 | 48 | if (UNEXPECTED(GC_DELREF(ht) == 0)) { |
3010 | 0 | zend_array_destroy(ht); |
3011 | 0 | goto return_null; |
3012 | 0 | } |
3013 | 48 | } |
3014 | 588 | goto fetch_from_array; |
3015 | 588 | } else { |
3016 | 16 | if (UNEXPECTED(Z_TYPE_P(container) == IS_FALSE)) { |
3017 | 6 | zend_false_to_array_deprecated(); |
3018 | 6 | } |
3019 | 16 | return_null: |
3020 | | /* for read-mode only */ |
3021 | 16 | if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
3022 | 0 | ZVAL_UNDEFINED_OP2(); |
3023 | 0 | } |
3024 | 16 | ZVAL_NULL(result); |
3025 | 16 | } |
3026 | 604 | } else { |
3027 | 81 | if (type == BP_VAR_UNSET) { |
3028 | 9 | zend_throw_error(NULL, "Cannot unset offset in a non-array variable"); |
3029 | 9 | ZVAL_UNDEF(result); |
3030 | 72 | } else { |
3031 | 72 | zend_use_scalar_as_array(); |
3032 | 72 | ZVAL_UNDEF(result); |
3033 | 72 | } |
3034 | 81 | } |
3035 | 685 | } |
3036 | 1.01k | } |
3037 | | |
3038 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_W(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3039 | 2.16k | { |
3040 | 2.16k | zval *result = EX_VAR(opline->result.var); |
3041 | 2.16k | zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W EXECUTE_DATA_CC); |
3042 | 2.16k | } |
3043 | | |
3044 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_RW(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3045 | 474 | { |
3046 | 474 | zval *result = EX_VAR(opline->result.var); |
3047 | 474 | zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_RW EXECUTE_DATA_CC); |
3048 | 474 | } |
3049 | | |
3050 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_UNSET(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3051 | 33 | { |
3052 | 33 | zval *result = EX_VAR(opline->result.var); |
3053 | 33 | zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_UNSET EXECUTE_DATA_CC); |
3054 | 33 | } |
3055 | | |
3056 | | static zend_always_inline void zend_fetch_dimension_address_read(zval *result, zval *container, zval *dim, int dim_type, int type, bool is_list, bool slow EXECUTE_DATA_DC) |
3057 | 3.85k | { |
3058 | 3.85k | zval *retval; |
3059 | | |
3060 | 3.85k | if (!slow) { |
3061 | 1.90k | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
3062 | 1.17k | try_array: |
3063 | 1.17k | retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC); |
3064 | 1.17k | ZVAL_COPY_DEREF(result, retval); |
3065 | 1.17k | return; |
3066 | 1.17k | } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) { |
3067 | 4 | container = Z_REFVAL_P(container); |
3068 | 4 | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
3069 | 2 | goto try_array; |
3070 | 2 | } |
3071 | 4 | } |
3072 | 1.90k | } |
3073 | 2.68k | if (!is_list && EXPECTED(Z_TYPE_P(container) == IS_STRING)) { |
3074 | 88 | zend_string *str = Z_STR_P(container); |
3075 | 88 | zend_long offset; |
3076 | | |
3077 | 88 | try_string_offset: |
3078 | 88 | if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) { |
3079 | 44 | switch (Z_TYPE_P(dim)) { |
3080 | 22 | case IS_STRING: |
3081 | 22 | { |
3082 | 22 | bool trailing_data = false; |
3083 | | /* For BC reasons we allow errors so that we can warn on leading numeric string */ |
3084 | 22 | if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, |
3085 | 22 | NULL, /* allow errors */ true, NULL, &trailing_data)) { |
3086 | 3 | if (UNEXPECTED(trailing_data)) { |
3087 | 2 | zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim)); |
3088 | 2 | } |
3089 | 3 | goto out; |
3090 | 3 | } |
3091 | 19 | if (type == BP_VAR_IS) { |
3092 | 10 | ZVAL_NULL(result); |
3093 | 10 | return; |
3094 | 10 | } |
3095 | 9 | zend_illegal_string_offset(dim, BP_VAR_R); |
3096 | 9 | ZVAL_NULL(result); |
3097 | 9 | return; |
3098 | 19 | } |
3099 | 3 | case IS_UNDEF: |
3100 | | /* The string may be destroyed while throwing the notice. |
3101 | | * Temporarily increase the refcount to detect this situation. */ |
3102 | 3 | if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { |
3103 | 0 | GC_ADDREF(str); |
3104 | 0 | } |
3105 | 3 | ZVAL_UNDEFINED_OP2(); |
3106 | 3 | if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { |
3107 | 0 | zend_string_efree(str); |
3108 | 0 | ZVAL_NULL(result); |
3109 | 0 | return; |
3110 | 0 | } |
3111 | 3 | ZEND_FALLTHROUGH; |
3112 | 16 | case IS_DOUBLE: |
3113 | 16 | case IS_NULL: |
3114 | 22 | case IS_FALSE: |
3115 | 22 | case IS_TRUE: |
3116 | 22 | if (type != BP_VAR_IS) { |
3117 | | /* The string may be destroyed while throwing the notice. |
3118 | | * Temporarily increase the refcount to detect this situation. */ |
3119 | 16 | if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { |
3120 | 1 | GC_ADDREF(str); |
3121 | 1 | } |
3122 | 16 | zend_error(E_WARNING, "String offset cast occurred"); |
3123 | 16 | if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { |
3124 | 0 | zend_string_efree(str); |
3125 | 0 | ZVAL_NULL(result); |
3126 | 0 | return; |
3127 | 0 | } |
3128 | 16 | } |
3129 | | /* To prevent double warning */ |
3130 | 22 | if (Z_TYPE_P(dim) == IS_DOUBLE) { |
3131 | 13 | offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); |
3132 | 13 | goto out; |
3133 | 13 | } |
3134 | 9 | break; |
3135 | 9 | case IS_REFERENCE: |
3136 | 0 | dim = Z_REFVAL_P(dim); |
3137 | 0 | goto try_string_offset; |
3138 | 0 | default: |
3139 | 0 | zend_illegal_string_offset(dim, BP_VAR_R); |
3140 | 0 | ZVAL_NULL(result); |
3141 | 0 | return; |
3142 | 44 | } |
3143 | | |
3144 | 9 | offset = zval_get_long_func(dim, /* is_strict */ false); |
3145 | 44 | } else { |
3146 | 44 | offset = Z_LVAL_P(dim); |
3147 | 44 | } |
3148 | 69 | out: |
3149 | | |
3150 | 69 | if (UNEXPECTED(ZSTR_LEN(str) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) { |
3151 | 8 | if (type != BP_VAR_IS) { |
3152 | 7 | zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset); |
3153 | 7 | ZVAL_EMPTY_STRING(result); |
3154 | 7 | } else { |
3155 | 1 | ZVAL_NULL(result); |
3156 | 1 | } |
3157 | 61 | } else { |
3158 | 61 | zend_uchar c; |
3159 | 61 | zend_long real_offset; |
3160 | | |
3161 | 61 | real_offset = (UNEXPECTED(offset < 0)) /* Handle negative offset */ |
3162 | 61 | ? (zend_long)ZSTR_LEN(str) + offset : offset; |
3163 | 61 | c = (zend_uchar)ZSTR_VAL(str)[real_offset]; |
3164 | | |
3165 | 61 | ZVAL_CHAR(result, c); |
3166 | 61 | } |
3167 | 2.59k | } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
3168 | 377 | zend_object *obj = Z_OBJ_P(container); |
3169 | | |
3170 | 377 | GC_ADDREF(obj); |
3171 | 377 | if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
3172 | 0 | dim = ZVAL_UNDEFINED_OP2(); |
3173 | 0 | } |
3174 | 377 | if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) { |
3175 | 0 | dim++; |
3176 | 0 | } |
3177 | 377 | retval = obj->handlers->read_dimension(obj, dim, type, result); |
3178 | | |
3179 | 377 | ZEND_ASSERT(result != NULL); |
3180 | 377 | if (retval) { |
3181 | 365 | if (result != retval) { |
3182 | 272 | ZVAL_COPY_DEREF(result, retval); |
3183 | 272 | } else if (UNEXPECTED(Z_ISREF_P(retval))) { |
3184 | 9 | zend_unwrap_reference(result); |
3185 | 9 | } |
3186 | 365 | } else { |
3187 | 12 | ZVAL_NULL(result); |
3188 | 12 | } |
3189 | 377 | if (UNEXPECTED(GC_DELREF(obj) == 0)) { |
3190 | 0 | zend_objects_store_del(obj); |
3191 | 0 | } |
3192 | 2.21k | } else { |
3193 | 2.21k | if (type != BP_VAR_IS && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) { |
3194 | 1.38k | container = ZVAL_UNDEFINED_OP1(); |
3195 | 1.38k | } |
3196 | 2.21k | if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
3197 | 82 | ZVAL_UNDEFINED_OP2(); |
3198 | 82 | } |
3199 | 2.21k | if (is_list && Z_TYPE_P(container) > IS_NULL) { |
3200 | 48 | zend_error(E_WARNING, "Cannot use %s as array", zend_zval_type_name(container)); |
3201 | 48 | } |
3202 | 2.21k | if (!is_list && type != BP_VAR_IS) { |
3203 | 1.87k | zend_error(E_WARNING, "Trying to access array offset on %s", |
3204 | 1.87k | zend_zval_value_name(container)); |
3205 | 1.87k | } |
3206 | 2.21k | ZVAL_NULL(result); |
3207 | 2.21k | } |
3208 | 2.68k | } |
3209 | | |
3210 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_read_R(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3211 | 423 | { |
3212 | 423 | zval *result = EX_VAR(opline->result.var); |
3213 | 423 | zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 0, 0 EXECUTE_DATA_CC); |
3214 | 423 | } |
3215 | | |
3216 | | static zend_never_inline void zend_fetch_dimension_address_read_R_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC) |
3217 | 1.95k | { |
3218 | 1.95k | zval *result = EX_VAR(opline->result.var); |
3219 | 1.95k | zend_fetch_dimension_address_read(result, container, dim, IS_CV, BP_VAR_R, 0, 1 EXECUTE_DATA_CC); |
3220 | 1.95k | } |
3221 | | |
3222 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_read_IS(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3223 | 1.16k | { |
3224 | 1.16k | zval *result = EX_VAR(opline->result.var); |
3225 | 1.16k | zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_IS, 0, 0 EXECUTE_DATA_CC); |
3226 | 1.16k | } |
3227 | | |
3228 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_LIST_r(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3229 | 304 | { |
3230 | 304 | zval *result = EX_VAR(opline->result.var); |
3231 | 304 | zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 1, 0 EXECUTE_DATA_CC); |
3232 | 304 | } |
3233 | | |
3234 | | ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *dim, int type) |
3235 | 12 | { |
3236 | 12 | zend_fetch_dimension_address_read(result, container, dim, IS_TMP_VAR, type, 0, 0 NO_EXECUTE_DATA_CC); |
3237 | 12 | } |
3238 | | |
3239 | | static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable *ht, zval *offset EXECUTE_DATA_DC) |
3240 | 0 | { |
3241 | 0 | zend_ulong hval; |
3242 | |
|
3243 | 0 | if (Z_TYPE_P(offset) == IS_DOUBLE) { |
3244 | | /* The array may be destroyed while throwing a warning in case the float is not representable as an int. |
3245 | | * Temporarily increase the refcount to detect this situation. */ |
3246 | 0 | GC_TRY_ADDREF(ht); |
3247 | 0 | hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); |
3248 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
3249 | 0 | zend_array_destroy(ht); |
3250 | 0 | return NULL; |
3251 | 0 | } |
3252 | 0 | if (EG(exception)) { |
3253 | 0 | return NULL; |
3254 | 0 | } |
3255 | 0 | num_idx: |
3256 | 0 | return zend_hash_index_find(ht, hval); |
3257 | 0 | } else if (Z_TYPE_P(offset) == IS_NULL) { |
3258 | 0 | null_undef_idx: |
3259 | | /* The array may be destroyed while throwing the notice. |
3260 | | * Temporarily increase the refcount to detect this situation. */ |
3261 | 0 | GC_TRY_ADDREF(ht); |
3262 | |
|
3263 | 0 | zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
3264 | |
|
3265 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
3266 | 0 | zend_array_destroy(ht); |
3267 | 0 | return NULL; |
3268 | 0 | } |
3269 | | |
3270 | 0 | if (EG(exception)) { |
3271 | 0 | return NULL; |
3272 | 0 | } |
3273 | | |
3274 | 0 | return zend_hash_find_known_hash(ht, ZSTR_EMPTY_ALLOC()); |
3275 | 0 | } else if (Z_TYPE_P(offset) == IS_FALSE) { |
3276 | 0 | hval = 0; |
3277 | 0 | goto num_idx; |
3278 | 0 | } else if (Z_TYPE_P(offset) == IS_TRUE) { |
3279 | 0 | hval = 1; |
3280 | 0 | goto num_idx; |
3281 | 0 | } else if (Z_TYPE_P(offset) == IS_RESOURCE) { |
3282 | 0 | zend_use_resource_as_offset(offset); |
3283 | 0 | hval = Z_RES_HANDLE_P(offset); |
3284 | 0 | goto num_idx; |
3285 | 0 | } else if (/*OP2_TYPE == IS_CV &&*/ Z_TYPE_P(offset) == IS_UNDEF) { |
3286 | 0 | ZVAL_UNDEFINED_OP2(); |
3287 | 0 | goto null_undef_idx; |
3288 | 0 | } else { |
3289 | 0 | zend_illegal_array_offset_isset(offset); |
3290 | 0 | return NULL; |
3291 | 0 | } |
3292 | 0 | } |
3293 | | |
3294 | | static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC) |
3295 | 363 | { |
3296 | 363 | if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { |
3297 | 0 | offset = ZVAL_UNDEFINED_OP2(); |
3298 | 0 | } |
3299 | | |
3300 | 363 | if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
3301 | 138 | return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0); |
3302 | 225 | } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */ |
3303 | 204 | zend_long lval; |
3304 | | |
3305 | 204 | if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) { |
3306 | 80 | lval = Z_LVAL_P(offset); |
3307 | 165 | str_offset: |
3308 | 165 | if (UNEXPECTED(lval < 0)) { /* Handle negative offset */ |
3309 | 46 | lval += (zend_long)Z_STRLEN_P(container); |
3310 | 46 | } |
3311 | 165 | if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) { |
3312 | 119 | return 1; |
3313 | 119 | } else { |
3314 | 46 | return 0; |
3315 | 46 | } |
3316 | 165 | } else { |
3317 | | /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/ |
3318 | 124 | ZVAL_DEREF(offset); |
3319 | | /*}*/ |
3320 | 124 | if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */ |
3321 | 88 | || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */ |
3322 | 85 | && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) { |
3323 | 85 | lval = zval_get_long_ex(offset, /* is_strict */ true); |
3324 | 85 | goto str_offset; |
3325 | 85 | } |
3326 | 39 | return 0; |
3327 | 124 | } |
3328 | 204 | } else { |
3329 | 21 | return 0; |
3330 | 21 | } |
3331 | 363 | } |
3332 | | |
3333 | | static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC) |
3334 | 241 | { |
3335 | 241 | if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { |
3336 | 0 | offset = ZVAL_UNDEFINED_OP2(); |
3337 | 0 | } |
3338 | | |
3339 | 241 | if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
3340 | 67 | return !Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 1); |
3341 | 174 | } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */ |
3342 | 171 | zend_long lval; |
3343 | | |
3344 | 171 | if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) { |
3345 | 72 | lval = Z_LVAL_P(offset); |
3346 | 141 | str_offset: |
3347 | 141 | if (UNEXPECTED(lval < 0)) { /* Handle negative offset */ |
3348 | 51 | lval += (zend_long)Z_STRLEN_P(container); |
3349 | 51 | } |
3350 | 141 | if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) { |
3351 | 105 | return (Z_STRVAL_P(container)[lval] == '0'); |
3352 | 105 | } else { |
3353 | 36 | return 1; |
3354 | 36 | } |
3355 | 141 | } else { |
3356 | | /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/ |
3357 | 99 | ZVAL_DEREF(offset); |
3358 | | /*}*/ |
3359 | 99 | if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */ |
3360 | 60 | || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */ |
3361 | 69 | && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) { |
3362 | 69 | lval = zval_get_long_ex(offset, /* is_strict */ true); |
3363 | 69 | goto str_offset; |
3364 | 69 | } |
3365 | 30 | return 1; |
3366 | 99 | } |
3367 | 171 | } else { |
3368 | 3 | return 1; |
3369 | 3 | } |
3370 | 241 | } |
3371 | | |
3372 | | static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable *ht, zval *key OPLINE_DC EXECUTE_DATA_DC) |
3373 | 5 | { |
3374 | 5 | zend_string *str; |
3375 | 5 | zend_ulong hval; |
3376 | | |
3377 | 5 | try_again: |
3378 | 5 | if (EXPECTED(Z_TYPE_P(key) == IS_STRING)) { |
3379 | 1 | str = Z_STR_P(key); |
3380 | 1 | if (ZEND_HANDLE_NUMERIC(str, hval)) { |
3381 | 0 | goto num_key; |
3382 | 0 | } |
3383 | 4 | str_key: |
3384 | 4 | return zend_hash_exists(ht, str); |
3385 | 4 | } else if (EXPECTED(Z_TYPE_P(key) == IS_LONG)) { |
3386 | 1 | hval = Z_LVAL_P(key); |
3387 | 1 | num_key: |
3388 | 1 | return zend_hash_index_exists(ht, hval); |
3389 | 3 | } else if (EXPECTED(Z_ISREF_P(key))) { |
3390 | 0 | key = Z_REFVAL_P(key); |
3391 | 0 | goto try_again; |
3392 | 3 | } else if (Z_TYPE_P(key) == IS_DOUBLE) { |
3393 | | /* The array may be destroyed while throwing a warning in case the float is not representable as an int. |
3394 | | * Temporarily increase the refcount to detect this situation. */ |
3395 | 0 | GC_TRY_ADDREF(ht); |
3396 | 0 | hval = zend_dval_to_lval_safe(Z_DVAL_P(key)); |
3397 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
3398 | 0 | zend_array_destroy(ht); |
3399 | 0 | return false; |
3400 | 0 | } |
3401 | 0 | if (EG(exception)) { |
3402 | 0 | return false; |
3403 | 0 | } |
3404 | 0 | goto num_key; |
3405 | 3 | } else if (Z_TYPE_P(key) == IS_FALSE) { |
3406 | 0 | hval = 0; |
3407 | 0 | goto num_key; |
3408 | 3 | } else if (Z_TYPE_P(key) == IS_TRUE) { |
3409 | 0 | hval = 1; |
3410 | 0 | goto num_key; |
3411 | 3 | } else if (Z_TYPE_P(key) == IS_RESOURCE) { |
3412 | 0 | zend_use_resource_as_offset(key); |
3413 | 0 | hval = Z_RES_HANDLE_P(key); |
3414 | 0 | goto num_key; |
3415 | 3 | } else if (Z_TYPE_P(key) <= IS_NULL) { |
3416 | 3 | if (UNEXPECTED(Z_TYPE_P(key) == IS_UNDEF)) { |
3417 | 0 | ZVAL_UNDEFINED_OP1(); |
3418 | 3 | } else { |
3419 | 3 | ZEND_ASSERT(Z_TYPE_P(key) == IS_NULL); |
3420 | 3 | zend_error(E_DEPRECATED, "Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead"); |
3421 | 3 | } |
3422 | 3 | str = ZSTR_EMPTY_ALLOC(); |
3423 | 3 | goto str_key; |
3424 | 3 | } else { |
3425 | 0 | zend_illegal_array_offset_access(key); |
3426 | 0 | return 0; |
3427 | 0 | } |
3428 | 5 | } |
3429 | | |
3430 | | static ZEND_COLD void ZEND_FASTCALL zend_array_key_exists_error( |
3431 | | zval *subject, zval *key OPLINE_DC EXECUTE_DATA_DC) |
3432 | 3 | { |
3433 | 3 | if (Z_TYPE_P(key) == IS_UNDEF) { |
3434 | 0 | ZVAL_UNDEFINED_OP1(); |
3435 | 0 | } |
3436 | 3 | if (Z_TYPE_P(subject) == IS_UNDEF) { |
3437 | 0 | ZVAL_UNDEFINED_OP2(); |
3438 | 0 | } |
3439 | 3 | if (!EG(exception)) { |
3440 | 3 | zend_type_error("array_key_exists(): Argument #2 ($array) must be of type array, %s given", |
3441 | 3 | zend_zval_value_name(subject)); |
3442 | 3 | } |
3443 | 3 | } |
3444 | | |
3445 | 24 | static zend_always_inline bool promotes_to_array(zval *val) { |
3446 | 24 | return Z_TYPE_P(val) <= IS_FALSE |
3447 | 18 | || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE); |
3448 | 24 | } |
3449 | | |
3450 | 6 | static zend_always_inline bool check_type_array_assignable(zend_type type) { |
3451 | 6 | if (!ZEND_TYPE_IS_SET(type)) { |
3452 | 0 | return 1; |
3453 | 0 | } |
3454 | 6 | return (ZEND_TYPE_FULL_MASK(type) & MAY_BE_ARRAY) != 0; |
3455 | 6 | } |
3456 | | |
3457 | | /* Checks whether an array can be assigned to the reference. Throws error if not assignable. */ |
3458 | 0 | ZEND_API bool zend_verify_ref_array_assignable(zend_reference *ref) { |
3459 | 0 | zend_property_info *prop; |
3460 | 0 | ZEND_ASSERT(ZEND_REF_HAS_TYPE_SOURCES(ref)); |
3461 | 0 | ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) { |
3462 | 0 | if (!check_type_array_assignable(prop->type)) { |
3463 | 0 | zend_throw_auto_init_in_ref_error(prop); |
3464 | 0 | return 0; |
3465 | 0 | } |
3466 | 0 | } ZEND_REF_FOREACH_TYPE_SOURCES_END(); |
3467 | 0 | return 1; |
3468 | 0 | } |
3469 | | |
3470 | | static zend_never_inline bool zend_handle_fetch_obj_flags( |
3471 | | zval *result, zval *ptr, zend_object *obj, zend_property_info *prop_info, uint32_t flags) |
3472 | 408 | { |
3473 | 408 | switch (flags) { |
3474 | 24 | case ZEND_FETCH_DIM_WRITE: |
3475 | 24 | if (promotes_to_array(ptr)) { |
3476 | 6 | if (!prop_info) { |
3477 | 0 | break; |
3478 | 0 | } |
3479 | 6 | if (!check_type_array_assignable(prop_info->type)) { |
3480 | 0 | zend_throw_auto_init_in_prop_error(prop_info); |
3481 | 0 | if (result) ZVAL_ERROR(result); |
3482 | 0 | return 0; |
3483 | 0 | } |
3484 | 6 | } |
3485 | 24 | break; |
3486 | 384 | case ZEND_FETCH_REF: |
3487 | 384 | if (Z_TYPE_P(ptr) != IS_REFERENCE) { |
3488 | 234 | if (!prop_info) { |
3489 | 0 | break; |
3490 | 0 | } |
3491 | 234 | if (Z_TYPE_P(ptr) == IS_UNDEF) { |
3492 | 2 | if (!ZEND_TYPE_ALLOW_NULL(prop_info->type)) { |
3493 | 1 | zend_throw_access_uninit_prop_by_ref_error(prop_info); |
3494 | 1 | if (result) ZVAL_ERROR(result); |
3495 | 1 | return 0; |
3496 | 1 | } |
3497 | 1 | ZVAL_NULL(ptr); |
3498 | 1 | } |
3499 | | |
3500 | 233 | ZVAL_NEW_REF(ptr, ptr); |
3501 | 233 | ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(ptr), prop_info); |
3502 | 233 | } |
3503 | 383 | break; |
3504 | 408 | EMPTY_SWITCH_DEFAULT_CASE() |
3505 | 408 | } |
3506 | 407 | return 1; |
3507 | 408 | } |
3508 | | |
3509 | | static zend_always_inline void zend_fetch_property_address(zval *result, zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, void **cache_slot, int type, uint32_t flags, zend_property_info **prop_info_p OPLINE_DC EXECUTE_DATA_DC) |
3510 | 1.21k | { |
3511 | 1.21k | zval *ptr; |
3512 | 1.21k | zend_object *zobj; |
3513 | 1.21k | zend_string *name, *tmp_name; |
3514 | 1.21k | void *_cache_slot[3] = {0}; |
3515 | 1.21k | if (prop_op_type != IS_CONST) { |
3516 | 507 | cache_slot = _cache_slot; |
3517 | 706 | } else { |
3518 | 706 | ZEND_ASSERT(cache_slot); |
3519 | 706 | } |
3520 | | |
3521 | 1.21k | if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) { |
3522 | 83 | do { |
3523 | 83 | if (Z_ISREF_P(container) && Z_TYPE_P(Z_REFVAL_P(container)) == IS_OBJECT) { |
3524 | 48 | container = Z_REFVAL_P(container); |
3525 | 48 | break; |
3526 | 48 | } |
3527 | | |
3528 | 35 | if (container_op_type == IS_CV |
3529 | 22 | && type != BP_VAR_W |
3530 | 5 | && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) { |
3531 | 2 | ZVAL_UNDEFINED_OP1(); |
3532 | 2 | } |
3533 | | |
3534 | | /* this should modify object only if it's empty */ |
3535 | 35 | if (type == BP_VAR_UNSET) { |
3536 | 6 | ZVAL_NULL(result); |
3537 | 6 | return; |
3538 | 6 | } |
3539 | | |
3540 | 29 | zend_throw_non_object_error(container, prop_ptr OPLINE_CC EXECUTE_DATA_CC); |
3541 | 29 | ZVAL_ERROR(result); |
3542 | 29 | return; |
3543 | 35 | } while (0); |
3544 | 83 | } |
3545 | | |
3546 | 1.17k | zobj = Z_OBJ_P(container); |
3547 | 1.17k | if (prop_op_type == IS_CONST && |
3548 | 680 | EXPECTED(zobj->ce == CACHED_PTR_EX(cache_slot))) { |
3549 | 221 | uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1); |
3550 | 221 | if (prop_info_p) { |
3551 | 0 | *prop_info_p = CACHED_PTR_EX(cache_slot + 2); |
3552 | 0 | } |
3553 | | |
3554 | 221 | if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { |
3555 | 217 | ptr = OBJ_PROP(zobj, prop_offset); |
3556 | 217 | if (EXPECTED(Z_TYPE_P(ptr) != IS_UNDEF)) { |
3557 | 187 | ZVAL_INDIRECT(result, ptr); |
3558 | 187 | zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2); |
3559 | 187 | if (prop_info) { |
3560 | 90 | if (UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK)) |
3561 | 18 | && ((prop_info->flags & ZEND_ACC_READONLY) || !zend_asymmetric_property_has_set_access(prop_info))) { |
3562 | | /* For objects, W/RW/UNSET fetch modes might not actually modify object. |
3563 | | * Similar as with magic __get() allow them, but return the value as a copy |
3564 | | * to make sure no actual modification is possible. */ |
3565 | 18 | ZEND_ASSERT(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET); |
3566 | 18 | if (Z_TYPE_P(ptr) == IS_OBJECT) { |
3567 | 12 | ZVAL_COPY(result, ptr); |
3568 | 12 | } else { |
3569 | 6 | if (prop_info->flags & ZEND_ACC_READONLY) { |
3570 | 6 | zend_readonly_property_indirect_modification_error(prop_info); |
3571 | 6 | } else { |
3572 | 0 | zend_asymmetric_visibility_property_modification_error(prop_info, "indirectly modify"); |
3573 | 0 | } |
3574 | 6 | ZVAL_ERROR(result); |
3575 | 6 | } |
3576 | 18 | return; |
3577 | 18 | } |
3578 | 72 | flags &= ZEND_FETCH_OBJ_FLAGS; |
3579 | 72 | if (flags) { |
3580 | 72 | zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags); |
3581 | 72 | } |
3582 | 72 | } |
3583 | 169 | return; |
3584 | 187 | } |
3585 | 217 | } else if (UNEXPECTED(IS_HOOKED_PROPERTY_OFFSET(prop_offset))) { |
3586 | | /* Fall through to read_property for hooks. */ |
3587 | 4 | } else if (EXPECTED(zobj->properties != NULL)) { |
3588 | 3 | ZEND_ASSERT(IS_DYNAMIC_PROPERTY_OFFSET(prop_offset)); |
3589 | 3 | if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) { |
3590 | 0 | if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) { |
3591 | 0 | GC_DELREF(zobj->properties); |
3592 | 0 | } |
3593 | 0 | zobj->properties = zend_array_dup(zobj->properties); |
3594 | 0 | } |
3595 | 3 | ptr = zend_hash_find_known_hash(zobj->properties, Z_STR_P(prop_ptr)); |
3596 | 3 | if (EXPECTED(ptr)) { |
3597 | 0 | ZVAL_INDIRECT(result, ptr); |
3598 | 0 | return; |
3599 | 0 | } |
3600 | 3 | } |
3601 | 957 | } else if (prop_op_type == IS_CONST) { |
3602 | | /* CE mismatch, make cache slot consistent */ |
3603 | 459 | cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL; |
3604 | 459 | } |
3605 | | |
3606 | | /* Pointer on property callback is required */ |
3607 | 991 | ZEND_ASSERT(zobj->handlers->get_property_ptr_ptr != NULL); |
3608 | | |
3609 | 991 | if (prop_op_type == IS_CONST) { |
3610 | 493 | name = Z_STR_P(prop_ptr); |
3611 | 498 | } else { |
3612 | 498 | name = zval_get_tmp_string(prop_ptr, &tmp_name); |
3613 | 498 | } |
3614 | 991 | ptr = zobj->handlers->get_property_ptr_ptr(zobj, name, type, cache_slot); |
3615 | 991 | if (NULL == ptr) { |
3616 | 69 | ptr = zobj->handlers->read_property(zobj, name, type, cache_slot, result); |
3617 | 69 | if (ptr == result) { |
3618 | 20 | if (UNEXPECTED(Z_ISREF_P(ptr) && Z_REFCOUNT_P(ptr) == 1)) { |
3619 | 0 | ZVAL_UNREF(ptr); |
3620 | 0 | } |
3621 | 20 | goto end; |
3622 | 20 | } |
3623 | 49 | if (UNEXPECTED(EG(exception))) { |
3624 | 38 | ZVAL_ERROR(result); |
3625 | 38 | goto end; |
3626 | 38 | } |
3627 | 922 | } else if (UNEXPECTED(Z_ISERROR_P(ptr))) { |
3628 | 0 | ZVAL_ERROR(result); |
3629 | 0 | goto end; |
3630 | 0 | } |
3631 | | |
3632 | 933 | ZVAL_INDIRECT(result, ptr); |
3633 | 933 | flags &= ZEND_FETCH_OBJ_FLAGS; |
3634 | 933 | if (flags) { |
3635 | 645 | zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2); |
3636 | 645 | if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) { |
3637 | 317 | if (UNEXPECTED(!zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags))) { |
3638 | 1 | goto end; |
3639 | 1 | } |
3640 | 317 | } |
3641 | 645 | } |
3642 | | |
3643 | 991 | end: |
3644 | 991 | if (prop_info_p) { |
3645 | 224 | *prop_info_p = CACHED_PTR_EX(cache_slot + 2); |
3646 | 224 | } |
3647 | 991 | if (prop_op_type != IS_CONST) { |
3648 | 498 | zend_tmp_string_release(tmp_name); |
3649 | 498 | } |
3650 | 991 | } |
3651 | | |
3652 | | static zend_always_inline void zend_assign_to_property_reference(zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3653 | 232 | { |
3654 | 232 | zval variable, *variable_ptr = &variable; |
3655 | 232 | void **cache_addr = (prop_op_type == IS_CONST) ? CACHE_ADDR(opline->extended_value & ~ZEND_RETURNS_FUNCTION) : NULL; |
3656 | 232 | zend_refcounted *garbage = NULL; |
3657 | 232 | zend_property_info *prop_info = NULL; |
3658 | | |
3659 | 232 | zend_fetch_property_address(variable_ptr, container, container_op_type, prop_ptr, prop_op_type, |
3660 | 232 | cache_addr, BP_VAR_W, 0, &prop_info OPLINE_CC EXECUTE_DATA_CC); |
3661 | | |
3662 | 232 | if (EXPECTED(Z_TYPE_P(variable_ptr) == IS_INDIRECT)) { |
3663 | 221 | variable_ptr = Z_INDIRECT_P(variable_ptr); |
3664 | 221 | if (/*OP_DATA_TYPE == IS_VAR &&*/ |
3665 | 221 | (opline->extended_value & ZEND_RETURNS_FUNCTION) && |
3666 | 1 | UNEXPECTED(!Z_ISREF_P(value_ptr))) { |
3667 | | |
3668 | 1 | variable_ptr = zend_wrong_assign_to_variable_reference( |
3669 | 1 | variable_ptr, value_ptr, &garbage OPLINE_CC EXECUTE_DATA_CC); |
3670 | 220 | } else if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) { |
3671 | 138 | variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr, &garbage EXECUTE_DATA_CC); |
3672 | 138 | } else { |
3673 | 82 | zend_assign_to_variable_reference(variable_ptr, value_ptr, &garbage); |
3674 | 82 | } |
3675 | 221 | } else if (Z_ISERROR_P(variable_ptr)) { |
3676 | 9 | variable_ptr = &EG(uninitialized_zval); |
3677 | 9 | } else { |
3678 | 2 | zend_throw_error(NULL, "Cannot assign by reference to overloaded object"); |
3679 | 2 | zval_ptr_dtor(&variable); |
3680 | 2 | variable_ptr = &EG(uninitialized_zval); |
3681 | 2 | } |
3682 | | |
3683 | 232 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
3684 | 39 | ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr); |
3685 | 39 | } |
3686 | 232 | if (garbage) { |
3687 | 119 | GC_DTOR(garbage); |
3688 | 119 | } |
3689 | 232 | } |
3690 | | |
3691 | | static zend_never_inline void zend_assign_to_property_reference_this_const(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3692 | 3 | { |
3693 | 3 | zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_CONST, value_ptr |
3694 | 3 | OPLINE_CC EXECUTE_DATA_CC); |
3695 | 3 | } |
3696 | | |
3697 | | static zend_never_inline void zend_assign_to_property_reference_var_const(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3698 | 40 | { |
3699 | 40 | zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_CONST, value_ptr |
3700 | 40 | OPLINE_CC EXECUTE_DATA_CC); |
3701 | 40 | } |
3702 | | |
3703 | | static zend_never_inline void zend_assign_to_property_reference_this_var(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3704 | 0 | { |
3705 | 0 | zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_VAR, value_ptr |
3706 | 0 | OPLINE_CC EXECUTE_DATA_CC); |
3707 | 0 | } |
3708 | | |
3709 | | static zend_never_inline void zend_assign_to_property_reference_var_var(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3710 | 189 | { |
3711 | 189 | zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_VAR, value_ptr |
3712 | 189 | OPLINE_CC EXECUTE_DATA_CC); |
3713 | 189 | } |
3714 | | |
3715 | 748 | static zend_never_inline zval* zend_fetch_static_property_address_ex(zend_property_info **prop_info, uint32_t cache_slot, int fetch_type OPLINE_DC EXECUTE_DATA_DC) { |
3716 | 748 | zval *result; |
3717 | 748 | zend_string *name; |
3718 | 748 | zend_class_entry *ce; |
3719 | 748 | zend_property_info *property_info; |
3720 | | |
3721 | 748 | uint8_t op1_type = opline->op1_type, op2_type = opline->op2_type; |
3722 | | |
3723 | 748 | if (EXPECTED(op2_type == IS_CONST)) { |
3724 | 590 | zval *class_name = RT_CONSTANT(opline, opline->op2); |
3725 | | |
3726 | 590 | ZEND_ASSERT(op1_type != IS_CONST || CACHED_PTR(cache_slot) == NULL); |
3727 | | |
3728 | 590 | if (EXPECTED((ce = CACHED_PTR(cache_slot)) == NULL)) { |
3729 | 548 | ce = zend_fetch_class_by_name(Z_STR_P(class_name), Z_STR_P(class_name + 1), ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); |
3730 | 548 | if (UNEXPECTED(ce == NULL)) { |
3731 | 10 | FREE_OP(op1_type, opline->op1.var); |
3732 | 10 | return NULL; |
3733 | 10 | } |
3734 | 538 | if (UNEXPECTED(op1_type != IS_CONST)) { |
3735 | 6 | CACHE_PTR(cache_slot, ce); |
3736 | 6 | } |
3737 | 538 | } |
3738 | 590 | } else { |
3739 | 158 | if (EXPECTED(op2_type == IS_UNUSED)) { |
3740 | 110 | ce = zend_fetch_class(NULL, opline->op2.num); |
3741 | 110 | if (UNEXPECTED(ce == NULL)) { |
3742 | 0 | FREE_OP(op1_type, opline->op1.var); |
3743 | 0 | return NULL; |
3744 | 0 | } |
3745 | 110 | } else { |
3746 | 48 | ce = Z_CE_P(EX_VAR(opline->op2.var)); |
3747 | 48 | } |
3748 | 158 | if (EXPECTED(op1_type == IS_CONST) && EXPECTED(CACHED_PTR(cache_slot) == ce)) { |
3749 | 0 | result = CACHED_PTR(cache_slot + sizeof(void *)); |
3750 | 0 | *prop_info = CACHED_PTR(cache_slot + sizeof(void *) * 2); |
3751 | 0 | return result; |
3752 | 0 | } |
3753 | 158 | } |
3754 | | |
3755 | 738 | if (EXPECTED(op1_type == IS_CONST)) { |
3756 | 690 | name = Z_STR_P(RT_CONSTANT(opline, opline->op1)); |
3757 | 690 | result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info); |
3758 | 690 | } else { |
3759 | 48 | zend_string *tmp_name; |
3760 | 48 | zval *varname = get_zval_ptr_undef(opline->op1_type, opline->op1, BP_VAR_R); |
3761 | 48 | if (EXPECTED(Z_TYPE_P(varname) == IS_STRING)) { |
3762 | 48 | name = Z_STR_P(varname); |
3763 | 48 | tmp_name = NULL; |
3764 | 48 | } else { |
3765 | 0 | if (op1_type == IS_CV && UNEXPECTED(Z_TYPE_P(varname) == IS_UNDEF)) { |
3766 | 0 | zval_undefined_cv(opline->op1.var EXECUTE_DATA_CC); |
3767 | 0 | } |
3768 | 0 | name = zval_get_tmp_string(varname, &tmp_name); |
3769 | 0 | } |
3770 | 48 | result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info); |
3771 | | |
3772 | 48 | zend_tmp_string_release(tmp_name); |
3773 | | |
3774 | 48 | FREE_OP(op1_type, opline->op1.var); |
3775 | 48 | } |
3776 | | |
3777 | 738 | if (UNEXPECTED(result == NULL)) { |
3778 | 62 | return NULL; |
3779 | 62 | } |
3780 | | |
3781 | 676 | *prop_info = property_info; |
3782 | | |
3783 | 676 | if (EXPECTED(op1_type == IS_CONST) |
3784 | 628 | && EXPECTED(!(property_info->ce->ce_flags & ZEND_ACC_TRAIT))) { |
3785 | 628 | CACHE_POLYMORPHIC_PTR(cache_slot, ce, result); |
3786 | 628 | CACHE_PTR(cache_slot + sizeof(void *) * 2, property_info); |
3787 | 628 | } |
3788 | | |
3789 | 676 | return result; |
3790 | 738 | } |
3791 | | |
3792 | | |
3793 | 1.21k | static zend_always_inline zval* zend_fetch_static_property_address(zend_property_info **prop_info, uint32_t cache_slot, int fetch_type, int flags OPLINE_DC EXECUTE_DATA_DC) { |
3794 | 1.21k | zval *result; |
3795 | 1.21k | zend_property_info *property_info; |
3796 | | |
3797 | 1.21k | if (opline->op1_type == IS_CONST |
3798 | 1.16k | && (opline->op2_type == IS_CONST |
3799 | 285 | || (opline->op2_type == IS_UNUSED |
3800 | 237 | && ((opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF |
3801 | 33 | || (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT))) |
3802 | 1.08k | && EXPECTED(CACHED_PTR(cache_slot + sizeof(void *)) != NULL)) { |
3803 | 469 | result = CACHED_PTR(cache_slot + sizeof(void *)); |
3804 | 469 | property_info = CACHED_PTR(cache_slot + sizeof(void *) * 2); |
3805 | | |
3806 | 469 | if ((fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW) |
3807 | 402 | && UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF) |
3808 | 0 | && ZEND_TYPE_IS_SET(property_info->type)) { |
3809 | 0 | zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization", |
3810 | 0 | ZSTR_VAL(property_info->ce->name), |
3811 | 0 | zend_get_unmangled_property_name(property_info->name)); |
3812 | 0 | return NULL; |
3813 | 0 | } |
3814 | 748 | } else { |
3815 | 748 | result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC); |
3816 | 748 | if (UNEXPECTED(!result)) { |
3817 | 72 | return NULL; |
3818 | 72 | } |
3819 | 748 | } |
3820 | | |
3821 | 1.14k | flags &= ZEND_FETCH_OBJ_FLAGS; |
3822 | 1.14k | if (flags && ZEND_TYPE_IS_SET(property_info->type)) { |
3823 | 19 | zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags); |
3824 | 19 | } |
3825 | | |
3826 | 1.14k | if (prop_info) { |
3827 | 1.10k | *prop_info = property_info; |
3828 | 1.10k | } |
3829 | | |
3830 | 1.14k | return result; |
3831 | 1.21k | } |
3832 | | |
3833 | 0 | ZEND_API zval* ZEND_FASTCALL zend_fetch_static_property(zend_execute_data *ex, int fetch_type) { |
3834 | 0 | zval *result; |
3835 | 0 | zend_property_info *property_info; |
3836 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3837 | | zend_execute_data *orig_execute_data = execute_data; |
3838 | | #else |
3839 | 0 | zend_execute_data *execute_data; |
3840 | 0 | #endif |
3841 | 0 | execute_data = ex; |
3842 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3843 | | const zend_op *orig_opline = opline; |
3844 | | #else |
3845 | 0 | const zend_op *opline; |
3846 | 0 | #endif |
3847 | 0 | opline = execute_data->opline; |
3848 | |
|
3849 | 0 | uint32_t cache_slot = opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS; |
3850 | 0 | uint32_t flags = 0; |
3851 | |
|
3852 | 0 | if (fetch_type == BP_VAR_W) { |
3853 | 0 | flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS; |
3854 | 0 | } |
3855 | 0 | result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC); |
3856 | 0 | if (EXPECTED(result)) { |
3857 | 0 | if (flags && ZEND_TYPE_IS_SET(property_info->type)) { |
3858 | 0 | zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags); |
3859 | 0 | } |
3860 | 0 | } else { |
3861 | 0 | result = &EG(uninitialized_zval); |
3862 | 0 | } |
3863 | |
|
3864 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3865 | | EX(opline) = opline; |
3866 | | opline = orig_opline; |
3867 | | #endif |
3868 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3869 | | execute_data = orig_execute_data; |
3870 | | #endif |
3871 | |
|
3872 | 0 | return result; |
3873 | 0 | } |
3874 | | |
3875 | 21 | ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) { |
3876 | 21 | zend_string *type1_str = zend_type_to_string(prop1->type); |
3877 | 21 | zend_string *type2_str = zend_type_to_string(prop2->type); |
3878 | 21 | zend_type_error("Reference with value of type %s held by property %s::$%s of type %s is not compatible with property %s::$%s of type %s", |
3879 | 21 | zend_zval_type_name(zv), |
3880 | 21 | ZSTR_VAL(prop1->ce->name), |
3881 | 21 | zend_get_unmangled_property_name(prop1->name), |
3882 | 21 | ZSTR_VAL(type1_str), |
3883 | 21 | ZSTR_VAL(prop2->ce->name), |
3884 | 21 | zend_get_unmangled_property_name(prop2->name), |
3885 | 21 | ZSTR_VAL(type2_str) |
3886 | 21 | ); |
3887 | 21 | zend_string_release(type1_str); |
3888 | 21 | zend_string_release(type2_str); |
3889 | 21 | } |
3890 | | |
3891 | 108 | ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv) { |
3892 | 108 | zend_string *type_str = zend_type_to_string(prop->type); |
3893 | 108 | zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s", |
3894 | 108 | zend_zval_value_name(zv), |
3895 | 108 | ZSTR_VAL(prop->ce->name), |
3896 | 108 | zend_get_unmangled_property_name(prop->name), |
3897 | 108 | ZSTR_VAL(type_str) |
3898 | 108 | ); |
3899 | 108 | zend_string_release(type_str); |
3900 | 108 | } |
3901 | | |
3902 | 12 | ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) { |
3903 | 12 | zend_string *type1_str = zend_type_to_string(prop1->type); |
3904 | 12 | zend_string *type2_str = zend_type_to_string(prop2->type); |
3905 | 12 | zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s and property %s::$%s of type %s, as this would result in an inconsistent type conversion", |
3906 | 12 | zend_zval_value_name(zv), |
3907 | 12 | ZSTR_VAL(prop1->ce->name), |
3908 | 12 | zend_get_unmangled_property_name(prop1->name), |
3909 | 12 | ZSTR_VAL(type1_str), |
3910 | 12 | ZSTR_VAL(prop2->ce->name), |
3911 | 12 | zend_get_unmangled_property_name(prop2->name), |
3912 | 12 | ZSTR_VAL(type2_str) |
3913 | 12 | ); |
3914 | 12 | zend_string_release(type1_str); |
3915 | 12 | zend_string_release(type2_str); |
3916 | 12 | } |
3917 | | |
3918 | | /* 1: valid, 0: invalid, -1: may be valid after type coercion */ |
3919 | | static zend_always_inline int i_zend_verify_type_assignable_zval( |
3920 | 29.4k | const zend_property_info *info, const zval *zv, bool strict) { |
3921 | 29.4k | zend_type type = info->type; |
3922 | 29.4k | uint32_t type_mask; |
3923 | 29.4k | uint8_t zv_type = Z_TYPE_P(zv); |
3924 | | |
3925 | 29.4k | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(type, zv_type))) { |
3926 | 15.8k | return 1; |
3927 | 15.8k | } |
3928 | | |
3929 | 13.6k | if (ZEND_TYPE_IS_COMPLEX(type) && zv_type == IS_OBJECT |
3930 | 13.5k | && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(zv))) { |
3931 | 13.4k | return 1; |
3932 | 13.4k | } |
3933 | | |
3934 | 149 | type_mask = ZEND_TYPE_FULL_MASK(type); |
3935 | 149 | ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC))); |
3936 | | |
3937 | | /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */ |
3938 | 149 | if (strict) { |
3939 | 6 | if ((type_mask & MAY_BE_DOUBLE) && zv_type == IS_LONG) { |
3940 | 0 | return -1; |
3941 | 0 | } |
3942 | 6 | return 0; |
3943 | 6 | } |
3944 | | |
3945 | | /* NULL may be accepted only by nullable hints (this is already checked) */ |
3946 | 143 | if (zv_type == IS_NULL) { |
3947 | 51 | return 0; |
3948 | 51 | } |
3949 | | |
3950 | | /* Does not contain any type to which a coercion is possible */ |
3951 | 92 | if (!(type_mask & (MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING)) |
3952 | 55 | && (type_mask & MAY_BE_BOOL) != MAY_BE_BOOL) { |
3953 | 55 | return 0; |
3954 | 55 | } |
3955 | | |
3956 | | /* Coercion may be necessary, check separately */ |
3957 | 37 | return -1; |
3958 | 92 | } |
3959 | | |
3960 | | ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict) |
3961 | 277 | { |
3962 | 277 | const zend_property_info *prop; |
3963 | | |
3964 | | /* The value must satisfy each property type, and coerce to the same value for each property |
3965 | | * type. Remember the first coerced type and value we've seen for this purpose. */ |
3966 | 277 | const zend_property_info *first_prop = NULL; |
3967 | 277 | zval coerced_value; |
3968 | 277 | ZVAL_UNDEF(&coerced_value); |
3969 | | |
3970 | 277 | ZEND_ASSERT(Z_TYPE_P(zv) != IS_REFERENCE); |
3971 | 910 | ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) { |
3972 | 910 | int result = i_zend_verify_type_assignable_zval(prop, zv, strict); |
3973 | 910 | if (result == 0) { |
3974 | 108 | type_error: |
3975 | 108 | zend_throw_ref_type_error_zval(prop, zv); |
3976 | 108 | zval_ptr_dtor(&coerced_value); |
3977 | 108 | return 0; |
3978 | 108 | } |
3979 | | |
3980 | 248 | if (result < 0) { |
3981 | 16 | if (!first_prop) { |
3982 | 9 | first_prop = prop; |
3983 | 9 | ZVAL_COPY(&coerced_value, zv); |
3984 | 9 | if (!zend_verify_weak_scalar_type_hint( |
3985 | 9 | ZEND_TYPE_FULL_MASK(prop->type), &coerced_value)) { |
3986 | 0 | goto type_error; |
3987 | 0 | } |
3988 | 9 | } else if (Z_ISUNDEF(coerced_value)) { |
3989 | | /* A previous property did not require coercion, but this one does, |
3990 | | * so they are incompatible. */ |
3991 | 6 | goto conflicting_coercion_error; |
3992 | 6 | } else { |
3993 | 1 | zval tmp; |
3994 | 1 | ZVAL_COPY(&tmp, zv); |
3995 | 1 | if (!zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop->type), &tmp)) { |
3996 | 0 | zval_ptr_dtor(&tmp); |
3997 | 0 | goto type_error; |
3998 | 0 | } |
3999 | 1 | if (!zend_is_identical(&coerced_value, &tmp)) { |
4000 | 0 | zval_ptr_dtor(&tmp); |
4001 | 0 | goto conflicting_coercion_error; |
4002 | 0 | } |
4003 | 1 | zval_ptr_dtor(&tmp); |
4004 | 1 | } |
4005 | 232 | } else { |
4006 | 232 | if (!first_prop) { |
4007 | 181 | first_prop = prop; |
4008 | 181 | } else if (!Z_ISUNDEF(coerced_value)) { |
4009 | | /* A previous property required coercion, but this one doesn't, |
4010 | | * so they are incompatible. */ |
4011 | 12 | conflicting_coercion_error: |
4012 | 12 | zend_throw_conflicting_coercion_error(first_prop, prop, zv); |
4013 | 12 | zval_ptr_dtor(&coerced_value); |
4014 | 12 | return 0; |
4015 | 6 | } |
4016 | 232 | } |
4017 | 248 | } ZEND_REF_FOREACH_TYPE_SOURCES_END(); |
4018 | | |
4019 | 157 | if (!Z_ISUNDEF(coerced_value)) { |
4020 | 3 | zval_ptr_dtor(zv); |
4021 | 3 | ZVAL_COPY_VALUE(zv, &coerced_value); |
4022 | 3 | } |
4023 | | |
4024 | 157 | return 1; |
4025 | 277 | } |
4026 | | |
4027 | 213 | static zend_always_inline void i_zval_ptr_dtor_noref(zval *zval_ptr) { |
4028 | 213 | if (Z_REFCOUNTED_P(zval_ptr)) { |
4029 | 68 | zend_refcounted *ref = Z_COUNTED_P(zval_ptr); |
4030 | 68 | ZEND_ASSERT(Z_TYPE_P(zval_ptr) != IS_REFERENCE); |
4031 | 68 | GC_DTOR_NO_REF(ref); |
4032 | 68 | } |
4033 | 213 | } |
4034 | | |
4035 | | ZEND_API zval* zend_assign_to_typed_ref_ex(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict, zend_refcounted **garbage_ptr) |
4036 | 273 | { |
4037 | 273 | bool ret; |
4038 | 273 | zval value; |
4039 | 273 | zend_refcounted *ref = NULL; |
4040 | | |
4041 | 273 | if (Z_ISREF_P(orig_value)) { |
4042 | 0 | ref = Z_COUNTED_P(orig_value); |
4043 | 0 | orig_value = Z_REFVAL_P(orig_value); |
4044 | 0 | } |
4045 | | |
4046 | 273 | ZVAL_COPY(&value, orig_value); |
4047 | 273 | ret = zend_verify_ref_assignable_zval(Z_REF_P(variable_ptr), &value, strict); |
4048 | 273 | variable_ptr = Z_REFVAL_P(variable_ptr); |
4049 | 273 | if (EXPECTED(ret)) { |
4050 | 156 | if (Z_REFCOUNTED_P(variable_ptr)) { |
4051 | 51 | *garbage_ptr = Z_COUNTED_P(variable_ptr); |
4052 | 51 | } |
4053 | 156 | ZVAL_COPY_VALUE(variable_ptr, &value); |
4054 | 156 | } else { |
4055 | 117 | zval_ptr_dtor_nogc(&value); |
4056 | 117 | } |
4057 | 273 | if (value_type & (IS_VAR|IS_TMP_VAR)) { |
4058 | 213 | if (UNEXPECTED(ref)) { |
4059 | 0 | if (UNEXPECTED(GC_DELREF(ref) == 0)) { |
4060 | 0 | zval_ptr_dtor(orig_value); |
4061 | 0 | efree_size(ref, sizeof(zend_reference)); |
4062 | 0 | } |
4063 | 213 | } else { |
4064 | 213 | i_zval_ptr_dtor_noref(orig_value); |
4065 | 213 | } |
4066 | 213 | } |
4067 | 273 | return variable_ptr; |
4068 | 273 | } |
4069 | | |
4070 | | ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict) |
4071 | 38 | { |
4072 | 38 | zend_refcounted *garbage = NULL; |
4073 | 38 | zval *result = zend_assign_to_typed_ref_ex(variable_ptr, orig_value, value_type, strict, &garbage); |
4074 | 38 | if (garbage) { |
4075 | 3 | GC_DTOR_NO_REF(garbage); |
4076 | 3 | } |
4077 | 38 | return result; |
4078 | 38 | } |
4079 | | |
4080 | 160k | ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref_ex(const zend_property_info *prop_info, zval *orig_val, bool strict, zend_verify_prop_assignable_by_ref_context context) { |
4081 | 160k | zval *val = orig_val; |
4082 | 160k | if (Z_ISREF_P(val) && ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(val))) { |
4083 | 29.1k | int result; |
4084 | | |
4085 | 29.1k | val = Z_REFVAL_P(val); |
4086 | 29.1k | result = i_zend_verify_type_assignable_zval(prop_info, val, strict); |
4087 | 29.1k | if (result > 0) { |
4088 | 29.0k | return 1; |
4089 | 29.0k | } |
4090 | | |
4091 | 25 | if (result < 0) { |
4092 | | /* This is definitely an error, but we still need to determined why: Either because |
4093 | | * the value is simply illegal for the type, or because or a conflicting coercion. */ |
4094 | 21 | zval tmp; |
4095 | 21 | ZVAL_COPY(&tmp, val); |
4096 | 21 | if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop_info->type), &tmp)) { |
4097 | 21 | const zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val)); |
4098 | 21 | zend_throw_ref_type_error_type(ref_prop, prop_info, val); |
4099 | 21 | zval_ptr_dtor(&tmp); |
4100 | 21 | return 0; |
4101 | 21 | } |
4102 | 0 | zval_ptr_dtor(&tmp); |
4103 | 0 | } |
4104 | 131k | } else { |
4105 | 131k | ZVAL_DEREF(val); |
4106 | 131k | if (i_zend_check_property_type(prop_info, val, strict)) { |
4107 | 131k | return 1; |
4108 | 131k | } |
4109 | 131k | } |
4110 | | |
4111 | 32 | if (EXPECTED(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT)) { |
4112 | 31 | zend_verify_property_type_error(prop_info, val); |
4113 | 31 | } else { |
4114 | 1 | ZEND_ASSERT(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET); |
4115 | 1 | zend_magic_get_property_type_inconsistency_error(prop_info, val); |
4116 | 1 | } |
4117 | | |
4118 | 32 | return 0; |
4119 | 32 | } |
4120 | | |
4121 | 160k | ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict) { |
4122 | 160k | return zend_verify_prop_assignable_by_ref_ex(prop_info, orig_val, strict, ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT); |
4123 | 160k | } |
4124 | | |
4125 | | ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop) |
4126 | 30.4k | { |
4127 | 30.4k | zend_property_info_list *list; |
4128 | 30.4k | if (source_list->ptr == NULL) { |
4129 | 1.27k | source_list->ptr = prop; |
4130 | 1.27k | return; |
4131 | 1.27k | } |
4132 | | |
4133 | 29.1k | list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list); |
4134 | 29.1k | if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) { |
4135 | 379 | list = emalloc(sizeof(zend_property_info_list) + (4 - 1) * sizeof(zend_property_info *)); |
4136 | 379 | list->ptr[0] = source_list->ptr; |
4137 | 379 | list->num_allocated = 4; |
4138 | 379 | list->num = 1; |
4139 | 28.7k | } else if (list->num_allocated == list->num) { |
4140 | 599 | list->num_allocated = list->num * 2; |
4141 | 599 | list = erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *)); |
4142 | 599 | } |
4143 | | |
4144 | 29.1k | list->ptr[list->num++] = prop; |
4145 | 29.1k | source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(list); |
4146 | 29.1k | } |
4147 | | |
4148 | | ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop) |
4149 | 30.4k | { |
4150 | 30.4k | zend_property_info_list *list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list); |
4151 | 30.4k | zend_property_info **ptr, **end; |
4152 | | |
4153 | 30.4k | ZEND_ASSERT(prop); |
4154 | 30.4k | if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) { |
4155 | 893 | ZEND_ASSERT(source_list->ptr == prop); |
4156 | 893 | source_list->ptr = NULL; |
4157 | 893 | return; |
4158 | 893 | } |
4159 | | |
4160 | 29.5k | if (list->num == 1) { |
4161 | 379 | ZEND_ASSERT(*list->ptr == prop); |
4162 | 379 | efree(list); |
4163 | 379 | source_list->ptr = NULL; |
4164 | 379 | return; |
4165 | 379 | } |
4166 | | |
4167 | | /* Checking against end here to get a more graceful failure mode if we missed adding a type |
4168 | | * source at some point. */ |
4169 | 29.1k | ptr = list->ptr; |
4170 | 29.1k | end = ptr + list->num; |
4171 | 29.5k | while (ptr < end && *ptr != prop) { |
4172 | 385 | ptr++; |
4173 | 385 | } |
4174 | 29.1k | ZEND_ASSERT(*ptr == prop); |
4175 | | |
4176 | | /* Copy the last list element into the deleted slot. */ |
4177 | 29.1k | *ptr = list->ptr[--list->num]; |
4178 | | |
4179 | 29.1k | if (list->num >= 4 && list->num * 4 == list->num_allocated) { |
4180 | 435 | list->num_allocated = list->num * 2; |
4181 | 435 | source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *))); |
4182 | 435 | } |
4183 | 29.1k | } |
4184 | | |
4185 | | static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DATA_DC) |
4186 | 2 | { |
4187 | 2 | zval *result = EX_VAR(opline->result.var); |
4188 | | |
4189 | 2 | switch (type) { |
4190 | 1 | case BP_VAR_R: |
4191 | 1 | if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) { |
4192 | 1 | ZVAL_OBJ(result, Z_OBJ(EX(This))); |
4193 | 1 | Z_ADDREF_P(result); |
4194 | 1 | } else { |
4195 | 0 | ZVAL_NULL(result); |
4196 | 0 | zend_error_unchecked(E_WARNING, "Undefined variable $this"); |
4197 | 0 | } |
4198 | 1 | break; |
4199 | 0 | case BP_VAR_IS: |
4200 | 0 | if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) { |
4201 | 0 | ZVAL_OBJ(result, Z_OBJ(EX(This))); |
4202 | 0 | Z_ADDREF_P(result); |
4203 | 0 | } else { |
4204 | 0 | ZVAL_NULL(result); |
4205 | 0 | } |
4206 | 0 | break; |
4207 | 0 | case BP_VAR_RW: |
4208 | 1 | case BP_VAR_W: |
4209 | 1 | ZVAL_UNDEF(result); |
4210 | 1 | zend_throw_error(NULL, "Cannot re-assign $this"); |
4211 | 1 | break; |
4212 | 0 | case BP_VAR_UNSET: |
4213 | 0 | ZVAL_UNDEF(result); |
4214 | 0 | zend_throw_error(NULL, "Cannot unset $this"); |
4215 | 0 | break; |
4216 | 2 | EMPTY_SWITCH_DEFAULT_CASE() |
4217 | 2 | } |
4218 | 2 | } |
4219 | | |
4220 | | #if ZEND_INTENSIVE_DEBUGGING |
4221 | | |
4222 | | #define CHECK_SYMBOL_TABLES() \ |
4223 | | zend_hash_apply(&EG(symbol_table), zend_check_symbol); \ |
4224 | | if (&EG(symbol_table)!=EX(symbol_table)) { \ |
4225 | | zend_hash_apply(EX(symbol_table), zend_check_symbol); \ |
4226 | | } |
4227 | | |
4228 | | static void zend_check_symbol(zval *pz) |
4229 | | { |
4230 | | if (Z_TYPE_P(pz) == IS_INDIRECT) { |
4231 | | pz = Z_INDIRECT_P(pz); |
4232 | | } |
4233 | | if (Z_TYPE_P(pz) > 10) { |
4234 | | fprintf(stderr, "Warning! %x has invalid type!\n", *pz); |
4235 | | /* See http://support.microsoft.com/kb/190351 */ |
4236 | | #ifdef ZEND_WIN32 |
4237 | | fflush(stderr); |
4238 | | #endif |
4239 | | } else if (Z_TYPE_P(pz) == IS_ARRAY) { |
4240 | | zend_hash_apply(Z_ARRVAL_P(pz), zend_check_symbol); |
4241 | | } else if (Z_TYPE_P(pz) == IS_OBJECT) { |
4242 | | /* OBJ-TBI - doesn't support new object model! */ |
4243 | | zend_hash_apply(Z_OBJPROP_P(pz), zend_check_symbol); |
4244 | | } |
4245 | | } |
4246 | | |
4247 | | |
4248 | | #else |
4249 | | #define CHECK_SYMBOL_TABLES() |
4250 | | #endif |
4251 | | |
4252 | | ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value) |
4253 | 426k | { |
4254 | 426k | execute_data->func->internal_function.handler(execute_data, return_value); |
4255 | 426k | } |
4256 | | |
4257 | | ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table) /* {{{ */ |
4258 | 336 | { |
4259 | | /* Clean before putting into the cache, since clean could call dtors, |
4260 | | * which could use the cached hash. Also do this before the check for |
4261 | | * available cache slots, as those may be used by a dtor as well. */ |
4262 | 336 | zend_symtable_clean(symbol_table); |
4263 | 336 | if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) { |
4264 | 16 | zend_array_destroy(symbol_table); |
4265 | 320 | } else { |
4266 | 320 | *(EG(symtable_cache_ptr)++) = symbol_table; |
4267 | 320 | } |
4268 | 336 | } |
4269 | | /* }}} */ |
4270 | | |
4271 | | static zend_always_inline void i_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */ |
4272 | 36.6k | { |
4273 | 36.6k | zval *cv = EX_VAR_NUM(0); |
4274 | 36.6k | int count = EX(func)->op_array.last_var; |
4275 | 101k | while (EXPECTED(count != 0)) { |
4276 | 64.8k | i_zval_ptr_dtor(cv); |
4277 | 64.8k | cv++; |
4278 | 64.8k | count--; |
4279 | 64.8k | } |
4280 | 36.6k | } |
4281 | | /* }}} */ |
4282 | | |
4283 | | ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */ |
4284 | 155 | { |
4285 | 155 | i_free_compiled_variables(execute_data); |
4286 | 155 | } |
4287 | | /* }}} */ |
4288 | | |
4289 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data *call) |
4290 | 0 | { |
4291 | 0 | zend_atomic_bool_store_ex(&EG(vm_interrupt), false); |
4292 | 0 | if (zend_atomic_bool_load_ex(&EG(timed_out))) { |
4293 | 0 | zend_timeout(); |
4294 | 0 | } else if (zend_interrupt_function) { |
4295 | 0 | zend_interrupt_function(call); |
4296 | 0 | } |
4297 | 0 | } |
4298 | | |
4299 | 492k | #define ZEND_VM_INTERRUPT_CHECK() do { \ |
4300 | 492k | if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \ |
4301 | 0 | ZEND_VM_INTERRUPT(); \ |
4302 | 0 | } \ |
4303 | 492k | } while (0) |
4304 | | |
4305 | 19.1k | #define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \ |
4306 | 19.1k | if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \ |
4307 | 0 | ZEND_VM_LOOP_INTERRUPT(); \ |
4308 | 0 | } \ |
4309 | 19.1k | } while (0) |
4310 | | |
4311 | 410k | #define ZEND_VM_FCALL_INTERRUPT_CHECK(call) do { \ |
4312 | 410k | if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \ |
4313 | 0 | zend_fcall_interrupt(call); \ |
4314 | 0 | } \ |
4315 | 410k | } while (0) |
4316 | | |
4317 | | /* |
4318 | | * Stack Frame Layout (the whole stack frame is allocated at once) |
4319 | | * ================== |
4320 | | * |
4321 | | * +========================================+ |
4322 | | * EG(current_execute_data) -> | zend_execute_data | |
4323 | | * +----------------------------------------+ |
4324 | | * EX_VAR_NUM(0) --------> | VAR[0] = ARG[1] | |
4325 | | * | ... | |
4326 | | * | VAR[op_array->num_args-1] = ARG[N] | |
4327 | | * | ... | |
4328 | | * | VAR[op_array->last_var-1] | |
4329 | | * | VAR[op_array->last_var] = TMP[0] | |
4330 | | * | ... | |
4331 | | * | VAR[op_array->last_var+op_array->T-1] | |
4332 | | * | ARG[N+1] (extra_args) | |
4333 | | * | ... | |
4334 | | * +----------------------------------------+ |
4335 | | */ |
4336 | | |
4337 | | /* zend_copy_extra_args is used when the actually passed number of arguments |
4338 | | * (EX_NUM_ARGS) is greater than what the function defined (op_array->num_args). |
4339 | | * |
4340 | | * The extra arguments will be copied into the call frame after all the compiled variables. |
4341 | | * |
4342 | | * If there are extra arguments copied, a flag "ZEND_CALL_FREE_EXTRA_ARGS" will be set |
4343 | | * on the zend_execute_data, and when the executor leaves the function, the |
4344 | | * args will be freed in zend_leave_helper. |
4345 | | */ |
4346 | | static zend_never_inline void zend_copy_extra_args(EXECUTE_DATA_D) |
4347 | 5.07k | { |
4348 | 5.07k | const zend_op_array *op_array = &EX(func)->op_array; |
4349 | 5.07k | uint32_t first_extra_arg = op_array->num_args; |
4350 | 5.07k | uint32_t num_args = EX_NUM_ARGS(); |
4351 | 5.07k | zval *src; |
4352 | 5.07k | size_t delta; |
4353 | 5.07k | uint32_t count; |
4354 | 5.07k | uint32_t type_flags = 0; |
4355 | | |
4356 | 5.07k | if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { |
4357 | | /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ |
4358 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4359 | | opline += first_extra_arg; |
4360 | | #else |
4361 | 5.04k | EX(opline) += first_extra_arg; |
4362 | 5.04k | #endif |
4363 | | |
4364 | 5.04k | } |
4365 | | |
4366 | | /* move extra args into separate array after all CV and TMP vars */ |
4367 | 5.07k | src = EX_VAR_NUM(num_args - 1); |
4368 | 5.07k | delta = op_array->last_var + op_array->T - first_extra_arg; |
4369 | 5.07k | count = num_args - first_extra_arg; |
4370 | 5.07k | if (EXPECTED(delta != 0)) { |
4371 | 4.33k | delta *= sizeof(zval); |
4372 | 89.9k | do { |
4373 | 89.9k | type_flags |= Z_TYPE_INFO_P(src); |
4374 | 89.9k | ZVAL_COPY_VALUE((zval*)(((char*)src) + delta), src); |
4375 | 89.9k | ZVAL_UNDEF(src); |
4376 | 89.9k | src--; |
4377 | 89.9k | } while (--count); |
4378 | 4.33k | if (Z_TYPE_INFO_REFCOUNTED(type_flags)) { |
4379 | 4.01k | ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS); |
4380 | 4.01k | } |
4381 | 4.33k | } else { |
4382 | 2.06k | do { |
4383 | 2.06k | if (Z_REFCOUNTED_P(src)) { |
4384 | 682 | ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS); |
4385 | 682 | break; |
4386 | 682 | } |
4387 | 1.38k | src--; |
4388 | 1.38k | } while (--count); |
4389 | 734 | } |
4390 | 5.07k | } |
4391 | | |
4392 | | static zend_always_inline void zend_init_cvs(uint32_t first, uint32_t last EXECUTE_DATA_DC) |
4393 | 47.1k | { |
4394 | 47.1k | if (EXPECTED(first < last)) { |
4395 | 28.7k | uint32_t count = last - first; |
4396 | 28.7k | zval *var = EX_VAR_NUM(first); |
4397 | | |
4398 | 231k | do { |
4399 | 231k | ZVAL_UNDEF(var); |
4400 | 231k | var++; |
4401 | 231k | } while (--count); |
4402 | 28.7k | } |
4403 | 47.1k | } |
4404 | | |
4405 | | static zend_always_inline void i_init_func_execute_data(zend_op_array *op_array, zval *return_value, bool may_be_trampoline EXECUTE_DATA_DC) /* {{{ */ |
4406 | 47.1k | { |
4407 | 47.1k | uint32_t first_extra_arg, num_args; |
4408 | 47.1k | ZEND_ASSERT(EX(func) == (zend_function*)op_array); |
4409 | | |
4410 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4411 | | opline = op_array->opcodes; |
4412 | | #else |
4413 | 47.1k | EX(opline) = op_array->opcodes; |
4414 | 47.1k | #endif |
4415 | 47.1k | EX(call) = NULL; |
4416 | 47.1k | EX(return_value) = return_value; |
4417 | | |
4418 | | /* Handle arguments */ |
4419 | 47.1k | first_extra_arg = op_array->num_args; |
4420 | 47.1k | num_args = EX_NUM_ARGS(); |
4421 | 47.1k | if (UNEXPECTED(num_args > first_extra_arg)) { |
4422 | 5.73k | if (!may_be_trampoline || EXPECTED(!(op_array->fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) { |
4423 | 5.07k | zend_copy_extra_args(EXECUTE_DATA_C); |
4424 | 5.07k | } |
4425 | 41.3k | } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { |
4426 | | /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ |
4427 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4428 | | opline += num_args; |
4429 | | #else |
4430 | 40.2k | EX(opline) += num_args; |
4431 | 40.2k | #endif |
4432 | 40.2k | } |
4433 | | |
4434 | | /* Initialize CV variables (skip arguments) */ |
4435 | 47.1k | zend_init_cvs(num_args, op_array->last_var EXECUTE_DATA_CC); |
4436 | | |
4437 | 47.1k | EX(run_time_cache) = RUN_TIME_CACHE(op_array); |
4438 | | |
4439 | 47.1k | EG(current_execute_data) = execute_data; |
4440 | 47.1k | } |
4441 | | /* }}} */ |
4442 | | |
4443 | | static zend_always_inline void init_func_run_time_cache_i(zend_op_array *op_array) /* {{{ */ |
4444 | 4.86k | { |
4445 | 4.86k | void **run_time_cache; |
4446 | | |
4447 | 4.86k | ZEND_ASSERT(RUN_TIME_CACHE(op_array) == NULL); |
4448 | 4.86k | run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size); |
4449 | 4.86k | memset(run_time_cache, 0, op_array->cache_size); |
4450 | 4.86k | ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache); |
4451 | 4.86k | } |
4452 | | /* }}} */ |
4453 | | |
4454 | | static zend_never_inline void ZEND_FASTCALL init_func_run_time_cache(zend_op_array *op_array) /* {{{ */ |
4455 | 4.76k | { |
4456 | 4.76k | init_func_run_time_cache_i(op_array); |
4457 | 4.76k | } |
4458 | | /* }}} */ |
4459 | | |
4460 | | ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /* {{{ */ |
4461 | 1.16k | { |
4462 | 1.16k | zval *zv = zend_hash_find(EG(function_table), name); |
4463 | | |
4464 | 1.16k | if (EXPECTED(zv != NULL)) { |
4465 | 828 | zend_function *fbc = Z_FUNC_P(zv); |
4466 | | |
4467 | 828 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
4468 | 101 | init_func_run_time_cache_i(&fbc->op_array); |
4469 | 101 | } |
4470 | 828 | return fbc; |
4471 | 828 | } |
4472 | 337 | return NULL; |
4473 | 1.16k | } /* }}} */ |
4474 | | |
4475 | | ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len) /* {{{ */ |
4476 | 1 | { |
4477 | 1 | zval *zv = zend_hash_str_find(EG(function_table), name, len); |
4478 | | |
4479 | 1 | if (EXPECTED(zv != NULL)) { |
4480 | 1 | zend_function *fbc = Z_FUNC_P(zv); |
4481 | | |
4482 | 1 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
4483 | 0 | init_func_run_time_cache_i(&fbc->op_array); |
4484 | 0 | } |
4485 | 1 | return fbc; |
4486 | 1 | } |
4487 | 0 | return NULL; |
4488 | 1 | } /* }}} */ |
4489 | | |
4490 | | ZEND_API void ZEND_FASTCALL zend_init_func_run_time_cache(zend_op_array *op_array) /* {{{ */ |
4491 | 0 | { |
4492 | 0 | if (!RUN_TIME_CACHE(op_array)) { |
4493 | 0 | init_func_run_time_cache_i(op_array); |
4494 | 0 | } |
4495 | 0 | } /* }}} */ |
4496 | | |
4497 | | static zend_always_inline void i_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4498 | 93.7k | { |
4499 | 93.7k | ZEND_ASSERT(EX(func) == (zend_function*)op_array); |
4500 | | |
4501 | 93.7k | EX(opline) = op_array->opcodes; |
4502 | 93.7k | EX(call) = NULL; |
4503 | 93.7k | EX(return_value) = return_value; |
4504 | | |
4505 | 93.7k | if (op_array->last_var) { |
4506 | 51.5k | zend_attach_symbol_table(execute_data); |
4507 | 51.5k | } |
4508 | | |
4509 | 93.7k | if (!ZEND_MAP_PTR(op_array->run_time_cache)) { |
4510 | 93.7k | void *ptr; |
4511 | | |
4512 | 93.7k | ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_HEAP_RT_CACHE); |
4513 | 93.7k | ptr = emalloc(op_array->cache_size); |
4514 | 93.7k | ZEND_MAP_PTR_INIT(op_array->run_time_cache, ptr); |
4515 | 93.7k | memset(ptr, 0, op_array->cache_size); |
4516 | 93.7k | } |
4517 | 93.7k | EX(run_time_cache) = RUN_TIME_CACHE(op_array); |
4518 | | |
4519 | 93.7k | EG(current_execute_data) = execute_data; |
4520 | 93.7k | } |
4521 | | /* }}} */ |
4522 | | |
4523 | | ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4524 | 37.0k | { |
4525 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4526 | | zend_execute_data *orig_execute_data = execute_data; |
4527 | | #endif |
4528 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4529 | | const zend_op *orig_opline = opline; |
4530 | | #endif |
4531 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4532 | | execute_data = ex; |
4533 | | #else |
4534 | 37.0k | zend_execute_data *execute_data = ex; |
4535 | 37.0k | #endif |
4536 | | |
4537 | 37.0k | EX(prev_execute_data) = EG(current_execute_data); |
4538 | 37.0k | if (!RUN_TIME_CACHE(op_array)) { |
4539 | 966 | init_func_run_time_cache(op_array); |
4540 | 966 | } |
4541 | 37.0k | i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC); |
4542 | | |
4543 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4544 | | EX(opline) = opline; |
4545 | | opline = orig_opline; |
4546 | | #endif |
4547 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4548 | | execute_data = orig_execute_data; |
4549 | | #endif |
4550 | 37.0k | } |
4551 | | /* }}} */ |
4552 | | |
4553 | | ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4554 | 0 | { |
4555 | 0 | EX(prev_execute_data) = EG(current_execute_data); |
4556 | 0 | i_init_code_execute_data(execute_data, op_array, return_value); |
4557 | 0 | } |
4558 | | /* }}} */ |
4559 | | |
4560 | | ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4561 | 0 | { |
4562 | 0 | if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) { |
4563 | 0 | zend_init_code_execute_data(execute_data, op_array, return_value); |
4564 | 0 | } else { |
4565 | 0 | zend_init_func_execute_data(execute_data, op_array, return_value); |
4566 | 0 | } |
4567 | 0 | } |
4568 | | /* }}} */ |
4569 | | |
4570 | | zend_execute_data *zend_vm_stack_copy_call_frame(zend_execute_data *call, uint32_t passed_args, uint32_t additional_args) /* {{{ */ |
4571 | 4 | { |
4572 | 4 | zend_execute_data *new_call; |
4573 | 4 | int used_stack = (EG(vm_stack_top) - (zval*)call) + additional_args; |
4574 | | |
4575 | | /* copy call frame into new stack segment */ |
4576 | 4 | new_call = zend_vm_stack_extend(used_stack * sizeof(zval)); |
4577 | 4 | *new_call = *call; |
4578 | 4 | ZEND_ADD_CALL_FLAG(new_call, ZEND_CALL_ALLOCATED); |
4579 | | |
4580 | 4 | if (passed_args) { |
4581 | 4 | zval *src = ZEND_CALL_ARG(call, 1); |
4582 | 4 | zval *dst = ZEND_CALL_ARG(new_call, 1); |
4583 | 40.3k | do { |
4584 | 40.3k | ZVAL_COPY_VALUE(dst, src); |
4585 | 40.3k | passed_args--; |
4586 | 40.3k | src++; |
4587 | 40.3k | dst++; |
4588 | 40.3k | } while (passed_args); |
4589 | 4 | } |
4590 | | |
4591 | | /* delete old call_frame from previous stack segment */ |
4592 | 4 | EG(vm_stack)->prev->top = (zval*)call; |
4593 | | |
4594 | | /* delete previous stack segment if it became empty */ |
4595 | 4 | if (UNEXPECTED(EG(vm_stack)->prev->top == ZEND_VM_STACK_ELEMENTS(EG(vm_stack)->prev))) { |
4596 | 0 | zend_vm_stack r = EG(vm_stack)->prev; |
4597 | |
|
4598 | 0 | EG(vm_stack)->prev = r->prev; |
4599 | 0 | efree(r); |
4600 | 0 | } |
4601 | | |
4602 | 4 | return new_call; |
4603 | 4 | } |
4604 | | /* }}} */ |
4605 | | |
4606 | | static zend_always_inline zend_generator *zend_get_running_generator(EXECUTE_DATA_D) /* {{{ */ |
4607 | 280 | { |
4608 | | /* The generator object is stored in EX(return_value) */ |
4609 | 280 | zend_generator *generator = (zend_generator *) EX(return_value); |
4610 | | /* However control may currently be delegated to another generator. |
4611 | | * That's the one we're interested in. */ |
4612 | 280 | return generator; |
4613 | 280 | } |
4614 | | /* }}} */ |
4615 | | |
4616 | | ZEND_API void zend_unfinished_calls_gc(zend_execute_data *execute_data, zend_execute_data *call, uint32_t op_num, zend_get_gc_buffer *buf) /* {{{ */ |
4617 | 4 | { |
4618 | 4 | zend_op *opline = EX(func)->op_array.opcodes + op_num; |
4619 | 4 | int level; |
4620 | 4 | int do_exit; |
4621 | 4 | uint32_t num_args; |
4622 | | |
4623 | 4 | if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL || |
4624 | 4 | opline->opcode == ZEND_INIT_FCALL_BY_NAME || |
4625 | 4 | opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME || |
4626 | 4 | opline->opcode == ZEND_INIT_DYNAMIC_CALL || |
4627 | 4 | opline->opcode == ZEND_INIT_USER_CALL || |
4628 | 4 | opline->opcode == ZEND_INIT_METHOD_CALL || |
4629 | 4 | opline->opcode == ZEND_INIT_STATIC_METHOD_CALL || |
4630 | 4 | opline->opcode == ZEND_NEW)) { |
4631 | 0 | ZEND_ASSERT(op_num); |
4632 | 0 | opline--; |
4633 | 0 | } |
4634 | | |
4635 | 8 | do { |
4636 | | /* find the number of actually passed arguments */ |
4637 | 8 | level = 0; |
4638 | 8 | do_exit = 0; |
4639 | 8 | num_args = ZEND_CALL_NUM_ARGS(call); |
4640 | 12 | do { |
4641 | 12 | switch (opline->opcode) { |
4642 | 0 | case ZEND_DO_FCALL: |
4643 | 0 | case ZEND_DO_ICALL: |
4644 | 0 | case ZEND_DO_UCALL: |
4645 | 0 | case ZEND_DO_FCALL_BY_NAME: |
4646 | 0 | case ZEND_CALLABLE_CONVERT: |
4647 | 0 | level++; |
4648 | 0 | break; |
4649 | 2 | case ZEND_INIT_FCALL: |
4650 | 2 | case ZEND_INIT_FCALL_BY_NAME: |
4651 | 2 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4652 | 2 | case ZEND_INIT_DYNAMIC_CALL: |
4653 | 2 | case ZEND_INIT_USER_CALL: |
4654 | 2 | case ZEND_INIT_METHOD_CALL: |
4655 | 2 | case ZEND_INIT_STATIC_METHOD_CALL: |
4656 | 2 | case ZEND_NEW: |
4657 | 2 | if (level == 0) { |
4658 | 2 | num_args = 0; |
4659 | 2 | do_exit = 1; |
4660 | 2 | } |
4661 | 2 | level--; |
4662 | 2 | break; |
4663 | 0 | case ZEND_SEND_VAL: |
4664 | 2 | case ZEND_SEND_VAL_EX: |
4665 | 6 | case ZEND_SEND_VAR: |
4666 | 6 | case ZEND_SEND_VAR_EX: |
4667 | 6 | case ZEND_SEND_FUNC_ARG: |
4668 | 6 | case ZEND_SEND_REF: |
4669 | 6 | case ZEND_SEND_VAR_NO_REF: |
4670 | 6 | case ZEND_SEND_VAR_NO_REF_EX: |
4671 | 6 | case ZEND_SEND_USER: |
4672 | 6 | if (level == 0) { |
4673 | | /* For named args, the number of arguments is up to date. */ |
4674 | 6 | if (opline->op2_type != IS_CONST) { |
4675 | 4 | num_args = opline->op2.num; |
4676 | 4 | } |
4677 | 6 | do_exit = 1; |
4678 | 6 | } |
4679 | 6 | break; |
4680 | 0 | case ZEND_SEND_ARRAY: |
4681 | 0 | case ZEND_SEND_UNPACK: |
4682 | 0 | case ZEND_CHECK_UNDEF_ARGS: |
4683 | 0 | if (level == 0) { |
4684 | 0 | do_exit = 1; |
4685 | 0 | } |
4686 | 0 | break; |
4687 | 12 | } |
4688 | 12 | if (!do_exit) { |
4689 | 4 | opline--; |
4690 | 4 | } |
4691 | 12 | } while (!do_exit); |
4692 | 8 | if (call->prev_execute_data) { |
4693 | | /* skip current call region */ |
4694 | 4 | level = 0; |
4695 | 4 | do_exit = 0; |
4696 | 10 | do { |
4697 | 10 | switch (opline->opcode) { |
4698 | 0 | case ZEND_DO_FCALL: |
4699 | 0 | case ZEND_DO_ICALL: |
4700 | 0 | case ZEND_DO_UCALL: |
4701 | 0 | case ZEND_DO_FCALL_BY_NAME: |
4702 | 0 | case ZEND_CALLABLE_CONVERT: |
4703 | 0 | level++; |
4704 | 0 | break; |
4705 | 4 | case ZEND_INIT_FCALL: |
4706 | 4 | case ZEND_INIT_FCALL_BY_NAME: |
4707 | 4 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4708 | 4 | case ZEND_INIT_DYNAMIC_CALL: |
4709 | 4 | case ZEND_INIT_USER_CALL: |
4710 | 4 | case ZEND_INIT_METHOD_CALL: |
4711 | 4 | case ZEND_INIT_STATIC_METHOD_CALL: |
4712 | 4 | case ZEND_NEW: |
4713 | 4 | if (level == 0) { |
4714 | 4 | do_exit = 1; |
4715 | 4 | } |
4716 | 4 | level--; |
4717 | 4 | break; |
4718 | 10 | } |
4719 | 10 | opline--; |
4720 | 10 | } while (!do_exit); |
4721 | 4 | } |
4722 | | |
4723 | 8 | if (EXPECTED(num_args > 0)) { |
4724 | 4 | zval *p = ZEND_CALL_ARG(call, 1); |
4725 | 6 | do { |
4726 | 6 | zend_get_gc_buffer_add_zval(buf, p); |
4727 | 6 | p++; |
4728 | 6 | } while (--num_args); |
4729 | 4 | } |
4730 | 8 | if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) { |
4731 | 0 | zend_get_gc_buffer_add_obj(buf, Z_OBJ(call->This)); |
4732 | 0 | } |
4733 | 8 | if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { |
4734 | 2 | zval *val; |
4735 | 6 | ZEND_HASH_FOREACH_VAL(call->extra_named_params, val) { |
4736 | 6 | zend_get_gc_buffer_add_zval(buf, val); |
4737 | 6 | } ZEND_HASH_FOREACH_END(); |
4738 | 2 | } |
4739 | 8 | if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) { |
4740 | 0 | zend_get_gc_buffer_add_obj(buf, ZEND_CLOSURE_OBJECT(call->func)); |
4741 | 0 | } |
4742 | | |
4743 | 8 | call = call->prev_execute_data; |
4744 | 8 | } while (call); |
4745 | 4 | } |
4746 | | /* }}} */ |
4747 | | |
4748 | | static void cleanup_unfinished_calls(zend_execute_data *execute_data, uint32_t op_num) /* {{{ */ |
4749 | 219k | { |
4750 | 219k | if (UNEXPECTED(EX(call))) { |
4751 | 774 | zend_execute_data *call = EX(call); |
4752 | 774 | zend_op *opline = EX(func)->op_array.opcodes + op_num; |
4753 | 774 | int level; |
4754 | 774 | int do_exit; |
4755 | | |
4756 | 774 | if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL || |
4757 | 774 | opline->opcode == ZEND_INIT_FCALL_BY_NAME || |
4758 | 774 | opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME || |
4759 | 774 | opline->opcode == ZEND_INIT_DYNAMIC_CALL || |
4760 | 774 | opline->opcode == ZEND_INIT_USER_CALL || |
4761 | 774 | opline->opcode == ZEND_INIT_METHOD_CALL || |
4762 | 774 | opline->opcode == ZEND_INIT_STATIC_METHOD_CALL || |
4763 | 774 | opline->opcode == ZEND_INIT_PARENT_PROPERTY_HOOK_CALL || |
4764 | 774 | opline->opcode == ZEND_NEW)) { |
4765 | 141 | ZEND_ASSERT(op_num); |
4766 | 141 | opline--; |
4767 | 141 | } |
4768 | | |
4769 | 846 | do { |
4770 | | /* If the exception was thrown during a function call there might be |
4771 | | * arguments pushed to the stack that have to be dtor'ed. */ |
4772 | | |
4773 | | /* find the number of actually passed arguments */ |
4774 | 846 | level = 0; |
4775 | 846 | do_exit = 0; |
4776 | 3.92k | do { |
4777 | 3.92k | switch (opline->opcode) { |
4778 | 255 | case ZEND_DO_FCALL: |
4779 | 255 | case ZEND_DO_ICALL: |
4780 | 275 | case ZEND_DO_UCALL: |
4781 | 275 | case ZEND_DO_FCALL_BY_NAME: |
4782 | 276 | case ZEND_CALLABLE_CONVERT: |
4783 | 276 | level++; |
4784 | 276 | break; |
4785 | 850 | case ZEND_INIT_FCALL: |
4786 | 854 | case ZEND_INIT_FCALL_BY_NAME: |
4787 | 860 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4788 | 892 | case ZEND_INIT_DYNAMIC_CALL: |
4789 | 893 | case ZEND_INIT_USER_CALL: |
4790 | 928 | case ZEND_INIT_METHOD_CALL: |
4791 | 965 | case ZEND_INIT_STATIC_METHOD_CALL: |
4792 | 965 | case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL: |
4793 | 1.01k | case ZEND_NEW: |
4794 | 1.01k | if (level == 0) { |
4795 | 738 | ZEND_CALL_NUM_ARGS(call) = 0; |
4796 | 738 | do_exit = 1; |
4797 | 738 | } |
4798 | 1.01k | level--; |
4799 | 1.01k | break; |
4800 | 222 | case ZEND_SEND_VAL: |
4801 | 247 | case ZEND_SEND_VAL_EX: |
4802 | 342 | case ZEND_SEND_VAR: |
4803 | 348 | case ZEND_SEND_VAR_EX: |
4804 | 348 | case ZEND_SEND_FUNC_ARG: |
4805 | 353 | case ZEND_SEND_REF: |
4806 | 356 | case ZEND_SEND_VAR_NO_REF: |
4807 | 361 | case ZEND_SEND_VAR_NO_REF_EX: |
4808 | 361 | case ZEND_SEND_USER: |
4809 | 361 | if (level == 0) { |
4810 | | /* For named args, the number of arguments is up to date. */ |
4811 | 93 | if (opline->op2_type != IS_CONST) { |
4812 | 83 | ZEND_CALL_NUM_ARGS(call) = opline->op2.num; |
4813 | 83 | } |
4814 | 93 | do_exit = 1; |
4815 | 93 | } |
4816 | 361 | break; |
4817 | 14 | case ZEND_SEND_ARRAY: |
4818 | 14 | case ZEND_SEND_UNPACK: |
4819 | 21 | case ZEND_CHECK_UNDEF_ARGS: |
4820 | 21 | if (level == 0) { |
4821 | 15 | do_exit = 1; |
4822 | 15 | } |
4823 | 21 | break; |
4824 | 3.92k | } |
4825 | 3.92k | if (!do_exit) { |
4826 | 3.08k | opline--; |
4827 | 3.08k | } |
4828 | 3.92k | } while (!do_exit); |
4829 | 846 | if (call->prev_execute_data) { |
4830 | | /* skip current call region */ |
4831 | 72 | level = 0; |
4832 | 72 | do_exit = 0; |
4833 | 138 | do { |
4834 | 138 | switch (opline->opcode) { |
4835 | 0 | case ZEND_DO_FCALL: |
4836 | 0 | case ZEND_DO_ICALL: |
4837 | 0 | case ZEND_DO_UCALL: |
4838 | 0 | case ZEND_DO_FCALL_BY_NAME: |
4839 | 0 | case ZEND_CALLABLE_CONVERT: |
4840 | 0 | level++; |
4841 | 0 | break; |
4842 | 64 | case ZEND_INIT_FCALL: |
4843 | 64 | case ZEND_INIT_FCALL_BY_NAME: |
4844 | 64 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4845 | 64 | case ZEND_INIT_DYNAMIC_CALL: |
4846 | 64 | case ZEND_INIT_USER_CALL: |
4847 | 71 | case ZEND_INIT_METHOD_CALL: |
4848 | 72 | case ZEND_INIT_STATIC_METHOD_CALL: |
4849 | 72 | case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL: |
4850 | 72 | case ZEND_NEW: |
4851 | 72 | if (level == 0) { |
4852 | 72 | do_exit = 1; |
4853 | 72 | } |
4854 | 72 | level--; |
4855 | 72 | break; |
4856 | 138 | } |
4857 | 138 | opline--; |
4858 | 138 | } while (!do_exit); |
4859 | 72 | } |
4860 | | |
4861 | 846 | zend_vm_stack_free_args(EX(call)); |
4862 | | |
4863 | 846 | if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) { |
4864 | 37 | OBJ_RELEASE(Z_OBJ(call->This)); |
4865 | 37 | } |
4866 | 846 | if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { |
4867 | 1 | zend_free_extra_named_params(call->extra_named_params); |
4868 | 1 | } |
4869 | 846 | if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) { |
4870 | 13 | zend_object_release(ZEND_CLOSURE_OBJECT(call->func)); |
4871 | 833 | } else if (call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { |
4872 | 1 | zend_string_release_ex(call->func->common.function_name, 0); |
4873 | 1 | zend_free_trampoline(call->func); |
4874 | 1 | } |
4875 | | |
4876 | 846 | EX(call) = call->prev_execute_data; |
4877 | 846 | zend_vm_stack_free_call_frame(call); |
4878 | 846 | call = EX(call); |
4879 | 846 | } while (call); |
4880 | 774 | } |
4881 | 219k | } |
4882 | | /* }}} */ |
4883 | | |
4884 | | static const zend_live_range *find_live_range(const zend_op_array *op_array, uint32_t op_num, uint32_t var_num) /* {{{ */ |
4885 | 1 | { |
4886 | 1 | int i; |
4887 | 2 | for (i = 0; i < op_array->last_live_range; i++) { |
4888 | 2 | const zend_live_range *range = &op_array->live_range[i]; |
4889 | 2 | if (op_num >= range->start && op_num < range->end |
4890 | 1 | && var_num == (range->var & ~ZEND_LIVE_MASK)) { |
4891 | 1 | return range; |
4892 | 1 | } |
4893 | 2 | } |
4894 | 0 | return NULL; |
4895 | 1 | } |
4896 | | /* }}} */ |
4897 | | |
4898 | | static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) /* {{{ */ |
4899 | 220k | { |
4900 | 220k | int i; |
4901 | | |
4902 | 872k | for (i = 0; i < EX(func)->op_array.last_live_range; i++) { |
4903 | 746k | const zend_live_range *range = &EX(func)->op_array.live_range[i]; |
4904 | 746k | if (range->start > op_num) { |
4905 | | /* further blocks will not be relevant... */ |
4906 | 94.4k | break; |
4907 | 651k | } else if (op_num < range->end) { |
4908 | 318k | if (!catch_op_num || catch_op_num >= range->end) { |
4909 | 190k | uint32_t kind = range->var & ZEND_LIVE_MASK; |
4910 | 190k | uint32_t var_num = range->var & ~ZEND_LIVE_MASK; |
4911 | 190k | zval *var = EX_VAR(var_num); |
4912 | | |
4913 | 190k | if (kind == ZEND_LIVE_TMPVAR) { |
4914 | 392 | zval_ptr_dtor_nogc(var); |
4915 | 190k | } else if (kind == ZEND_LIVE_NEW) { |
4916 | 186k | zend_object *obj; |
4917 | 186k | ZEND_ASSERT(Z_TYPE_P(var) == IS_OBJECT); |
4918 | 186k | obj = Z_OBJ_P(var); |
4919 | 186k | zend_object_store_ctor_failed(obj); |
4920 | 186k | OBJ_RELEASE(obj); |
4921 | 186k | } else if (kind == ZEND_LIVE_LOOP) { |
4922 | 272 | if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { |
4923 | 8 | zend_hash_iterator_del(Z_FE_ITER_P(var)); |
4924 | 8 | } |
4925 | 272 | zval_ptr_dtor_nogc(var); |
4926 | 3.22k | } else if (kind == ZEND_LIVE_ROPE) { |
4927 | 28 | zend_string **rope = (zend_string **)var; |
4928 | 28 | const zend_op *last = EX(func)->op_array.opcodes + op_num; |
4929 | 43 | while ((last->opcode != ZEND_ROPE_ADD && last->opcode != ZEND_ROPE_INIT) |
4930 | 28 | || last->result.var != var_num) { |
4931 | 15 | ZEND_ASSERT(last >= EX(func)->op_array.opcodes); |
4932 | 15 | last--; |
4933 | 15 | } |
4934 | 28 | if (last->opcode == ZEND_ROPE_INIT) { |
4935 | 3 | zend_string_release_ex(*rope, 0); |
4936 | 25 | } else { |
4937 | 25 | uint32_t j = last->extended_value; |
4938 | 1.05k | do { |
4939 | 1.05k | zend_string_release_ex(rope[j], 0); |
4940 | 1.05k | } while (j--); |
4941 | 25 | } |
4942 | 3.19k | } else if (kind == ZEND_LIVE_SILENCE) { |
4943 | | /* restore previous error_reporting value */ |
4944 | 3.19k | if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting)) |
4945 | 3.19k | && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) { |
4946 | 0 | EG(error_reporting) = Z_LVAL_P(var); |
4947 | 0 | } |
4948 | 3.19k | } |
4949 | 190k | } |
4950 | 318k | } |
4951 | 746k | } |
4952 | 220k | } |
4953 | | /* }}} */ |
4954 | | |
4955 | 38 | ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) { |
4956 | 38 | cleanup_unfinished_calls(execute_data, op_num); |
4957 | 38 | cleanup_live_vars(execute_data, op_num, catch_op_num); |
4958 | 38 | } |
4959 | | |
4960 | | ZEND_API ZEND_ATTRIBUTE_DEPRECATED HashTable *zend_unfinished_execution_gc(zend_execute_data *execute_data, zend_execute_data *call, zend_get_gc_buffer *gc_buffer) |
4961 | 0 | { |
4962 | 0 | return zend_unfinished_execution_gc_ex(execute_data, call, gc_buffer, false); |
4963 | 0 | } |
4964 | | |
4965 | | ZEND_API HashTable *zend_unfinished_execution_gc_ex(zend_execute_data *execute_data, zend_execute_data *call, zend_get_gc_buffer *gc_buffer, bool suspended_by_yield) |
4966 | 1.73k | { |
4967 | 1.73k | if (!EX(func)) { |
4968 | 0 | return NULL; |
4969 | 0 | } |
4970 | | |
4971 | 1.73k | if (EX_CALL_INFO() & ZEND_CALL_RELEASE_THIS) { |
4972 | 2 | zend_get_gc_buffer_add_obj(gc_buffer, Z_OBJ(execute_data->This)); |
4973 | 2 | } |
4974 | | |
4975 | 1.73k | if (EX_CALL_INFO() & ZEND_CALL_CLOSURE) { |
4976 | 556 | zend_get_gc_buffer_add_obj(gc_buffer, ZEND_CLOSURE_OBJECT(EX(func))); |
4977 | 556 | } |
4978 | | |
4979 | 1.73k | if (!ZEND_USER_CODE(EX(func)->common.type)) { |
4980 | 1.12k | ZEND_ASSERT(!(EX_CALL_INFO() & (ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS))); |
4981 | 1.12k | return NULL; |
4982 | 1.12k | } |
4983 | | |
4984 | 608 | const zend_op_array *op_array = &EX(func)->op_array; |
4985 | | |
4986 | 608 | if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) { |
4987 | 600 | uint32_t i, num_cvs = EX(func)->op_array.last_var; |
4988 | 630 | for (i = 0; i < num_cvs; i++) { |
4989 | 30 | zend_get_gc_buffer_add_zval(gc_buffer, EX_VAR_NUM(i)); |
4990 | 30 | } |
4991 | 600 | } |
4992 | | |
4993 | 608 | if (EX_CALL_INFO() & ZEND_CALL_FREE_EXTRA_ARGS) { |
4994 | 2 | zval *zv = EX_VAR_NUM(op_array->last_var + op_array->T); |
4995 | 2 | const zval *end = zv + (EX_NUM_ARGS() - op_array->num_args); |
4996 | 6 | while (zv != end) { |
4997 | 4 | zend_get_gc_buffer_add_zval(gc_buffer, zv++); |
4998 | 4 | } |
4999 | 2 | } |
5000 | | |
5001 | 608 | if (EX_CALL_INFO() & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { |
5002 | 0 | zval extra_named_params; |
5003 | 0 | ZVAL_ARR(&extra_named_params, EX(extra_named_params)); |
5004 | 0 | zend_get_gc_buffer_add_zval(gc_buffer, &extra_named_params); |
5005 | 0 | } |
5006 | | |
5007 | 608 | uint32_t op_num; |
5008 | 608 | if (UNEXPECTED(execute_data->opline->opcode == ZEND_HANDLE_EXCEPTION)) { |
5009 | 0 | op_num = EG(opline_before_exception) - op_array->opcodes; |
5010 | 608 | } else { |
5011 | 608 | op_num = execute_data->opline - op_array->opcodes; |
5012 | 608 | } |
5013 | 608 | ZEND_ASSERT(op_num < op_array->last); |
5014 | | |
5015 | 608 | if (call) { |
5016 | 4 | zend_unfinished_calls_gc(execute_data, call, op_num, gc_buffer); |
5017 | 4 | } |
5018 | | |
5019 | 608 | if (execute_data->opline != op_array->opcodes) { |
5020 | 604 | uint32_t i; |
5021 | 653 | for (i = 0; i < op_array->last_live_range; i++) { |
5022 | 58 | const zend_live_range *range = &op_array->live_range[i]; |
5023 | 58 | if (range->start > op_num) { |
5024 | 9 | break; |
5025 | 49 | } else if (op_num < range->end) { |
5026 | 5 | uint32_t kind = range->var & ZEND_LIVE_MASK; |
5027 | 5 | uint32_t var_num = range->var & ~ZEND_LIVE_MASK; |
5028 | 5 | zval *var = EX_VAR(var_num); |
5029 | 5 | if (kind == ZEND_LIVE_TMPVAR || kind == ZEND_LIVE_LOOP) { |
5030 | 5 | zend_get_gc_buffer_add_zval(gc_buffer, var); |
5031 | 5 | } |
5032 | 5 | } |
5033 | 58 | } |
5034 | 604 | } |
5035 | | |
5036 | 608 | if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) { |
5037 | 8 | return execute_data->symbol_table; |
5038 | 600 | } else { |
5039 | 600 | return NULL; |
5040 | 600 | } |
5041 | 608 | } |
5042 | | |
5043 | | #if ZEND_VM_SPEC |
5044 | | static void zend_swap_operands(zend_op *op) /* {{{ */ |
5045 | 180k | { |
5046 | 180k | znode_op tmp; |
5047 | 180k | uint8_t tmp_type; |
5048 | | |
5049 | 180k | tmp = op->op1; |
5050 | 180k | tmp_type = op->op1_type; |
5051 | 180k | op->op1 = op->op2; |
5052 | 180k | op->op1_type = op->op2_type; |
5053 | 180k | op->op2 = tmp; |
5054 | 180k | op->op2_type = tmp_type; |
5055 | | |
5056 | | #ifdef ZEND_VERIFY_TYPE_INFERENCE |
5057 | | uint32_t tmp_info; |
5058 | | tmp_info = op->op1_use_type; |
5059 | | op->op1_use_type = op->op2_use_type; |
5060 | | op->op2_use_type = tmp_info; |
5061 | | tmp_info = op->op1_def_type; |
5062 | | op->op1_def_type = op->op2_def_type; |
5063 | | op->op2_def_type = tmp_info; |
5064 | | #endif |
5065 | 180k | } |
5066 | | /* }}} */ |
5067 | | #endif |
5068 | | |
5069 | | static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_string *function, uint32_t num_args) /* {{{ */ |
5070 | 165 | { |
5071 | 165 | zend_function *fbc; |
5072 | 165 | zval *func; |
5073 | 165 | zend_class_entry *called_scope; |
5074 | 165 | zend_string *lcname; |
5075 | 165 | const char *colon; |
5076 | | |
5077 | 165 | if ((colon = zend_memrchr(ZSTR_VAL(function), ':', ZSTR_LEN(function))) != NULL && |
5078 | 21 | colon > ZSTR_VAL(function) && |
5079 | 15 | *(colon-1) == ':' |
5080 | 165 | ) { |
5081 | 9 | zend_string *mname; |
5082 | 9 | size_t cname_length = colon - ZSTR_VAL(function) - 1; |
5083 | 9 | size_t mname_length = ZSTR_LEN(function) - cname_length - (sizeof("::") - 1); |
5084 | | |
5085 | 9 | lcname = zend_string_init(ZSTR_VAL(function), cname_length, 0); |
5086 | | |
5087 | 9 | called_scope = zend_fetch_class_by_name(lcname, NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); |
5088 | 9 | if (UNEXPECTED(called_scope == NULL)) { |
5089 | 6 | zend_string_release_ex(lcname, 0); |
5090 | 6 | return NULL; |
5091 | 6 | } |
5092 | | |
5093 | 3 | mname = zend_string_init(ZSTR_VAL(function) + (cname_length + sizeof("::") - 1), mname_length, 0); |
5094 | | |
5095 | 3 | if (called_scope->get_static_method) { |
5096 | 0 | fbc = called_scope->get_static_method(called_scope, mname); |
5097 | 3 | } else { |
5098 | 3 | fbc = zend_std_get_static_method(called_scope, mname, NULL); |
5099 | 3 | } |
5100 | 3 | if (UNEXPECTED(fbc == NULL)) { |
5101 | 0 | if (EXPECTED(!EG(exception))) { |
5102 | 0 | zend_undefined_method(called_scope, mname); |
5103 | 0 | } |
5104 | 0 | zend_string_release_ex(lcname, 0); |
5105 | 0 | zend_string_release_ex(mname, 0); |
5106 | 0 | return NULL; |
5107 | 0 | } |
5108 | | |
5109 | 3 | zend_string_release_ex(lcname, 0); |
5110 | 3 | zend_string_release_ex(mname, 0); |
5111 | | |
5112 | 3 | if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) { |
5113 | 0 | zend_non_static_method_call(fbc); |
5114 | 0 | if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { |
5115 | 0 | zend_string_release_ex(fbc->common.function_name, 0); |
5116 | 0 | zend_free_trampoline(fbc); |
5117 | 0 | } |
5118 | 0 | return NULL; |
5119 | 0 | } |
5120 | 3 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5121 | 0 | init_func_run_time_cache(&fbc->op_array); |
5122 | 0 | } |
5123 | 156 | } else { |
5124 | 156 | if (ZSTR_VAL(function)[0] == '\\') { |
5125 | 1 | lcname = zend_string_alloc(ZSTR_LEN(function) - 1, 0); |
5126 | 1 | zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(function) + 1, ZSTR_LEN(function) - 1); |
5127 | 155 | } else { |
5128 | 155 | lcname = zend_string_tolower(function); |
5129 | 155 | } |
5130 | 156 | if (UNEXPECTED((func = zend_hash_find(EG(function_table), lcname)) == NULL)) { |
5131 | 19 | zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(function)); |
5132 | 19 | zend_string_release_ex(lcname, 0); |
5133 | 19 | return NULL; |
5134 | 19 | } |
5135 | 137 | zend_string_release_ex(lcname, 0); |
5136 | | |
5137 | 137 | fbc = Z_FUNC_P(func); |
5138 | 137 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5139 | 62 | init_func_run_time_cache(&fbc->op_array); |
5140 | 62 | } |
5141 | 137 | called_scope = NULL; |
5142 | 137 | } |
5143 | | |
5144 | 140 | return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC, |
5145 | 140 | fbc, num_args, called_scope); |
5146 | 165 | } |
5147 | | /* }}} */ |
5148 | | |
5149 | | static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_object *function, uint32_t num_args) /* {{{ */ |
5150 | 548 | { |
5151 | 548 | zend_function *fbc; |
5152 | 548 | void *object_or_called_scope; |
5153 | 548 | zend_class_entry *called_scope; |
5154 | 548 | zend_object *object; |
5155 | 548 | uint32_t call_info; |
5156 | | |
5157 | 548 | if (EXPECTED(function->handlers->get_closure) && |
5158 | 548 | EXPECTED(function->handlers->get_closure(function, &called_scope, &fbc, &object, 0) == SUCCESS)) { |
5159 | | |
5160 | 547 | object_or_called_scope = called_scope; |
5161 | 547 | if (EXPECTED(fbc->common.fn_flags & ZEND_ACC_CLOSURE)) { |
5162 | | /* Delay closure destruction until its invocation */ |
5163 | 514 | GC_ADDREF(ZEND_CLOSURE_OBJECT(fbc)); |
5164 | 514 | ZEND_ASSERT(ZEND_ACC_FAKE_CLOSURE == ZEND_CALL_FAKE_CLOSURE); |
5165 | 514 | call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_CLOSURE | |
5166 | 514 | (fbc->common.fn_flags & ZEND_ACC_FAKE_CLOSURE); |
5167 | 514 | if (object) { |
5168 | 66 | call_info |= ZEND_CALL_HAS_THIS; |
5169 | 66 | object_or_called_scope = object; |
5170 | 66 | } |
5171 | 514 | } else { |
5172 | 33 | call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC; |
5173 | 33 | if (object) { |
5174 | 33 | call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS; |
5175 | 33 | GC_ADDREF(object); /* For $this pointer */ |
5176 | 33 | object_or_called_scope = object; |
5177 | 33 | } |
5178 | 33 | } |
5179 | 547 | } else { |
5180 | 1 | zend_throw_error(NULL, "Object of type %s is not callable", ZSTR_VAL(function->ce->name)); |
5181 | 1 | return NULL; |
5182 | 1 | } |
5183 | | |
5184 | 547 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5185 | 15 | init_func_run_time_cache(&fbc->op_array); |
5186 | 15 | } |
5187 | | |
5188 | 547 | return zend_vm_stack_push_call_frame(call_info, |
5189 | 547 | fbc, num_args, object_or_called_scope); |
5190 | 548 | } |
5191 | | /* }}} */ |
5192 | | |
5193 | | static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_array *function, uint32_t num_args) /* {{{ */ |
5194 | 73 | { |
5195 | 73 | zend_function *fbc; |
5196 | 73 | void *object_or_called_scope; |
5197 | 73 | uint32_t call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC; |
5198 | | |
5199 | 73 | if (zend_hash_num_elements(function) == 2) { |
5200 | 72 | zval *obj; |
5201 | 72 | zval *method; |
5202 | 72 | obj = zend_hash_index_find(function, 0); |
5203 | 72 | method = zend_hash_index_find(function, 1); |
5204 | | |
5205 | 72 | if (UNEXPECTED(!obj) || UNEXPECTED(!method)) { |
5206 | 1 | zend_throw_error(NULL, "Array callback has to contain indices 0 and 1"); |
5207 | 1 | return NULL; |
5208 | 1 | } |
5209 | | |
5210 | 71 | ZVAL_DEREF(obj); |
5211 | 71 | if (UNEXPECTED(Z_TYPE_P(obj) != IS_STRING) && UNEXPECTED(Z_TYPE_P(obj) != IS_OBJECT)) { |
5212 | 0 | zend_throw_error(NULL, "First array member is not a valid class name or object"); |
5213 | 0 | return NULL; |
5214 | 0 | } |
5215 | | |
5216 | 71 | ZVAL_DEREF(method); |
5217 | 71 | if (UNEXPECTED(Z_TYPE_P(method) != IS_STRING)) { |
5218 | 3 | zend_throw_error(NULL, "Second array member is not a valid method"); |
5219 | 3 | return NULL; |
5220 | 3 | } |
5221 | | |
5222 | 68 | if (Z_TYPE_P(obj) == IS_STRING) { |
5223 | 31 | zend_class_entry *called_scope = zend_fetch_class_by_name(Z_STR_P(obj), NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); |
5224 | | |
5225 | 31 | if (UNEXPECTED(called_scope == NULL)) { |
5226 | 7 | return NULL; |
5227 | 7 | } |
5228 | | |
5229 | 24 | if (called_scope->get_static_method) { |
5230 | 0 | fbc = called_scope->get_static_method(called_scope, Z_STR_P(method)); |
5231 | 24 | } else { |
5232 | 24 | fbc = zend_std_get_static_method(called_scope, Z_STR_P(method), NULL); |
5233 | 24 | } |
5234 | 24 | if (UNEXPECTED(fbc == NULL)) { |
5235 | 1 | if (EXPECTED(!EG(exception))) { |
5236 | 1 | zend_undefined_method(called_scope, Z_STR_P(method)); |
5237 | 1 | } |
5238 | 1 | return NULL; |
5239 | 1 | } |
5240 | 23 | if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { |
5241 | 2 | zend_non_static_method_call(fbc); |
5242 | 2 | if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { |
5243 | 2 | zend_string_release_ex(fbc->common.function_name, 0); |
5244 | 2 | zend_free_trampoline(fbc); |
5245 | 2 | } |
5246 | 2 | return NULL; |
5247 | 2 | } |
5248 | 21 | object_or_called_scope = called_scope; |
5249 | 37 | } else { |
5250 | 37 | zend_object *object = Z_OBJ_P(obj); |
5251 | | |
5252 | 37 | fbc = Z_OBJ_HT_P(obj)->get_method(&object, Z_STR_P(method), NULL); |
5253 | 37 | if (UNEXPECTED(fbc == NULL)) { |
5254 | 0 | if (EXPECTED(!EG(exception))) { |
5255 | 0 | zend_undefined_method(object->ce, Z_STR_P(method)); |
5256 | 0 | } |
5257 | 0 | return NULL; |
5258 | 0 | } |
5259 | | |
5260 | 37 | if ((fbc->common.fn_flags & ZEND_ACC_STATIC) != 0) { |
5261 | 9 | object_or_called_scope = object->ce; |
5262 | 28 | } else { |
5263 | 28 | call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS; |
5264 | 28 | GC_ADDREF(object); /* For $this pointer */ |
5265 | 28 | object_or_called_scope = object; |
5266 | 28 | } |
5267 | 37 | } |
5268 | 68 | } else { |
5269 | 1 | zend_throw_error(NULL, "Array callback must have exactly two elements"); |
5270 | 1 | return NULL; |
5271 | 1 | } |
5272 | | |
5273 | 58 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5274 | 14 | init_func_run_time_cache(&fbc->op_array); |
5275 | 14 | } |
5276 | | |
5277 | 58 | return zend_vm_stack_push_call_frame(call_info, |
5278 | 58 | fbc, num_args, object_or_called_scope); |
5279 | 73 | } |
5280 | | /* }}} */ |
5281 | | |
5282 | 42.0k | #define ZEND_FAKE_OP_ARRAY ((zend_op_array*)(intptr_t)-1) |
5283 | | |
5284 | | static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval *inc_filename_zv, int type) /* {{{ */ |
5285 | 41.3k | { |
5286 | 41.3k | zend_op_array *new_op_array = NULL; |
5287 | 41.3k | zend_string *tmp_inc_filename; |
5288 | 41.3k | zend_string *inc_filename = zval_try_get_tmp_string(inc_filename_zv, &tmp_inc_filename); |
5289 | 41.3k | if (UNEXPECTED(!inc_filename)) { |
5290 | 3 | return NULL; |
5291 | 3 | } |
5292 | | |
5293 | 41.3k | switch (type) { |
5294 | 0 | case ZEND_INCLUDE_ONCE: |
5295 | 1.99k | case ZEND_REQUIRE_ONCE: { |
5296 | 1.99k | zend_file_handle file_handle; |
5297 | 1.99k | zend_string *resolved_path; |
5298 | | |
5299 | 1.99k | resolved_path = zend_resolve_path(inc_filename); |
5300 | 1.99k | if (EXPECTED(resolved_path)) { |
5301 | 1 | if (zend_hash_exists(&EG(included_files), resolved_path)) { |
5302 | 0 | new_op_array = ZEND_FAKE_OP_ARRAY; |
5303 | 0 | zend_string_release_ex(resolved_path, 0); |
5304 | 0 | break; |
5305 | 0 | } |
5306 | 1.99k | } else if (UNEXPECTED(EG(exception))) { |
5307 | 0 | break; |
5308 | 1.99k | } else if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) { |
5309 | 3 | zend_message_dispatcher( |
5310 | 3 | (type == ZEND_INCLUDE_ONCE) ? |
5311 | 3 | ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |
5312 | 3 | ZSTR_VAL(inc_filename)); |
5313 | 3 | break; |
5314 | 1.99k | } else { |
5315 | 1.99k | resolved_path = zend_string_copy(inc_filename); |
5316 | 1.99k | } |
5317 | | |
5318 | 1.99k | zend_stream_init_filename_ex(&file_handle, resolved_path); |
5319 | 1.99k | if (SUCCESS == zend_stream_open(&file_handle)) { |
5320 | | |
5321 | 1 | if (!file_handle.opened_path) { |
5322 | 0 | file_handle.opened_path = zend_string_copy(resolved_path); |
5323 | 0 | } |
5324 | | |
5325 | 1 | if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) { |
5326 | 1 | new_op_array = zend_compile_file(&file_handle, (type==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE)); |
5327 | 1 | } else { |
5328 | 0 | new_op_array = ZEND_FAKE_OP_ARRAY; |
5329 | 0 | } |
5330 | 1.99k | } else if (!EG(exception)) { |
5331 | 17 | zend_message_dispatcher( |
5332 | 17 | (type == ZEND_INCLUDE_ONCE) ? |
5333 | 17 | ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |
5334 | 17 | ZSTR_VAL(inc_filename)); |
5335 | 17 | } |
5336 | 1.99k | zend_destroy_file_handle(&file_handle); |
5337 | 1.99k | zend_string_release_ex(resolved_path, 0); |
5338 | 1.99k | } |
5339 | 0 | break; |
5340 | 708 | case ZEND_INCLUDE: |
5341 | 38.8k | case ZEND_REQUIRE: |
5342 | 38.8k | if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) { |
5343 | 82 | zend_message_dispatcher( |
5344 | 82 | (type == ZEND_INCLUDE) ? |
5345 | 78 | ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |
5346 | 82 | ZSTR_VAL(inc_filename)); |
5347 | 82 | break; |
5348 | 82 | } |
5349 | 38.8k | new_op_array = compile_filename(type, inc_filename); |
5350 | 38.8k | break; |
5351 | 445 | case ZEND_EVAL: { |
5352 | 445 | char *eval_desc = zend_make_compiled_string_description("eval()'d code"); |
5353 | 445 | new_op_array = zend_compile_string(inc_filename, eval_desc, ZEND_COMPILE_POSITION_AFTER_OPEN_TAG); |
5354 | 445 | efree(eval_desc); |
5355 | 445 | } |
5356 | 445 | break; |
5357 | 41.3k | EMPTY_SWITCH_DEFAULT_CASE() |
5358 | 41.3k | } |
5359 | | |
5360 | 36.7k | zend_tmp_string_release(tmp_inc_filename); |
5361 | 36.7k | return new_op_array; |
5362 | 41.3k | } |
5363 | | /* }}} */ |
5364 | | |
5365 | | static zend_never_inline bool ZEND_FASTCALL zend_fe_reset_iterator(zval *array_ptr, int by_ref OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5366 | 391 | { |
5367 | 391 | zend_class_entry *ce = Z_OBJCE_P(array_ptr); |
5368 | 391 | zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, by_ref); |
5369 | 391 | bool is_empty; |
5370 | | |
5371 | 391 | if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { |
5372 | 3 | if (iter) { |
5373 | 0 | OBJ_RELEASE(&iter->std); |
5374 | 0 | } |
5375 | 3 | if (!EG(exception)) { |
5376 | 0 | zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); |
5377 | 0 | } |
5378 | 3 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5379 | 3 | return 1; |
5380 | 3 | } |
5381 | | |
5382 | 388 | iter->index = 0; |
5383 | 388 | if (iter->funcs->rewind) { |
5384 | 388 | iter->funcs->rewind(iter); |
5385 | 388 | if (UNEXPECTED(EG(exception) != NULL)) { |
5386 | 100 | OBJ_RELEASE(&iter->std); |
5387 | 100 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5388 | 100 | return 1; |
5389 | 100 | } |
5390 | 388 | } |
5391 | | |
5392 | 288 | is_empty = iter->funcs->valid(iter) != SUCCESS; |
5393 | | |
5394 | 288 | if (UNEXPECTED(EG(exception) != NULL)) { |
5395 | 51 | OBJ_RELEASE(&iter->std); |
5396 | 51 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5397 | 51 | return 1; |
5398 | 51 | } |
5399 | 237 | iter->index = -1; /* will be set to 0 before using next handler */ |
5400 | | |
5401 | 237 | ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); |
5402 | 237 | Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; |
5403 | | |
5404 | 237 | return is_empty; |
5405 | 288 | } |
5406 | | /* }}} */ |
5407 | | |
5408 | | static zend_always_inline zend_result _zend_quick_get_constant( |
5409 | | const zval *key, uint32_t flags, bool check_defined_only OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5410 | 1.15k | { |
5411 | 1.15k | zval *zv; |
5412 | 1.15k | zend_constant *c = NULL; |
5413 | | |
5414 | | /* null/true/false are resolved during compilation, so don't check for them here. */ |
5415 | 1.15k | zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key)); |
5416 | 1.15k | if (zv) { |
5417 | 267 | c = (zend_constant*)Z_PTR_P(zv); |
5418 | 889 | } else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) { |
5419 | 35 | key++; |
5420 | 35 | zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key)); |
5421 | 35 | if (zv) { |
5422 | 17 | c = (zend_constant*)Z_PTR_P(zv); |
5423 | 17 | } |
5424 | 35 | } |
5425 | | |
5426 | 1.15k | if (!c) { |
5427 | 872 | if (!check_defined_only) { |
5428 | 869 | zend_throw_error(NULL, "Undefined constant \"%s\"", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); |
5429 | 869 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5430 | 869 | } |
5431 | 872 | return FAILURE; |
5432 | 872 | } |
5433 | | |
5434 | 284 | if (!check_defined_only) { |
5435 | 280 | ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value); |
5436 | 280 | if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) { |
5437 | 23 | if (!CONST_IS_RECURSIVE(c)) { |
5438 | 23 | CONST_PROTECT_RECURSION(c); |
5439 | 23 | zend_deprecated_constant(c, c->name); |
5440 | 23 | CONST_UNPROTECT_RECURSION(c); |
5441 | 23 | } |
5442 | 23 | return SUCCESS; |
5443 | 23 | } |
5444 | 280 | } |
5445 | | |
5446 | 261 | CACHE_PTR(opline->extended_value, c); |
5447 | 261 | return SUCCESS; |
5448 | 284 | } |
5449 | | /* }}} */ |
5450 | | |
5451 | | static zend_never_inline void ZEND_FASTCALL zend_quick_get_constant( |
5452 | | const zval *key, uint32_t flags OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5453 | 1.14k | { |
5454 | 1.14k | _zend_quick_get_constant(key, flags, 0 OPLINE_CC EXECUTE_DATA_CC); |
5455 | 1.14k | } /* }}} */ |
5456 | | |
5457 | | static zend_never_inline zend_result ZEND_FASTCALL zend_quick_check_constant( |
5458 | | const zval *key OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5459 | 7 | { |
5460 | 7 | return _zend_quick_get_constant(key, 0, 1 OPLINE_CC EXECUTE_DATA_CC); |
5461 | 7 | } /* }}} */ |
5462 | | |
5463 | | static zend_always_inline uint32_t zend_get_arg_offset_by_name( |
5464 | 1.06k | const zend_function *fbc, const zend_string *arg_name, void **cache_slot) { |
5465 | | /* Due to closures, the `fbc` address isn't unique if the memory address is reused. |
5466 | | * The argument info will be however and uniquely positions the arguments. |
5467 | | * We do support NULL arg_info, so we have to distinguish that from an uninitialized cache slot. */ |
5468 | 1.06k | void *unique_id = (void *) ((uintptr_t) fbc->common.arg_info | 1); |
5469 | | |
5470 | 1.06k | if (EXPECTED(*cache_slot == unique_id)) { |
5471 | 0 | return *(uintptr_t *)(cache_slot + 1); |
5472 | 0 | } |
5473 | | |
5474 | | // TODO: Use a hash table? |
5475 | 1.06k | uint32_t num_args = fbc->common.num_args; |
5476 | 3.31k | for (uint32_t i = 0; i < num_args; i++) { |
5477 | 3.15k | const zend_arg_info *arg_info = &fbc->common.arg_info[i]; |
5478 | 3.15k | if (zend_string_equals(arg_name, arg_info->name)) { |
5479 | 903 | if ((fbc->type == ZEND_USER_FUNCTION |
5480 | 825 | && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE))) |
5481 | 79 | || (fbc->type == ZEND_INTERNAL_FUNCTION |
5482 | 894 | && !(fbc->common.fn_flags & ZEND_ACC_NEVER_CACHE))) { |
5483 | 894 | *cache_slot = unique_id; |
5484 | 894 | *(uintptr_t *)(cache_slot + 1) = i; |
5485 | 894 | } |
5486 | 903 | return i; |
5487 | 903 | } |
5488 | 3.15k | } |
5489 | | |
5490 | 158 | if (fbc->common.fn_flags & ZEND_ACC_VARIADIC) { |
5491 | 144 | if ((fbc->type == ZEND_USER_FUNCTION |
5492 | 32 | && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE))) |
5493 | 112 | || (fbc->type == ZEND_INTERNAL_FUNCTION |
5494 | 138 | && !(fbc->common.fn_flags & ZEND_ACC_NEVER_CACHE))) { |
5495 | 138 | *cache_slot = unique_id; |
5496 | 138 | *(uintptr_t *)(cache_slot + 1) = fbc->common.num_args; |
5497 | 138 | } |
5498 | 144 | return fbc->common.num_args; |
5499 | 144 | } |
5500 | | |
5501 | 14 | return (uint32_t) -1; |
5502 | 158 | } |
5503 | | |
5504 | | zval * ZEND_FASTCALL zend_handle_named_arg( |
5505 | | zend_execute_data **call_ptr, zend_string *arg_name, |
5506 | 1.06k | uint32_t *arg_num_ptr, void **cache_slot) { |
5507 | 1.06k | zend_execute_data *call = *call_ptr; |
5508 | 1.06k | const zend_function *fbc = call->func; |
5509 | 1.06k | uint32_t arg_offset = zend_get_arg_offset_by_name(fbc, arg_name, cache_slot); |
5510 | 1.06k | if (UNEXPECTED(arg_offset == (uint32_t) -1)) { |
5511 | 14 | zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name)); |
5512 | 14 | return NULL; |
5513 | 14 | } |
5514 | | |
5515 | 1.04k | zval *arg; |
5516 | 1.04k | if (UNEXPECTED(arg_offset == fbc->common.num_args)) { |
5517 | | /* Unknown named parameter that will be collected into a variadic. */ |
5518 | 143 | if (!(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) { |
5519 | 132 | ZEND_ADD_CALL_FLAG(call, ZEND_CALL_HAS_EXTRA_NAMED_PARAMS); |
5520 | 132 | call->extra_named_params = zend_new_array(0); |
5521 | 132 | } |
5522 | | |
5523 | 143 | arg = zend_hash_add_empty_element(call->extra_named_params, arg_name); |
5524 | 143 | if (!arg) { |
5525 | 0 | zend_throw_error(NULL, "Named parameter $%s overwrites previous argument", |
5526 | 0 | ZSTR_VAL(arg_name)); |
5527 | 0 | return NULL; |
5528 | 0 | } |
5529 | 143 | *arg_num_ptr = arg_offset + 1; |
5530 | 143 | return arg; |
5531 | 143 | } |
5532 | | |
5533 | 903 | uint32_t current_num_args = ZEND_CALL_NUM_ARGS(call); |
5534 | | // TODO: We may wish to optimize the arg_offset == current_num_args case, |
5535 | | // which is probably common (if the named parameters are in order of declaration). |
5536 | 903 | if (arg_offset >= current_num_args) { |
5537 | 496 | uint32_t new_num_args = arg_offset + 1; |
5538 | 496 | ZEND_CALL_NUM_ARGS(call) = new_num_args; |
5539 | | |
5540 | 496 | uint32_t num_extra_args = new_num_args - current_num_args; |
5541 | 496 | zend_vm_stack_extend_call_frame(call_ptr, current_num_args, num_extra_args); |
5542 | 496 | call = *call_ptr; |
5543 | | |
5544 | 496 | arg = ZEND_CALL_VAR_NUM(call, arg_offset); |
5545 | 496 | if (num_extra_args > 1) { |
5546 | 369 | zval *zv = ZEND_CALL_VAR_NUM(call, current_num_args); |
5547 | 622 | do { |
5548 | 622 | ZVAL_UNDEF(zv); |
5549 | 622 | zv++; |
5550 | 622 | } while (zv != arg); |
5551 | 369 | ZEND_ADD_CALL_FLAG(call, ZEND_CALL_MAY_HAVE_UNDEF); |
5552 | 369 | } |
5553 | 496 | } else { |
5554 | 407 | arg = ZEND_CALL_VAR_NUM(call, arg_offset); |
5555 | 407 | if (UNEXPECTED(!Z_ISUNDEF_P(arg))) { |
5556 | 3 | zend_throw_error(NULL, "Named parameter $%s overwrites previous argument", |
5557 | 3 | ZSTR_VAL(arg_name)); |
5558 | 3 | return NULL; |
5559 | 3 | } |
5560 | 407 | } |
5561 | | |
5562 | 900 | *arg_num_ptr = arg_offset + 1; |
5563 | 900 | return arg; |
5564 | 903 | } |
5565 | | |
5566 | 17 | static zend_execute_data *start_fake_frame(zend_execute_data *call, const zend_op *opline) { |
5567 | 17 | zend_execute_data *old_prev_execute_data = call->prev_execute_data; |
5568 | 17 | call->prev_execute_data = EG(current_execute_data); |
5569 | 17 | call->opline = opline; |
5570 | 17 | EG(current_execute_data) = call; |
5571 | 17 | return old_prev_execute_data; |
5572 | 17 | } |
5573 | | |
5574 | 17 | static void end_fake_frame(zend_execute_data *call, zend_execute_data *old_prev_execute_data) { |
5575 | 17 | zend_execute_data *prev_execute_data = call->prev_execute_data; |
5576 | 17 | EG(current_execute_data) = prev_execute_data; |
5577 | 17 | call->prev_execute_data = old_prev_execute_data; |
5578 | 17 | if (UNEXPECTED(EG(exception)) && ZEND_USER_CODE(prev_execute_data->func->common.type)) { |
5579 | 3 | zend_rethrow_exception(prev_execute_data); |
5580 | 3 | } |
5581 | 17 | } |
5582 | | |
5583 | 368 | ZEND_API zend_result ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call) { |
5584 | 368 | zend_function *fbc = call->func; |
5585 | 368 | if (fbc->type == ZEND_USER_FUNCTION) { |
5586 | 313 | zend_op_array *op_array = &fbc->op_array; |
5587 | 313 | uint32_t num_args = ZEND_CALL_NUM_ARGS(call); |
5588 | 1.67k | for (uint32_t i = 0; i < num_args; i++) { |
5589 | 1.36k | zval *arg = ZEND_CALL_VAR_NUM(call, i); |
5590 | 1.36k | if (!Z_ISUNDEF_P(arg)) { |
5591 | 1.19k | continue; |
5592 | 1.19k | } |
5593 | | |
5594 | 175 | const zend_op *opline = &op_array->opcodes[i]; |
5595 | 175 | if (EXPECTED(opline->opcode == ZEND_RECV_INIT)) { |
5596 | 166 | zval *default_value = RT_CONSTANT(opline, opline->op2); |
5597 | 166 | if (Z_OPT_TYPE_P(default_value) == IS_CONSTANT_AST) { |
5598 | 1 | if (UNEXPECTED(!RUN_TIME_CACHE(op_array))) { |
5599 | 1 | init_func_run_time_cache(op_array); |
5600 | 1 | } |
5601 | | |
5602 | 1 | void *run_time_cache = RUN_TIME_CACHE(op_array); |
5603 | 1 | zval *cache_val = |
5604 | 1 | (zval *) ((char *) run_time_cache + Z_CACHE_SLOT_P(default_value)); |
5605 | | |
5606 | 1 | if (Z_TYPE_P(cache_val) != IS_UNDEF) { |
5607 | | /* We keep in cache only not refcounted values */ |
5608 | 0 | ZVAL_COPY_VALUE(arg, cache_val); |
5609 | 1 | } else { |
5610 | | /* Update constant inside a temporary zval, to make sure the CONSTANT_AST |
5611 | | * value is not accessible through back traces. */ |
5612 | 1 | zval tmp; |
5613 | 1 | ZVAL_COPY(&tmp, default_value); |
5614 | 1 | zend_execute_data *old = start_fake_frame(call, opline); |
5615 | 1 | zend_result ret = zval_update_constant_ex(&tmp, fbc->op_array.scope); |
5616 | 1 | end_fake_frame(call, old); |
5617 | 1 | if (UNEXPECTED(ret == FAILURE)) { |
5618 | 0 | zval_ptr_dtor_nogc(&tmp); |
5619 | 0 | return FAILURE; |
5620 | 0 | } |
5621 | 1 | ZVAL_COPY_VALUE(arg, &tmp); |
5622 | 1 | if (!Z_REFCOUNTED(tmp)) { |
5623 | 1 | ZVAL_COPY_VALUE(cache_val, &tmp); |
5624 | 1 | } |
5625 | 1 | } |
5626 | 165 | } else { |
5627 | 165 | ZVAL_COPY(arg, default_value); |
5628 | 165 | } |
5629 | 166 | } else { |
5630 | 9 | ZEND_ASSERT(opline->opcode == ZEND_RECV); |
5631 | 9 | zend_execute_data *old = start_fake_frame(call, opline); |
5632 | 9 | zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed"); |
5633 | 9 | end_fake_frame(call, old); |
5634 | 9 | return FAILURE; |
5635 | 9 | } |
5636 | 175 | } |
5637 | | |
5638 | 304 | return SUCCESS; |
5639 | 313 | } else { |
5640 | 55 | if (fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO) { |
5641 | | /* Magic function, let it deal with it. */ |
5642 | 6 | return SUCCESS; |
5643 | 6 | } |
5644 | | |
5645 | 49 | uint32_t num_args = ZEND_CALL_NUM_ARGS(call); |
5646 | 155 | for (uint32_t i = 0; i < num_args; i++) { |
5647 | 112 | zval *arg = ZEND_CALL_VAR_NUM(call, i); |
5648 | 112 | if (!Z_ISUNDEF_P(arg)) { |
5649 | 82 | continue; |
5650 | 82 | } |
5651 | | |
5652 | 30 | zend_arg_info *arg_info = &fbc->internal_function.arg_info[i]; |
5653 | 30 | if (i < fbc->common.required_num_args) { |
5654 | 6 | zend_execute_data *old = start_fake_frame(call, NULL); |
5655 | 6 | zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed"); |
5656 | 6 | end_fake_frame(call, old); |
5657 | 6 | return FAILURE; |
5658 | 6 | } |
5659 | | |
5660 | 24 | zval default_value; |
5661 | 24 | if (zend_get_default_from_internal_arg_info(&default_value, arg_info) == FAILURE) { |
5662 | 0 | zend_execute_data *old = start_fake_frame(call, NULL); |
5663 | 0 | zend_argument_error(zend_ce_argument_count_error, i + 1, |
5664 | 0 | "must be passed explicitly, because the default value is not known"); |
5665 | 0 | end_fake_frame(call, old); |
5666 | 0 | return FAILURE; |
5667 | 0 | } |
5668 | | |
5669 | 24 | if (Z_TYPE(default_value) == IS_CONSTANT_AST) { |
5670 | 1 | zend_execute_data *old = start_fake_frame(call, NULL); |
5671 | 1 | zend_result ret = zval_update_constant_ex(&default_value, fbc->common.scope); |
5672 | 1 | end_fake_frame(call, old); |
5673 | 1 | if (ret == FAILURE) { |
5674 | 0 | return FAILURE; |
5675 | 0 | } |
5676 | 1 | } |
5677 | | |
5678 | 24 | ZVAL_COPY_VALUE(arg, &default_value); |
5679 | 24 | if (ZEND_ARG_SEND_MODE(arg_info) & ZEND_SEND_BY_REF) { |
5680 | 0 | ZVAL_NEW_REF(arg, arg); |
5681 | 0 | } |
5682 | 24 | } |
5683 | 49 | } |
5684 | | |
5685 | 43 | return SUCCESS; |
5686 | 368 | } |
5687 | | |
5688 | | ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named_params) |
5689 | 126 | { |
5690 | | /* Extra named params may be shared. */ |
5691 | 126 | zend_array_release(extra_named_params); |
5692 | 126 | } |
5693 | | |
5694 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
5695 | | /* Special versions of functions that sets EX(opline) before calling zend_vm_stack_extend() */ |
5696 | | static zend_always_inline zend_execute_data *_zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope) /* {{{ */ |
5697 | | { |
5698 | | zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top); |
5699 | | |
5700 | | ZEND_ASSERT_VM_STACK_GLOBAL; |
5701 | | |
5702 | | if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) { |
5703 | | EX(opline) = opline; /* this is the only difference */ |
5704 | | call = (zend_execute_data*)zend_vm_stack_extend(used_stack); |
5705 | | ZEND_ASSERT_VM_STACK_GLOBAL; |
5706 | | zend_vm_init_call_frame(call, call_info | ZEND_CALL_ALLOCATED, func, num_args, object_or_called_scope); |
5707 | | return call; |
5708 | | } else { |
5709 | | EG(vm_stack_top) = (zval*)((char*)call + used_stack); |
5710 | | zend_vm_init_call_frame(call, call_info, func, num_args, object_or_called_scope); |
5711 | | return call; |
5712 | | } |
5713 | | } /* }}} */ |
5714 | | |
5715 | | static zend_always_inline zend_execute_data *_zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope) /* {{{ */ |
5716 | | { |
5717 | | uint32_t used_stack = zend_vm_calc_used_stack(num_args, func); |
5718 | | |
5719 | | return _zend_vm_stack_push_call_frame_ex(used_stack, call_info, |
5720 | | func, num_args, object_or_called_scope); |
5721 | | } /* }}} */ |
5722 | | #else |
5723 | 146k | # define _zend_vm_stack_push_call_frame_ex zend_vm_stack_push_call_frame_ex |
5724 | 477 | # define _zend_vm_stack_push_call_frame zend_vm_stack_push_call_frame |
5725 | | #endif |
5726 | | |
5727 | | #ifdef ZEND_VM_TRACE_HANDLERS |
5728 | | # include "zend_vm_trace_handlers.h" |
5729 | | #elif defined(ZEND_VM_TRACE_LINES) |
5730 | | # include "zend_vm_trace_lines.h" |
5731 | | #elif defined(ZEND_VM_TRACE_MAP) |
5732 | | # include "zend_vm_trace_map.h" |
5733 | | #elif defined(ZEND_VERIFY_TYPE_INFERENCE) |
5734 | | # include "zend_verify_type_inference.h" |
5735 | | #endif |
5736 | | |
5737 | | #define ZEND_VM_NEXT_OPCODE_EX(check_exception, skip) \ |
5738 | 4.70M | CHECK_SYMBOL_TABLES() \ |
5739 | 4.75M | if (check_exception) { \ |
5740 | 2.96M | OPLINE = EX(opline) + (skip); \ |
5741 | 2.96M | } else { \ |
5742 | 1.78M | ZEND_ASSERT(!EG(exception)); \ |
5743 | 1.78M | OPLINE = opline + (skip); \ |
5744 | 1.74M | } \ |
5745 | 4.70M | ZEND_VM_CONTINUE() |
5746 | | |
5747 | | #define ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION() \ |
5748 | 2.92M | ZEND_VM_NEXT_OPCODE_EX(1, 1) |
5749 | | |
5750 | | #define ZEND_VM_NEXT_OPCODE() \ |
5751 | 1.97M | ZEND_VM_NEXT_OPCODE_EX(0, 1) |
5752 | | |
5753 | | #define ZEND_VM_SET_NEXT_OPCODE(new_op) \ |
5754 | 149k | CHECK_SYMBOL_TABLES() \ |
5755 | 149k | OPLINE = new_op |
5756 | | |
5757 | | #define ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op) \ |
5758 | 902k | CHECK_SYMBOL_TABLES() \ |
5759 | 902k | OPLINE = new_op |
5760 | | |
5761 | | #define ZEND_VM_SET_OPCODE(new_op) \ |
5762 | 492k | ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op); \ |
5763 | 492k | ZEND_VM_INTERRUPT_CHECK() |
5764 | | |
5765 | | #define ZEND_VM_SET_RELATIVE_OPCODE(opline, offset) \ |
5766 | 4.51k | ZEND_VM_SET_OPCODE(ZEND_OFFSET_TO_OPLINE(opline, offset)) |
5767 | | |
5768 | 438k | #define ZEND_VM_JMP_EX(new_op, check_exception) do { \ |
5769 | 438k | if (check_exception && UNEXPECTED(EG(exception))) { \ |
5770 | 0 | HANDLE_EXCEPTION(); \ |
5771 | 0 | } \ |
5772 | 438k | ZEND_VM_SET_OPCODE(new_op); \ |
5773 | 438k | ZEND_VM_CONTINUE(); \ |
5774 | 438k | } while (0) |
5775 | | |
5776 | | #define ZEND_VM_JMP(new_op) \ |
5777 | 31.3k | ZEND_VM_JMP_EX(new_op, 1) |
5778 | | |
5779 | | #define ZEND_VM_INC_OPCODE() \ |
5780 | 662 | OPLINE++ |
5781 | | |
5782 | | |
5783 | | #define ZEND_VM_REPEATABLE_OPCODE \ |
5784 | 526 | do { |
5785 | | #define ZEND_VM_REPEAT_OPCODE(_opcode) \ |
5786 | 526 | } while (UNEXPECTED((++opline)->opcode == _opcode)); \ |
5787 | 451 | OPLINE = opline; \ |
5788 | 481 | ZEND_VM_CONTINUE() |
5789 | 145k | #define ZEND_VM_SMART_BRANCH(_result, _check) do { \ |
5790 | 145k | if ((_check) && UNEXPECTED(EG(exception))) { \ |
5791 | 10 | OPLINE = EX(opline); \ |
5792 | 145k | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \ |
5793 | 107k | if (_result) { \ |
5794 | 104k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5795 | 104k | } else { \ |
5796 | 3.17k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5797 | 3.17k | } \ |
5798 | 107k | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \ |
5799 | 9.59k | if (!(_result)) { \ |
5800 | 1.01k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5801 | 8.57k | } else { \ |
5802 | 8.57k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5803 | 8.57k | } \ |
5804 | 28.0k | } else { \ |
5805 | 28.0k | ZVAL_BOOL(EX_VAR(opline->result.var), _result); \ |
5806 | 28.0k | ZEND_VM_SET_NEXT_OPCODE(opline + 1); \ |
5807 | 28.0k | } \ |
5808 | 145k | ZEND_VM_CONTINUE(); \ |
5809 | 145k | } while (0) |
5810 | 431 | #define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check) do { \ |
5811 | 431 | if ((_check) && UNEXPECTED(EG(exception))) { \ |
5812 | 0 | OPLINE = EX(opline); \ |
5813 | 431 | } else if (_result) { \ |
5814 | 226 | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5815 | 226 | } else { \ |
5816 | 205 | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5817 | 205 | } \ |
5818 | 431 | ZEND_VM_CONTINUE(); \ |
5819 | 431 | } while (0) |
5820 | 1.88k | #define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check) do { \ |
5821 | 1.88k | if ((_check) && UNEXPECTED(EG(exception))) { \ |
5822 | 0 | OPLINE = EX(opline); \ |
5823 | 1.88k | } else if (!(_result)) { \ |
5824 | 179 | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5825 | 1.70k | } else { \ |
5826 | 1.70k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5827 | 1.70k | } \ |
5828 | 1.88k | ZEND_VM_CONTINUE(); \ |
5829 | 1.88k | } while (0) |
5830 | 41 | #define ZEND_VM_SMART_BRANCH_NONE(_result, _check) do { \ |
5831 | 41 | ZVAL_BOOL(EX_VAR(opline->result.var), _result); \ |
5832 | 41 | ZEND_VM_NEXT_OPCODE_EX(_check, 1); \ |
5833 | 41 | ZEND_VM_CONTINUE(); \ |
5834 | 41 | } while (0) |
5835 | 10 | #define ZEND_VM_SMART_BRANCH_TRUE() do { \ |
5836 | 10 | if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \ |
5837 | 1 | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5838 | 9 | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \ |
5839 | 7 | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5840 | 7 | } else { \ |
5841 | 2 | ZVAL_TRUE(EX_VAR(opline->result.var)); \ |
5842 | 2 | ZEND_VM_SET_NEXT_OPCODE(opline + 1); \ |
5843 | 2 | } \ |
5844 | 10 | ZEND_VM_CONTINUE(); \ |
5845 | 10 | } while (0) |
5846 | 13.8k | #define ZEND_VM_SMART_BRANCH_TRUE_JMPZ() do { \ |
5847 | 13.8k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5848 | 13.8k | ZEND_VM_CONTINUE(); \ |
5849 | 13.8k | } while (0) |
5850 | 35.0k | #define ZEND_VM_SMART_BRANCH_TRUE_JMPNZ() do { \ |
5851 | 35.0k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5852 | 35.0k | ZEND_VM_CONTINUE(); \ |
5853 | 35.0k | } while (0) |
5854 | 1.49k | #define ZEND_VM_SMART_BRANCH_TRUE_NONE() do { \ |
5855 | 1.49k | ZVAL_TRUE(EX_VAR(opline->result.var)); \ |
5856 | 1.49k | ZEND_VM_NEXT_OPCODE(); \ |
5857 | 1.49k | } while (0) |
5858 | 8 | #define ZEND_VM_SMART_BRANCH_FALSE() do { \ |
5859 | 8 | if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \ |
5860 | 2 | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5861 | 6 | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \ |
5862 | 0 | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5863 | 6 | } else { \ |
5864 | 6 | ZVAL_FALSE(EX_VAR(opline->result.var)); \ |
5865 | 6 | ZEND_VM_SET_NEXT_OPCODE(opline + 1); \ |
5866 | 6 | } \ |
5867 | 8 | ZEND_VM_CONTINUE(); \ |
5868 | 8 | } while (0) |
5869 | 1.26k | #define ZEND_VM_SMART_BRANCH_FALSE_JMPZ() do { \ |
5870 | 1.26k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5871 | 1.26k | ZEND_VM_CONTINUE(); \ |
5872 | 1.26k | } while (0) |
5873 | 1.74k | #define ZEND_VM_SMART_BRANCH_FALSE_JMPNZ() do { \ |
5874 | 1.74k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5875 | 1.74k | ZEND_VM_CONTINUE(); \ |
5876 | 1.74k | } while (0) |
5877 | 2.45k | #define ZEND_VM_SMART_BRANCH_FALSE_NONE() do { \ |
5878 | 2.45k | ZVAL_FALSE(EX_VAR(opline->result.var)); \ |
5879 | 2.45k | ZEND_VM_NEXT_OPCODE(); \ |
5880 | 2.45k | } while (0) |
5881 | | |
5882 | | #ifdef __GNUC__ |
5883 | | # define ZEND_VM_GUARD(name) __asm__("#" #name) |
5884 | | #else |
5885 | | # define ZEND_VM_GUARD(name) |
5886 | | #endif |
5887 | | |
5888 | 938 | #define UNDEF_RESULT() do { \ |
5889 | 938 | if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { \ |
5890 | 151 | ZVAL_UNDEF(EX_VAR(opline->result.var)); \ |
5891 | 151 | } \ |
5892 | 938 | } while (0) |
5893 | | |
5894 | | /* This callback disables optimization of "vm_stack_data" variable in VM */ |
5895 | | ZEND_API void (ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data) = NULL; |
5896 | | |
5897 | | #include "zend_vm_execute.h" |
5898 | | |
5899 | | ZEND_API zend_result zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler) |
5900 | 0 | { |
5901 | 0 | if (opcode != ZEND_USER_OPCODE) { |
5902 | 0 | if (handler == NULL) { |
5903 | | /* restore the original handler */ |
5904 | 0 | zend_user_opcodes[opcode] = opcode; |
5905 | 0 | } else { |
5906 | 0 | zend_user_opcodes[opcode] = ZEND_USER_OPCODE; |
5907 | 0 | } |
5908 | 0 | zend_user_opcode_handlers[opcode] = handler; |
5909 | 0 | return SUCCESS; |
5910 | 0 | } |
5911 | 0 | return FAILURE; |
5912 | 0 | } |
5913 | | |
5914 | | ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode) |
5915 | 3.58k | { |
5916 | 3.58k | return zend_user_opcode_handlers[opcode]; |
5917 | 3.58k | } |
5918 | | |
5919 | | ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data) |
5920 | 0 | { |
5921 | 0 | zval *ret; |
5922 | |
|
5923 | 0 | switch (op_type) { |
5924 | 0 | case IS_CONST: |
5925 | 0 | ret = RT_CONSTANT(opline, *node); |
5926 | 0 | break; |
5927 | 0 | case IS_TMP_VAR: |
5928 | 0 | case IS_VAR: |
5929 | 0 | case IS_CV: |
5930 | 0 | ret = EX_VAR(node->var); |
5931 | 0 | break; |
5932 | 0 | default: |
5933 | 0 | ret = NULL; |
5934 | 0 | break; |
5935 | 0 | } |
5936 | 0 | return ret; |
5937 | 0 | } |