Coverage Report

Created: 2026-01-18 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
0
# define EXECUTE_DATA_C     execute_data
89
# define EXECUTE_DATA_DC    , EXECUTE_DATA_D
90
0
# define EXECUTE_DATA_CC    , EXECUTE_DATA_C
91
0
# 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
0
# define OPLINE_C           opline
102
# define OPLINE_DC          , OPLINE_D
103
0
# 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
83.7M
#define _CONST_CODE  0
114
83.7M
#define _TMP_CODE    1
115
83.7M
#define _VAR_CODE    2
116
418M
#define _UNUSED_CODE 3
117
83.7M
#define _CV_CODE     4
118
119
typedef int (ZEND_FASTCALL *incdec_t)(zval *);
120
121
0
#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
0
#define get_zval_ptr_undef(op_type, node, type) _get_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
124
0
#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
0
#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
0
#define RETURN_VALUE_USED(opline) ((opline)->result_type != IS_UNUSED)
134
135
static ZEND_FUNCTION(pass)
136
0
{
137
0
}
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
0
#define FREE_VAR_PTR_AND_EXTRACT_RESULT_IF_NECESSARY(free_var) do {     \
164
0
  zval *__container_to_free = EX_VAR(free_var);             \
165
0
  if (UNEXPECTED(Z_REFCOUNTED_P(__container_to_free))) {         \
166
0
    zend_refcounted *__ref = Z_COUNTED_P(__container_to_free);      \
167
0
    if (UNEXPECTED(!GC_DELREF(__ref))) {               \
168
0
      zval *__zv = EX_VAR(opline->result.var);           \
169
0
      if (EXPECTED(Z_TYPE_P(__zv) == IS_INDIRECT)) {         \
170
0
        ZVAL_COPY(__zv, Z_INDIRECT_P(__zv));           \
171
0
      }                               \
172
0
      rc_dtor_func(__ref);                      \
173
0
    }                                 \
174
0
  }                                   \
175
0
} while (0)
176
177
#define FREE_OP(type, var) \
178
0
  if ((type) & (IS_TMP_VAR|IS_VAR)) { \
179
0
    zval_ptr_dtor_nogc(EX_VAR(var)); \
180
0
  }
181
182
0
#define CV_DEF_OF(i) (EX(func)->op_array.vars[i])
183
184
107k
#define ZEND_VM_STACK_PAGE_SLOTS (16 * 1024) /* should be a power of 2 */
185
186
107k
#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
0
  (((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \
190
0
    + ((page_size) - 1)) & ~((page_size) - 1))
191
192
ZEND_API void zend_vm_stack_init(void)
193
53.5k
{
194
53.5k
  EG(vm_stack_page_size) = ZEND_VM_STACK_PAGE_SIZE;
195
53.5k
  EG(vm_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE, NULL);
196
53.5k
  EG(vm_stack_top) = EG(vm_stack)->top;
197
53.5k
  EG(vm_stack_end) = EG(vm_stack)->end;
198
53.5k
}
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
53.5k
{
212
53.5k
  zend_vm_stack stack = EG(vm_stack);
213
214
107k
  while (stack != NULL) {
215
53.5k
    zend_vm_stack p = stack->prev;
216
53.5k
    efree(stack);
217
53.5k
    stack = p;
218
53.5k
  }
219
53.5k
}
220
221
ZEND_API void* zend_vm_stack_extend(size_t size)
222
0
{
223
0
  zend_vm_stack stack;
224
0
  void *ptr;
225
226
0
  stack = EG(vm_stack);
227
0
  stack->top = EG(vm_stack_top);
228
0
  EG(vm_stack) = stack = zend_vm_stack_new_page(
229
0
    EXPECTED(size < EG(vm_stack_page_size) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval))) ?
230
0
      EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, EG(vm_stack_page_size)),
231
0
    stack);
232
0
  ptr = stack->top;
233
0
  EG(vm_stack_top) = (void*)(((char*)ptr) + size);
234
0
  EG(vm_stack_end) = stack->end;
235
0
  return ptr;
236
0
}
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
0
{
254
0
  zval *ret = EX_VAR(var);
255
256
0
  ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE);
257
258
0
  return ret;
259
0
}
260
261
static zend_always_inline zval *_get_zval_ptr_var(uint32_t var EXECUTE_DATA_DC)
262
0
{
263
0
  zval *ret = EX_VAR(var);
264
265
0
  return ret;
266
0
}
267
268
static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var EXECUTE_DATA_DC)
269
0
{
270
0
  zval *ret = EX_VAR(var);
271
272
0
  ZVAL_DEREF(ret);
273
0
  return ret;
274
0
}
275
276
static zend_never_inline ZEND_COLD zval* zval_undefined_cv(uint32_t var EXECUTE_DATA_DC)
277
0
{
278
0
  if (EXPECTED(EG(exception) == NULL)) {
279
0
    zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
280
0
    zend_error_unchecked(E_WARNING, "Undefined variable $%S", cv);
281
0
  }
282
0
  return &EG(uninitialized_zval);
283
0
}
284
285
static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op1(EXECUTE_DATA_D)
286
0
{
287
0
  return zval_undefined_cv(EX(opline)->op1.var EXECUTE_DATA_CC);
288
0
}
289
290
static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op2(EXECUTE_DATA_D)
291
0
{
292
0
  return zval_undefined_cv(EX(opline)->op2.var EXECUTE_DATA_CC);
293
0
}
294
295
0
#define ZVAL_UNDEFINED_OP1() _zval_undefined_op1(EXECUTE_DATA_C)
296
0
#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
0
{
300
0
  switch (type) {
301
0
    case BP_VAR_R:
302
0
    case BP_VAR_UNSET:
303
0
      ptr = zval_undefined_cv(var EXECUTE_DATA_CC);
304
0
      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
0
  }
315
0
  return ptr;
316
0
}
317
318
static zend_always_inline zval *_get_zval_ptr_cv(uint32_t var, int type EXECUTE_DATA_DC)
319
0
{
320
0
  zval *ret = EX_VAR(var);
321
322
0
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
323
0
    if (type == BP_VAR_W) {
324
0
      ZVAL_NULL(ret);
325
0
    } else {
326
0
      return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC);
327
0
    }
328
0
  }
329
0
  return ret;
330
0
}
331
332
static zend_always_inline zval *_get_zval_ptr_cv_deref(uint32_t var, int type EXECUTE_DATA_DC)
333
0
{
334
0
  zval *ret = EX_VAR(var);
335
336
0
  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
0
  ZVAL_DEREF(ret);
345
0
  return ret;
346
0
}
347
348
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(uint32_t var EXECUTE_DATA_DC)
349
0
{
350
0
  zval *ret = EX_VAR(var);
351
352
0
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
353
0
    return zval_undefined_cv(var EXECUTE_DATA_CC);
354
0
  }
355
0
  return ret;
356
0
}
357
358
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_R(uint32_t var EXECUTE_DATA_DC)
359
0
{
360
0
  zval *ret = EX_VAR(var);
361
362
0
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
363
0
    return zval_undefined_cv(var EXECUTE_DATA_CC);
364
0
  }
365
0
  ZVAL_DEREF(ret);
366
0
  return ret;
367
0
}
368
369
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_IS(uint32_t var EXECUTE_DATA_DC)
370
0
{
371
0
  zval *ret = EX_VAR(var);
372
373
0
  return ret;
374
0
}
375
376
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(uint32_t var EXECUTE_DATA_DC)
377
0
{
378
0
  zval *ret = EX_VAR(var);
379
380
0
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
381
0
    zval_undefined_cv(var EXECUTE_DATA_CC);
382
0
    ZVAL_NULL(ret);
383
0
    return ret;
384
0
  }
385
0
  return ret;
386
0
}
387
388
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(uint32_t var EXECUTE_DATA_DC)
389
0
{
390
0
  zval *ret = EX_VAR(var);
391
392
0
  if (Z_TYPE_P(ret) == IS_UNDEF) {
393
0
    ZVAL_NULL(ret);
394
0
  }
395
0
  return ret;
396
0
}
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
0
{
415
0
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
416
0
    if (!ZEND_DEBUG || op_type == IS_VAR) {
417
0
      return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
418
0
    } else {
419
0
      ZEND_ASSERT(op_type == IS_TMP_VAR);
420
0
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
421
0
    }
422
0
  } else {
423
0
    if (op_type == IS_CONST) {
424
0
      return RT_CONSTANT(opline, node);
425
0
    } else if (op_type == IS_CV) {
426
0
      return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC);
427
0
    } else {
428
0
      return NULL;
429
0
    }
430
0
  }
431
0
}
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
0
{
435
0
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
436
0
    if (!ZEND_DEBUG || op_type == IS_VAR) {
437
0
      return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
438
0
    } else {
439
0
      ZEND_ASSERT(op_type == IS_TMP_VAR);
440
0
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
441
0
    }
442
0
  } else {
443
0
    if (op_type == IS_CONST) {
444
0
      return RT_CONSTANT(opline + 1, node);
445
0
    } else if (op_type == IS_CV) {
446
0
      return _get_zval_ptr_cv_BP_VAR_R(node.var EXECUTE_DATA_CC);
447
0
    } else {
448
0
      return NULL;
449
0
    }
450
0
  }
451
0
}
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
0
{
455
0
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
456
0
    if (op_type == IS_TMP_VAR) {
457
0
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
458
0
    } else {
459
0
      ZEND_ASSERT(op_type == IS_VAR);
460
0
      return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
461
0
    }
462
0
  } else {
463
0
    if (op_type == IS_CONST) {
464
0
      return RT_CONSTANT(opline, node);
465
0
    } else if (op_type == IS_CV) {
466
0
      return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC);
467
0
    } else {
468
0
      return NULL;
469
0
    }
470
0
  }
471
0
}
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
0
{
495
0
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
496
0
    if (!ZEND_DEBUG || op_type == IS_VAR) {
497
0
      return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
498
0
    } 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
0
  } else {
503
0
    if (op_type == IS_CONST) {
504
0
      return RT_CONSTANT(opline, node);
505
0
    } else if (op_type == IS_CV) {
506
0
      return EX_VAR(node.var);
507
0
    } else {
508
0
      return NULL;
509
0
    }
510
0
  }
511
0
}
512
513
static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var EXECUTE_DATA_DC)
514
0
{
515
0
  zval *ret = EX_VAR(var);
516
517
0
  if (EXPECTED(Z_TYPE_P(ret) == IS_INDIRECT)) {
518
0
    ret = Z_INDIRECT_P(ret);
519
0
  }
520
0
  return ret;
521
0
}
522
523
static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC)
524
0
{
525
0
  if (op_type == IS_CV) {
526
0
    return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC);
527
0
  } else /* if (op_type == IS_VAR) */ {
528
0
    ZEND_ASSERT(op_type == IS_VAR);
529
0
    return _get_zval_ptr_ptr_var(node.var EXECUTE_DATA_CC);
530
0
  }
531
0
}
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
0
{
567
0
  zend_reference *ref;
568
569
0
  if (EXPECTED(!Z_ISREF_P(value_ptr))) {
570
0
    ZVAL_NEW_REF(value_ptr, value_ptr);
571
0
  } else if (UNEXPECTED(variable_ptr == value_ptr)) {
572
0
    return;
573
0
  }
574
575
0
  ref = Z_REF_P(value_ptr);
576
0
  GC_ADDREF(ref);
577
0
  if (Z_REFCOUNTED_P(variable_ptr)) {
578
0
    *garbage_ptr = Z_COUNTED_P(variable_ptr);
579
0
  }
580
0
  ZVAL_REF(variable_ptr, ref);
581
0
}
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
0
{
585
0
  if (!zend_verify_prop_assignable_by_ref(prop_info, value_ptr, EX_USES_STRICT_TYPES())) {
586
0
    return &EG(uninitialized_zval);
587
0
  }
588
0
  if (Z_ISREF_P(prop)) {
589
0
    ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(prop), prop_info);
590
0
  }
591
0
  zend_assign_to_variable_reference(prop, value_ptr, garbage_ptr);
592
0
  ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(prop), prop_info);
593
0
  return prop;
594
0
}
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
0
{
598
0
  zend_error(E_NOTICE, "Only variables should be assigned by reference");
599
0
  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
0
  Z_TRY_ADDREF_P(value_ptr);
605
0
  return zend_assign_to_variable_ex(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr);
606
0
}
607
608
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num)
609
0
{
610
0
  const zend_execute_data *execute_data = EG(current_execute_data);
611
0
  zend_string *func_name = get_function_or_method_name(EX(call)->func);
612
0
  const char *param_name = get_function_arg_name(EX(call)->func, arg_num);
613
614
0
  zend_throw_error(NULL, "%s(): Argument #%d%s%s%s could not be passed by reference",
615
0
    ZSTR_VAL(func_name), arg_num, param_name ? " ($" : "", param_name ? param_name : "", param_name ? ")" : ""
616
0
  );
617
618
0
  zend_string_release(func_name);
619
0
}
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
0
    const zend_property_info *prop) {
643
0
  zend_throw_error(NULL,
644
0
    "Cannot access uninitialized non-nullable property %s::$%s by reference",
645
0
    ZSTR_VAL(prop->ce->name),
646
0
    zend_get_unmangled_property_name(prop->name));
647
0
}
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
0
{
652
0
  zend_string *tmp_property_name;
653
0
  zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
654
655
0
  if (opline->opcode == ZEND_PRE_INC_OBJ
656
0
   || opline->opcode == ZEND_PRE_DEC_OBJ
657
0
   || opline->opcode == ZEND_POST_INC_OBJ
658
0
   || opline->opcode == ZEND_POST_DEC_OBJ) {
659
0
    zend_throw_error(NULL,
660
0
      "Attempt to increment/decrement property \"%s\" on %s",
661
0
      ZSTR_VAL(property_name), zend_zval_value_name(object)
662
0
    );
663
0
  } else if (opline->opcode == ZEND_FETCH_OBJ_W
664
0
      || opline->opcode == ZEND_FETCH_OBJ_RW
665
0
      || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG
666
0
      || opline->opcode == ZEND_ASSIGN_OBJ_REF) {
667
0
    zend_throw_error(NULL,
668
0
      "Attempt to modify property \"%s\" on %s",
669
0
      ZSTR_VAL(property_name), zend_zval_value_name(object)
670
0
    );
671
0
  } else {
672
0
    zend_throw_error(NULL,
673
0
      "Attempt to assign property \"%s\" on %s",
674
0
      ZSTR_VAL(property_name), zend_zval_value_name(object)
675
0
    );
676
0
  }
677
0
  zend_tmp_string_release(tmp_property_name);
678
679
0
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
680
0
    ZVAL_NULL(EX_VAR(opline->result.var));
681
0
  }
682
0
}
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
0
{
689
0
  *fname = ZSTR_VAL(zf->common.function_name);
690
0
  if (zf->common.scope) {
691
0
    *fsep =  "::";
692
0
    *fclass = ZSTR_VAL(zf->common.scope->name);
693
0
  } else {
694
0
    *fsep =  "";
695
0
    *fclass = "";
696
0
  }
697
698
0
  *need_msg = zend_type_to_string_resolved(arg_info->type, zf->common.scope);
699
700
0
  if (value) {
701
0
    *given_kind = zend_zval_value_name(value);
702
0
  } else {
703
0
    *given_kind = "none";
704
0
  }
705
0
}
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
0
{
710
0
  const zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
711
0
  const char *fname, *fsep, *fclass;
712
0
  zend_string *need_msg;
713
0
  const char *given_msg;
714
715
0
  zend_verify_type_error_common(
716
0
    zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);
717
718
0
  ZEND_ASSERT(zf->common.type == ZEND_USER_FUNCTION
719
0
    && "Arginfo verification is not performed for internal functions");
720
0
  if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
721
0
    zend_argument_type_error(arg_num, "must be of type %s, %s given, called in %s on line %d",
722
0
      ZSTR_VAL(need_msg), given_msg,
723
0
      ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
724
0
    );
725
0
  } else {
726
0
    zend_argument_type_error(arg_num,
727
0
      "must be of type %s, %s given", ZSTR_VAL(need_msg), given_msg);
728
0
  }
729
730
0
  zend_string_release(need_msg);
731
0
}
732
733
static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
734
0
{
735
0
  zend_long lval;
736
0
  double dval;
737
0
  zend_string *str;
738
0
  bool bval;
739
740
  /* Type preference order: int -> float -> string -> bool */
741
0
  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
0
    if ((type_mask & MAY_BE_DOUBLE) && Z_TYPE_P(arg) == IS_STRING) {
745
0
      uint8_t type = is_numeric_str_function(Z_STR_P(arg), &lval, &dval);
746
0
      if (type == IS_LONG) {
747
0
        zend_string_release(Z_STR_P(arg));
748
0
        ZVAL_LONG(arg, lval);
749
0
        return true;
750
0
      }
751
0
      if (type == IS_DOUBLE) {
752
0
        zend_string_release(Z_STR_P(arg));
753
0
        ZVAL_DOUBLE(arg, dval);
754
0
        return true;
755
0
      }
756
0
    } else if (zend_parse_arg_long_weak(arg, &lval, 0)) {
757
0
      zval_ptr_dtor(arg);
758
0
      ZVAL_LONG(arg, lval);
759
0
      return true;
760
0
    } else if (UNEXPECTED(EG(exception))) {
761
0
      return false;
762
0
    }
763
0
  }
764
0
  if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) {
765
0
    zval_ptr_dtor(arg);
766
0
    ZVAL_DOUBLE(arg, dval);
767
0
    return true;
768
0
  }
769
0
  if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str, 0)) {
770
    /* on success "arg" is converted to IS_STRING */
771
0
    return true;
772
0
  }
773
0
  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
0
  return false;
779
0
}
780
781
#if ZEND_DEBUG
782
0
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
0
  if (Z_TYPE_P(zv) == IS_OBJECT) {
787
0
    return Z_OBJ_HT_P(zv)->cast_object != zend_std_cast_object_tostring
788
0
      || Z_OBJCE_P(zv)->__tostring;
789
0
  }
790
0
  return Z_TYPE_P(zv) <= IS_STRING;
791
0
}
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
0
{
796
0
  zend_long lval;
797
0
  double dval;
798
0
  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
0
  if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) {
803
0
    return true;
804
0
  }
805
0
  if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) {
806
0
    return true;
807
0
  }
808
0
  if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) {
809
0
    return true;
810
0
  }
811
0
  if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) {
812
0
    return true;
813
0
  }
814
0
  return false;
815
0
}
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
0
{
820
0
  if (UNEXPECTED(strict)) {
821
    /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */
822
0
    if (!(type_mask & MAY_BE_DOUBLE) || Z_TYPE_P(arg) != IS_LONG) {
823
0
      return 0;
824
0
    }
825
0
  } 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
0
    return is_internal_arg
829
0
      && (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING));
830
0
  }
831
0
#if ZEND_DEBUG
832
0
  if (is_internal_arg) {
833
0
    return zend_verify_weak_scalar_type_hint_no_sideeffect(type_mask, arg);
834
0
  }
835
0
#endif
836
0
  return zend_verify_weak_scalar_type_hint(type_mask, arg);
837
0
}
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
0
{
841
0
  zend_string *type_str = zend_type_to_string(c->type);
842
843
0
  zend_type_error("Cannot assign %s to class constant %s::%s of type %s",
844
0
    zend_zval_type_name(constant), ZSTR_VAL(c->ce->name), ZSTR_VAL(name), ZSTR_VAL(type_str));
845
846
0
  zend_string_release(type_str);
847
0
}
848
849
ZEND_COLD zend_never_inline void zend_verify_property_type_error(const zend_property_info *info, const zval *property)
850
0
{
851
0
  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
0
  if (EG(exception)) {
855
0
    return;
856
0
  }
857
858
0
  type_str = zend_type_to_string(info->type);
859
0
  zend_type_error("Cannot assign %s to property %s::$%s of type %s",
860
0
    zend_zval_value_name(property),
861
0
    ZSTR_VAL(info->ce->name),
862
0
    zend_get_unmangled_property_name(info->name),
863
0
    ZSTR_VAL(type_str));
864
0
  zend_string_release(type_str);
865
0
}
866
867
ZEND_COLD zend_never_inline void zend_magic_get_property_type_inconsistency_error(const zend_property_info *info, const zval *property)
868
0
{
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
0
  if (EG(exception)) {
871
0
    return;
872
0
  }
873
874
0
  zend_string *type_str = zend_type_to_string(info->type);
875
0
  zend_type_error("Value of type %s returned from %s::__get() must be compatible with unset property %s::$%s of type %s",
876
0
    zend_zval_type_name(property),
877
0
    ZSTR_VAL(info->ce->name),
878
0
    ZSTR_VAL(info->ce->name),
879
0
    zend_get_unmangled_property_name(info->name),
880
0
    ZSTR_VAL(type_str));
881
0
  zend_string_release(type_str);
882
0
}
883
884
ZEND_COLD void zend_match_unhandled_error(const zval *value)
885
0
{
886
0
  zend_long max_len = EG(exception_string_param_max_len);
887
0
  smart_str msg = {0};
888
0
  if (
889
0
    EG(exception_ignore_args)
890
0
    || (Z_TYPE_P(value) == IS_STRING && max_len == 0)
891
0
    || smart_str_append_zval(&msg, value, max_len) != SUCCESS
892
0
  ) {
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
0
  smart_str_0(&msg);
897
898
0
  zend_throw_exception_ex(
899
0
    zend_ce_unhandled_match_error, 0, "Unhandled match case %s", ZSTR_VAL(msg.s));
900
901
0
  smart_str_free(&msg);
902
0
}
903
904
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(
905
0
    const zend_property_info *info) {
906
0
  zend_readonly_property_modification_error_ex(
907
0
    ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
908
0
}
909
910
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(
911
0
    const char *class_name, const char *prop_name) {
912
0
  zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", class_name, prop_name);
913
0
}
914
915
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info)
916
0
{
917
0
  zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s",
918
0
    ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
919
0
}
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
0
{
928
0
  zend_throw_error(NULL, "Object was released while assigning to property %s::$%s",
929
0
    ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
930
0
}
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
0
) {
935
0
  const zend_class_entry *scope;
936
0
  if (EG(fake_scope)) {
937
0
    scope = EG(fake_scope);
938
0
  } else {
939
0
    scope = zend_get_called_scope(EG(current_execute_data));
940
0
  }
941
942
0
  const char *visibility;
943
0
  if (prop_info->flags & ZEND_ACC_PRIVATE_SET) {
944
0
    visibility = "private(set)";
945
0
  } else {
946
0
    ZEND_ASSERT(prop_info->flags & ZEND_ACC_PROTECTED_SET);
947
0
    if (prop_info->flags & ZEND_ACC_READONLY) {
948
0
      visibility = "protected(set) readonly";
949
0
    } else {
950
0
      visibility = "protected(set)";
951
0
    }
952
0
  }
953
954
0
  zend_throw_error(NULL, "Cannot %s %s property %s::$%s from %s%s",
955
0
    operation,
956
0
    visibility,
957
0
    ZSTR_VAL(prop_info->ce->name),
958
0
    ZSTR_VAL(prop_info->name),
959
0
    scope ? "scope " : "global scope", scope ? ZSTR_VAL(scope->name) : "");
960
0
}
961
962
0
static const zend_class_entry *resolve_single_class_type(zend_string *name, const zend_class_entry *self_ce) {
963
0
  if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) {
964
0
    return self_ce;
965
0
  } else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
966
0
    return self_ce->parent;
967
0
  } else {
968
0
    return zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
969
0
  }
970
0
}
971
972
static zend_always_inline const zend_class_entry *zend_ce_from_type(
973
18
    const zend_class_entry *scope, const zend_type *type) {
974
18
  ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type));
975
18
  zend_string *name = ZEND_TYPE_NAME(*type);
976
18
  if (ZSTR_HAS_CE_CACHE(name)) {
977
18
    zend_class_entry *ce = ZSTR_GET_CE_CACHE(name);
978
18
    if (!ce) {
979
18
      ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
980
18
    }
981
18
    return ce;
982
18
  }
983
0
  return resolve_single_class_type(name, scope);
984
18
}
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
0
{
989
0
  const zend_type *list_type;
990
991
0
  ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
992
0
    ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
993
0
    const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
994
0
    if (!ce || !instanceof_function(value_ce, ce)) {
995
0
      return false;
996
0
    }
997
0
  } ZEND_TYPE_LIST_FOREACH_END();
998
0
  return true;
999
0
}
1000
1001
static bool zend_check_and_resolve_property_or_class_constant_class_type(
1002
18
  const zend_class_entry *scope, const zend_type member_type, const zend_class_entry *value_ce) {
1003
18
  if (ZEND_TYPE_HAS_LIST(member_type)) {
1004
0
    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
0
    } else {
1008
0
      const zend_type *list_type;
1009
0
      ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(member_type), list_type) {
1010
0
        if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
1011
0
          if (zend_check_intersection_for_property_or_class_constant_class_type(
1012
0
              scope, ZEND_TYPE_LIST(*list_type), value_ce)) {
1013
0
            return true;
1014
0
          }
1015
0
          continue;
1016
0
        }
1017
0
        ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
1018
0
        const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
1019
0
        if (ce && instanceof_function(value_ce, ce)) {
1020
0
          return true;
1021
0
        }
1022
0
      } ZEND_TYPE_LIST_FOREACH_END();
1023
1024
0
      if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC)) {
1025
0
        return value_ce == scope;
1026
0
      }
1027
1028
0
      return false;
1029
0
    }
1030
18
  } else if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC) && value_ce == scope) {
1031
0
    return true;
1032
18
  } else if (ZEND_TYPE_HAS_NAME(member_type)) {
1033
18
    const zend_class_entry *ce = zend_ce_from_type(scope, &member_type);
1034
18
    return ce && instanceof_function(value_ce, ce);
1035
18
  }
1036
1037
0
  return false;
1038
18
}
1039
1040
static zend_always_inline bool i_zend_check_property_type(const zend_property_info *info, zval *property, bool strict)
1041
18
{
1042
18
  ZEND_ASSERT(!Z_ISREF_P(property));
1043
18
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) {
1044
0
    return 1;
1045
0
  }
1046
1047
18
  if (ZEND_TYPE_IS_COMPLEX(info->type) && Z_TYPE_P(property) == IS_OBJECT
1048
18
      && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(property))) {
1049
18
    return 1;
1050
18
  }
1051
1052
0
  uint32_t type_mask = ZEND_TYPE_FULL_MASK(info->type);
1053
0
  ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC|MAY_BE_NEVER|MAY_BE_VOID)));
1054
0
  return zend_verify_scalar_type_hint(type_mask, property, strict, false);
1055
0
}
1056
1057
static zend_always_inline bool i_zend_verify_property_type(const zend_property_info *info, zval *property, bool strict)
1058
18
{
1059
18
  if (i_zend_check_property_type(info, property, strict)) {
1060
18
    return 1;
1061
18
  }
1062
1063
0
  zend_verify_property_type_error(info, property);
1064
0
  return 0;
1065
18
}
1066
1067
18
ZEND_API bool zend_never_inline zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) {
1068
18
  return i_zend_verify_property_type(info, property, strict);
1069
18
}
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
0
{
1073
0
  zval tmp;
1074
1075
0
  if (UNEXPECTED(info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) {
1076
0
    if ((info->flags & ZEND_ACC_READONLY) && !(Z_PROP_FLAG_P(property_val) & IS_PROP_REINITABLE)) {
1077
0
      zend_readonly_property_modification_error(info);
1078
0
      return &EG(uninitialized_zval);
1079
0
    }
1080
0
    if (info->flags & ZEND_ACC_PPP_SET_MASK && !zend_asymmetric_property_has_set_access(info)) {
1081
0
      zend_asymmetric_visibility_property_modification_error(info, "modify");
1082
0
      return &EG(uninitialized_zval);
1083
0
    }
1084
0
  }
1085
1086
0
  ZVAL_DEREF(value);
1087
0
  ZVAL_COPY(&tmp, value);
1088
1089
0
  if (UNEXPECTED(!i_zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) {
1090
0
    zval_ptr_dtor(&tmp);
1091
0
    return &EG(uninitialized_zval);
1092
0
  }
1093
1094
0
  Z_PROP_FLAG_P(property_val) &= ~IS_PROP_REINITABLE;
1095
1096
0
  return zend_assign_to_variable_ex(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr);
1097
0
}
1098
1099
0
static zend_always_inline bool zend_value_instanceof_static(const zval *zv) {
1100
0
  if (Z_TYPE_P(zv) != IS_OBJECT) {
1101
0
    return 0;
1102
0
  }
1103
1104
0
  zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
1105
0
  if (!called_scope) {
1106
0
    return 0;
1107
0
  }
1108
0
  return instanceof_function(Z_OBJCE_P(zv), called_scope);
1109
0
}
1110
1111
static zend_always_inline zend_class_entry *zend_fetch_ce_from_type(
1112
    const zend_type *type)
1113
0
{
1114
0
  zend_string *name = ZEND_TYPE_NAME(*type);
1115
0
  zend_class_entry *ce;
1116
0
  if (ZSTR_HAS_CE_CACHE(name)) {
1117
0
    ce = ZSTR_GET_CE_CACHE(name);
1118
0
    if (!ce) {
1119
0
      ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
1120
0
      if (UNEXPECTED(!ce)) {
1121
        /* Cannot resolve */
1122
0
        return NULL;
1123
0
      }
1124
0
    }
1125
0
  } else {
1126
0
    ce = zend_fetch_class(name,
1127
0
      ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT);
1128
0
    if (UNEXPECTED(!ce)) {
1129
0
      return NULL;
1130
0
    }
1131
0
  }
1132
0
  return ce;
1133
0
}
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
0
{
1139
0
  zend_class_entry *ce;
1140
0
  const zend_type *list_type;
1141
0
  ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
1142
0
    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
0
    if (!ce || !instanceof_function(arg_ce, ce)) {
1146
0
      return false;
1147
0
    }
1148
0
  } ZEND_TYPE_LIST_FOREACH_END();
1149
0
  return true;
1150
0
}
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
0
{
1156
0
  if (ZEND_TYPE_IS_COMPLEX(*type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
1157
0
    zend_class_entry *ce;
1158
0
    if (UNEXPECTED(ZEND_TYPE_HAS_LIST(*type))) {
1159
0
      if (ZEND_TYPE_IS_INTERSECTION(*type)) {
1160
0
        return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), Z_OBJCE_P(arg));
1161
0
      } else {
1162
0
        const zend_type *list_type;
1163
0
        ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) {
1164
0
          if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
1165
0
            if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), Z_OBJCE_P(arg))) {
1166
0
              return true;
1167
0
            }
1168
0
          } else {
1169
0
            ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
1170
0
            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
0
            if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) {
1173
0
              return true;
1174
0
            }
1175
0
          }
1176
0
        } ZEND_TYPE_LIST_FOREACH_END();
1177
0
      }
1178
0
    } else {
1179
0
      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
0
      if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) {
1183
0
        return true;
1184
0
      }
1185
0
    }
1186
0
  }
1187
1188
0
  const uint32_t type_mask = ZEND_TYPE_FULL_MASK(*type);
1189
0
  if ((type_mask & MAY_BE_CALLABLE) &&
1190
0
    zend_is_callable(arg, is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0, NULL)) {
1191
0
    return 1;
1192
0
  }
1193
0
  if ((type_mask & MAY_BE_STATIC) && zend_value_instanceof_static(arg)) {
1194
0
    return 1;
1195
0
  }
1196
0
  if (ref && ZEND_REF_HAS_TYPE_SOURCES(ref)) {
1197
    /* We cannot have conversions for typed refs. */
1198
0
    return 0;
1199
0
  }
1200
0
  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
0
  return zend_verify_scalar_type_hint(type_mask, arg,
1208
0
    is_return_type ? ZEND_RET_USES_STRICT_TYPES() : ZEND_ARG_USES_STRICT_TYPES(),
1209
0
    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
0
}
1214
1215
static zend_always_inline bool zend_check_type(
1216
    const zend_type *type, zval *arg, bool is_return_type, bool is_internal)
1217
0
{
1218
0
  const zend_reference *ref = NULL;
1219
0
  ZEND_ASSERT(ZEND_TYPE_IS_SET(*type));
1220
1221
0
  if (UNEXPECTED(Z_ISREF_P(arg))) {
1222
0
    ref = Z_REF_P(arg);
1223
0
    arg = Z_REFVAL_P(arg);
1224
0
  }
1225
1226
0
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(*type, Z_TYPE_P(arg)))) {
1227
0
    return 1;
1228
0
  }
1229
1230
0
  return zend_check_type_slow(type, arg, ref, is_return_type, is_internal);
1231
0
}
1232
1233
ZEND_API bool zend_check_user_type_slow(
1234
    const zend_type *type, zval *arg, const zend_reference *ref, bool is_return_type)
1235
0
{
1236
0
  return zend_check_type_slow(
1237
0
    type, arg, ref, is_return_type, /* is_internal */ false);
1238
0
}
1239
1240
static zend_always_inline bool zend_verify_recv_arg_type(const zend_function *zf, uint32_t arg_num, zval *arg)
1241
0
{
1242
0
  const zend_arg_info *cur_arg_info;
1243
1244
0
  ZEND_ASSERT(arg_num <= zf->common.num_args);
1245
0
  cur_arg_info = &zf->common.arg_info[arg_num-1];
1246
1247
0
  if (ZEND_TYPE_IS_SET(cur_arg_info->type)
1248
0
      && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, false, false))) {
1249
0
    zend_verify_arg_error(zf, cur_arg_info, arg_num, arg);
1250
0
    return 0;
1251
0
  }
1252
1253
0
  return 1;
1254
0
}
1255
1256
static zend_always_inline bool zend_verify_variadic_arg_type(
1257
    const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, zval *arg)
1258
0
{
1259
0
  ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type));
1260
0
  if (UNEXPECTED(!zend_check_type(&arg_info->type, arg, false, false))) {
1261
0
    zend_verify_arg_error(zf, arg_info, arg_num, arg);
1262
0
    return 0;
1263
0
  }
1264
1265
0
  return 1;
1266
0
}
1267
1268
static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_types(const zend_function *fbc, zend_execute_data *call)
1269
0
{
1270
0
  uint32_t i;
1271
0
  uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
1272
0
  zval *arg = ZEND_CALL_ARG(call, 1);
1273
1274
0
  for (i = 0; i < num_args; ++i) {
1275
0
    zend_arg_info *cur_arg_info;
1276
0
    if (EXPECTED(i < fbc->common.num_args)) {
1277
0
      cur_arg_info = &fbc->common.arg_info[i];
1278
0
    } else if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) {
1279
0
      cur_arg_info = &fbc->common.arg_info[fbc->common.num_args];
1280
0
    } else {
1281
0
      break;
1282
0
    }
1283
1284
0
    if (ZEND_TYPE_IS_SET(cur_arg_info->type)
1285
0
        && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, false, /* is_internal */ true))) {
1286
0
      return 0;
1287
0
    }
1288
0
    arg++;
1289
0
  }
1290
0
  return 1;
1291
0
}
1292
1293
#if ZEND_DEBUG
1294
/* Determine whether an internal call should throw, because the passed arguments violate
1295
 * an arginfo constraint. This is only checked in debug builds. In release builds, we
1296
 * trust that arginfo matches what is enforced by zend_parse_parameters. */
1297
ZEND_API bool zend_internal_call_should_throw(const zend_function *fbc, zend_execute_data *call)
1298
0
{
1299
0
  if (fbc->internal_function.handler == ZEND_FN(pass) || (fbc->internal_function.fn_flags & ZEND_ACC_FAKE_CLOSURE)) {
1300
    /* Be lenient about the special pass function and about fake closures. */
1301
0
    return 0;
1302
0
  }
1303
1304
0
  if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) {
1305
    /* Required argument not passed. */
1306
0
    return 1;
1307
0
  }
1308
1309
0
  if (fbc->common.num_args < ZEND_CALL_NUM_ARGS(call)
1310
0
      && !(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) {
1311
    /* Too many arguments passed. For internal functions (unlike userland functions),
1312
     * this should always throw. */
1313
0
    return 1;
1314
0
  }
1315
1316
0
  if ((fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) &&
1317
0
      !zend_verify_internal_arg_types(fbc, call)) {
1318
0
    zend_clear_exception();
1319
0
    return 1;
1320
0
  }
1321
1322
0
  return 0;
1323
0
}
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
0
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
0
}
1394
#endif
1395
1396
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(const zend_execute_data *execute_data)
1397
0
{
1398
0
  const zend_execute_data *ptr = EX(prev_execute_data);
1399
1400
0
  if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
1401
0
    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
0
      EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "",
1403
0
      EX(func)->common.scope ? "::" : "",
1404
0
      ZSTR_VAL(EX(func)->common.function_name),
1405
0
      EX_NUM_ARGS(),
1406
0
      ZSTR_VAL(ptr->func->op_array.filename),
1407
0
      ptr->opline->lineno,
1408
0
      EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least",
1409
0
      EX(func)->common.required_num_args);
1410
0
  } 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
0
}
1420
1421
ZEND_API ZEND_COLD void zend_verify_return_error(const zend_function *zf, const zval *value)
1422
0
{
1423
0
  const zend_arg_info *arg_info = &zf->common.arg_info[-1];
1424
0
  const char *fname, *fsep, *fclass;
1425
0
  zend_string *need_msg;
1426
0
  const char *given_msg;
1427
1428
0
  zend_verify_type_error_common(
1429
0
    zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);
1430
1431
0
  zend_type_error("%s%s%s(): Return value must be of type %s, %s returned",
1432
0
    fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg);
1433
1434
0
  zend_string_release(need_msg);
1435
0
}
1436
1437
ZEND_API ZEND_COLD void zend_verify_never_error(const zend_function *zf)
1438
0
{
1439
0
  zend_string *func_name = get_function_or_method_name(zf);
1440
1441
0
  zend_type_error("%s(): never-returning %s must not implicitly return",
1442
0
    ZSTR_VAL(func_name), zf->common.scope ? "method" : "function");
1443
1444
0
  zend_string_release(func_name);
1445
0
}
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
0
{
1482
0
  const zend_arg_info *ret_info = zf->internal_function.arg_info - 1;
1483
1484
0
  if (ZEND_TYPE_FULL_MASK(ret_info->type) & MAY_BE_VOID) {
1485
0
    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
0
    return 1;
1490
0
  }
1491
1492
0
  if (UNEXPECTED(!zend_check_type(&ret_info->type, ret, true, /* is_internal */ true))) {
1493
0
    zend_verify_internal_return_error(zf, ret);
1494
0
    return 0;
1495
0
  }
1496
1497
0
  return 1;
1498
0
}
1499
#endif
1500
1501
static ZEND_COLD void zend_verify_missing_return_type(const zend_function *zf)
1502
0
{
1503
  /* VERIFY_RETURN_TYPE is not emitted for "void" functions, so this is always an error. */
1504
0
  zend_verify_return_error(zf, NULL);
1505
0
}
1506
1507
static zend_always_inline bool zend_check_class_constant_type(const zend_class_constant *c, zval *constant)
1508
0
{
1509
0
  ZEND_ASSERT(!Z_ISREF_P(constant));
1510
0
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(c->type, Z_TYPE_P(constant)))) {
1511
0
    return 1;
1512
0
  }
1513
1514
0
  if (((ZEND_TYPE_PURE_MASK(c->type) & MAY_BE_STATIC) || ZEND_TYPE_IS_COMPLEX(c->type)) && Z_TYPE_P(constant) == IS_OBJECT
1515
0
    && zend_check_and_resolve_property_or_class_constant_class_type(c->ce, c->type, Z_OBJCE_P(constant))) {
1516
0
    return 1;
1517
0
  }
1518
1519
0
  uint32_t type_mask = ZEND_TYPE_FULL_MASK(c->type);
1520
0
  ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_NEVER|MAY_BE_VOID)));
1521
0
  return zend_verify_scalar_type_hint(type_mask, constant, true, false);
1522
0
}
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
0
{
1526
0
  if (!zend_check_class_constant_type(c, constant)) {
1527
0
    zend_verify_class_constant_type_error(c, name, constant);
1528
0
    return 0;
1529
0
  }
1530
1531
0
  return 1;
1532
0
}
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
0
{
1541
0
  zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_RW);
1542
0
}
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
0
{
1556
0
  zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, type);
1557
0
}
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
0
{
1561
0
  obj->handlers->write_dimension(obj, dim, value);
1562
1563
0
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1564
0
    ZVAL_COPY(EX_VAR(opline->result.var), value);
1565
0
  }
1566
0
}
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
0
{
1618
0
  static const binary_op_type zend_binary_ops[] = {
1619
0
    add_function,
1620
0
    sub_function,
1621
0
    mul_function,
1622
0
    div_function,
1623
0
    mod_function,
1624
0
    shift_left_function,
1625
0
    shift_right_function,
1626
0
    concat_function,
1627
0
    bitwise_or_function,
1628
0
    bitwise_and_function,
1629
0
    bitwise_xor_function,
1630
0
    pow_function
1631
0
  };
1632
  /* size_t cast makes GCC to better optimize 64-bit PIC code */
1633
0
  size_t opcode = (size_t)opline->extended_value;
1634
1635
0
  return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2);
1636
0
}
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
0
{
1675
0
  zval z_copy;
1676
1677
  /* Make sure that in-place concatenation is used if the LHS is a string. */
1678
0
  if (opline->extended_value == ZEND_CONCAT && Z_TYPE(ref->val) == IS_STRING) {
1679
0
    concat_function(&ref->val, &ref->val, value);
1680
0
    ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string");
1681
0
    return;
1682
0
  }
1683
1684
0
  zend_binary_op(&z_copy, &ref->val, value OPLINE_CC);
1685
0
  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
0
  } else {
1689
0
    zval_ptr_dtor(&z_copy);
1690
0
  }
1691
0
}
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
0
{
1695
0
  zval z_copy;
1696
1697
  /* Make sure that in-place concatenation is used if the LHS is a string. */
1698
0
  if (opline->extended_value == ZEND_CONCAT && Z_TYPE_P(zptr) == IS_STRING) {
1699
0
    concat_function(zptr, zptr, value);
1700
0
    ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string");
1701
0
    return;
1702
0
  }
1703
1704
0
  zend_binary_op(&z_copy, zptr, value OPLINE_CC);
1705
0
  if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
1706
0
    zval_ptr_dtor(zptr);
1707
0
    ZVAL_COPY_VALUE(zptr, &z_copy);
1708
0
  } else {
1709
0
    zval_ptr_dtor(&z_copy);
1710
0
  }
1711
0
}
1712
1713
static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type EXECUTE_DATA_DC)
1714
0
{
1715
0
  zend_long offset;
1716
1717
0
try_again:
1718
0
  switch(Z_TYPE_P(dim)) {
1719
0
    case IS_LONG:
1720
0
      return Z_LVAL_P(dim);
1721
0
    case IS_STRING:
1722
0
    {
1723
0
      bool trailing_data = false;
1724
      /* For BC reasons we allow errors so that we can warn on leading numeric string */
1725
0
      if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
1726
0
          /* allow errors */ true, NULL, &trailing_data)) {
1727
0
        if (UNEXPECTED(trailing_data) && type != BP_VAR_UNSET) {
1728
0
          zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
1729
0
        }
1730
0
        return offset;
1731
0
      }
1732
0
      zend_illegal_string_offset(dim, type);
1733
0
      return 0;
1734
0
    }
1735
0
    case IS_DOUBLE:
1736
      /* Suppress potential double warning */
1737
0
      zend_error(E_WARNING, "String offset cast occurred");
1738
0
      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
0
    case IS_NULL:
1743
0
    case IS_FALSE:
1744
0
    case IS_TRUE:
1745
0
      zend_error(E_WARNING, "String offset cast occurred");
1746
0
      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
0
  }
1754
1755
0
  return zval_get_long_func(dim, /* is_strict */ false);
1756
0
}
1757
1758
ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void)
1759
0
{
1760
0
  const char *msg = NULL;
1761
0
  const zend_execute_data *execute_data = EG(current_execute_data);
1762
0
  const zend_op *opline = execute_data->opline;
1763
1764
0
  if (UNEXPECTED(EG(exception) != NULL)) {
1765
0
    return;
1766
0
  }
1767
1768
0
  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
0
    case ZEND_FETCH_LIST_W:
1773
0
      msg = "Cannot create references to/from string offsets";
1774
0
      break;
1775
0
    case ZEND_FETCH_DIM_W:
1776
0
    case ZEND_FETCH_DIM_RW:
1777
0
    case ZEND_FETCH_DIM_FUNC_ARG:
1778
0
    case ZEND_FETCH_DIM_UNSET:
1779
0
      switch (opline->extended_value) {
1780
0
        case ZEND_FETCH_DIM_REF:
1781
0
          msg = "Cannot create references to/from string offsets";
1782
0
          break;
1783
0
        case ZEND_FETCH_DIM_DIM:
1784
0
          msg = "Cannot use string offset as an array";
1785
0
          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
0
      }
1794
0
      break;
1795
0
    EMPTY_SWITCH_DEFAULT_CASE();
1796
0
  }
1797
0
  ZEND_ASSERT(msg != NULL);
1798
0
  zend_throw_error(NULL, "%s", msg);
1799
0
}
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
0
{
1803
0
  *message_suffix = ZSTR_EMPTY_ALLOC();
1804
1805
0
  if (!attributes) {
1806
0
    return SUCCESS;
1807
0
  }
1808
1809
0
  zend_attribute *deprecated = zend_get_attribute_str(attributes, "deprecated", sizeof("deprecated")-1);
1810
1811
0
  if (!deprecated) {
1812
0
    return SUCCESS;
1813
0
  }
1814
1815
0
  if (deprecated->argc == 0) {
1816
0
    return SUCCESS;
1817
0
  }
1818
1819
0
  zend_result result = FAILURE;
1820
1821
0
  zend_string *message = ZSTR_EMPTY_ALLOC();
1822
0
  zend_string *since = ZSTR_EMPTY_ALLOC();
1823
1824
0
  zval obj;
1825
0
  ZVAL_UNDEF(&obj);
1826
0
  zval *z;
1827
1828
  /* Construct the Deprecated object to correctly handle parameter processing. */
1829
0
  if (FAILURE == zend_get_attribute_object(&obj, zend_ce_deprecated, deprecated, scope, NULL)) {
1830
0
    goto out;
1831
0
  }
1832
1833
  /* Extract the $message property. */
1834
0
  z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL);
1835
0
  ZEND_ASSERT(z != &EG(uninitialized_zval));
1836
0
  if (Z_TYPE_P(z) == IS_STRING) {
1837
0
    message = Z_STR_P(z);
1838
0
  }
1839
1840
  /* Extract the $since property. */
1841
0
  z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_SINCE), false, NULL);
1842
0
  ZEND_ASSERT(z != &EG(uninitialized_zval));
1843
0
  if (Z_TYPE_P(z) == IS_STRING) {
1844
0
    since = Z_STR_P(z);
1845
0
  }
1846
1847
  /* Construct the suffix. */
1848
0
  *message_suffix = zend_strpprintf_unchecked(
1849
0
    0,
1850
0
    "%s%S%s%S",
1851
0
    ZSTR_LEN(since) > 0 ? " since " : "",
1852
0
    since,
1853
0
    ZSTR_LEN(message) > 0 ? ", " : "",
1854
0
    message
1855
0
  );
1856
1857
0
  result = SUCCESS;
1858
1859
0
 out:
1860
1861
0
  zval_ptr_dtor(&obj);
1862
1863
0
  return result;
1864
0
}
1865
1866
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
1867
0
{
1868
0
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1869
1870
0
  if (get_deprecation_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) {
1871
0
    return;
1872
0
  }
1873
1874
0
  int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_DEPRECATED : E_USER_DEPRECATED;
1875
1876
0
  if (fbc->common.scope) {
1877
0
    zend_error_unchecked(code, "Method %s::%s() is deprecated%S",
1878
0
      ZSTR_VAL(fbc->common.scope->name),
1879
0
      ZSTR_VAL(fbc->common.function_name),
1880
0
      message_suffix
1881
0
    );
1882
0
  } else {
1883
0
    zend_error_unchecked(code, "Function %s() is deprecated%S",
1884
0
      ZSTR_VAL(fbc->common.function_name),
1885
0
      message_suffix
1886
0
    );
1887
0
  }
1888
1889
0
  zend_string_release(message_suffix);
1890
0
}
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
0
{
1894
0
  *message_suffix = ZSTR_EMPTY_ALLOC();
1895
1896
0
  if (!attributes) {
1897
0
    return SUCCESS;
1898
0
  }
1899
1900
0
  zend_attribute *nodiscard = zend_get_attribute_str(attributes, "nodiscard", sizeof("nodiscard")-1);
1901
1902
0
  if (!nodiscard) {
1903
0
    return SUCCESS;
1904
0
  }
1905
1906
0
  if (nodiscard->argc == 0) {
1907
0
    return SUCCESS;
1908
0
  }
1909
1910
0
  zend_result result = FAILURE;
1911
1912
0
  zend_string *message = ZSTR_EMPTY_ALLOC();
1913
1914
0
  zval obj;
1915
0
  ZVAL_UNDEF(&obj);
1916
0
  zval *z;
1917
1918
  /* Construct the NoDiscard object to correctly handle parameter processing. */
1919
0
  if (FAILURE == zend_get_attribute_object(&obj, zend_ce_nodiscard, nodiscard, scope, NULL)) {
1920
0
    goto out;
1921
0
  }
1922
1923
  /* Extract the $message property. */
1924
0
  z = zend_read_property_ex(zend_ce_nodiscard, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL);
1925
0
  ZEND_ASSERT(z != &EG(uninitialized_zval));
1926
0
  if (Z_TYPE_P(z) == IS_STRING) {
1927
0
    message = Z_STR_P(z);
1928
0
  }
1929
1930
  /* Construct the suffix. */
1931
0
  *message_suffix = zend_strpprintf_unchecked(
1932
0
    0,
1933
0
    "%s%S",
1934
0
    ZSTR_LEN(message) > 0 ? ", " : "",
1935
0
    message
1936
0
  );
1937
1938
0
  result = SUCCESS;
1939
1940
0
 out:
1941
1942
0
  zval_ptr_dtor(&obj);
1943
1944
0
  return result;
1945
0
}
1946
1947
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_nodiscard_function(const zend_function *fbc)
1948
0
{
1949
0
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1950
1951
0
  if (get_nodiscard_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) {
1952
0
    return;
1953
0
  }
1954
1955
0
  int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_WARNING : E_USER_WARNING;
1956
1957
0
  if (fbc->common.scope) {
1958
0
    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
0
      ZSTR_VAL(fbc->common.scope->name),
1960
0
      ZSTR_VAL(fbc->common.function_name),
1961
0
      message_suffix
1962
0
    );
1963
0
  } else {
1964
0
    zend_error_unchecked(code, "The return value of function %s() should either be used or intentionally ignored by casting it as (void)%S",
1965
0
      ZSTR_VAL(fbc->common.function_name),
1966
0
      message_suffix
1967
0
    );
1968
0
  }
1969
1970
0
  zend_string_release(message_suffix);
1971
0
}
1972
1973
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_class_constant(const zend_class_constant *c, const zend_string *constant_name)
1974
0
{
1975
0
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1976
1977
0
  if (get_deprecation_suffix_from_attribute(c->attributes, c->ce, &message_suffix) == FAILURE) {
1978
0
    return;
1979
0
  }
1980
1981
0
  int code = c->ce->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED;
1982
0
  char *type = (ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE) ? "Enum case" : "Constant";
1983
1984
0
  zend_error_unchecked(code, "%s %s::%s is deprecated%S",
1985
0
    type,
1986
0
    ZSTR_VAL(c->ce->name),
1987
0
    ZSTR_VAL(constant_name),
1988
0
    message_suffix
1989
0
  );
1990
1991
0
  zend_string_release(message_suffix);
1992
0
}
1993
1994
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_constant(const zend_constant *c, const zend_string *constant_name)
1995
0
{
1996
0
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1997
1998
0
  if (get_deprecation_suffix_from_attribute(c->attributes, NULL, &message_suffix) == FAILURE) {
1999
0
    return;
2000
0
  }
2001
2002
0
  int code = ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT ? E_USER_DEPRECATED : E_DEPRECATED;
2003
2004
0
  zend_error_unchecked(code, "Constant %s is deprecated%S",
2005
0
    ZSTR_VAL(constant_name),
2006
0
    message_suffix
2007
0
  );
2008
2009
0
  zend_string_release(message_suffix);
2010
0
}
2011
2012
ZEND_API ZEND_COLD void zend_use_of_deprecated_trait(
2013
  zend_class_entry *trait,
2014
  const zend_string *used_by
2015
0
) {
2016
0
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
2017
2018
0
  if (get_deprecation_suffix_from_attribute(trait->attributes, trait, &message_suffix) == FAILURE) {
2019
0
    return;
2020
0
  }
2021
2022
0
  int code = trait->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED;
2023
2024
0
  zend_error_unchecked(code, "Trait %s used by %s is deprecated%S",
2025
0
    ZSTR_VAL(trait->name),
2026
0
    ZSTR_VAL(used_by),
2027
0
    message_suffix
2028
0
  );
2029
2030
0
  zend_string_release(message_suffix);
2031
0
}
2032
2033
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void)
2034
0
{
2035
0
  zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
2036
0
}
2037
2038
static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)
2039
0
{
2040
0
  zend_uchar c;
2041
0
  size_t string_len;
2042
0
  zend_long offset;
2043
0
  zend_string *s;
2044
2045
  /* separate string */
2046
0
  if (Z_REFCOUNTED_P(str) && Z_REFCOUNT_P(str) == 1) {
2047
0
    s = Z_STR_P(str);
2048
0
  } else {
2049
0
    s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
2050
0
    ZSTR_H(s) = ZSTR_H(Z_STR_P(str));
2051
0
    if (Z_REFCOUNTED_P(str)) {
2052
0
      GC_DELREF(Z_STR_P(str));
2053
0
    }
2054
0
    ZVAL_NEW_STR(str, s);
2055
0
  }
2056
2057
0
  if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
2058
0
    offset = Z_LVAL_P(dim);
2059
0
  } else {
2060
    /* The string may be destroyed while throwing the notice.
2061
     * Temporarily increase the refcount to detect this situation. */
2062
0
    GC_ADDREF(s);
2063
0
    offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC);
2064
0
    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
0
    if (UNEXPECTED(EG(exception) != NULL)) {
2073
0
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2074
0
        ZVAL_UNDEF(EX_VAR(opline->result.var));
2075
0
      }
2076
0
      return;
2077
0
    }
2078
0
  }
2079
2080
0
  if (UNEXPECTED(offset < -(zend_long)ZSTR_LEN(s))) {
2081
    /* Error on negative offset */
2082
0
    zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);
2083
0
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2084
0
      ZVAL_NULL(EX_VAR(opline->result.var));
2085
0
    }
2086
0
    return;
2087
0
  }
2088
2089
0
  if (offset < 0) { /* Handle negative offset */
2090
0
    offset += (zend_long)ZSTR_LEN(s);
2091
0
  }
2092
2093
0
  if (UNEXPECTED(Z_TYPE_P(value) != IS_STRING)) {
2094
0
    zend_string *tmp;
2095
2096
    /* The string may be destroyed while throwing the notice.
2097
     * Temporarily increase the refcount to detect this situation. */
2098
0
    GC_ADDREF(s);
2099
0
    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
0
    tmp = zval_try_get_string_func(value);
2104
0
    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
0
    if (UNEXPECTED(!tmp)) {
2115
0
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2116
0
        ZVAL_UNDEF(EX_VAR(opline->result.var));
2117
0
      }
2118
0
      return;
2119
0
    }
2120
2121
0
    string_len = ZSTR_LEN(tmp);
2122
0
    c = (zend_uchar)ZSTR_VAL(tmp)[0];
2123
0
    zend_string_release_ex(tmp, 0);
2124
0
  } else {
2125
0
    string_len = Z_STRLEN_P(value);
2126
0
    c = (zend_uchar)Z_STRVAL_P(value)[0];
2127
0
  }
2128
2129
0
  if (UNEXPECTED(string_len != 1)) {
2130
0
    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
0
    GC_ADDREF(s);
2142
0
    zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
2143
0
    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
0
    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
0
  }
2158
2159
0
  if ((size_t)offset >= ZSTR_LEN(s)) {
2160
    /* Extend string if needed */
2161
0
    zend_long old_len = ZSTR_LEN(s);
2162
0
    ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0));
2163
0
    memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
2164
0
    Z_STRVAL_P(str)[offset+1] = 0;
2165
0
  } else {
2166
0
    zend_string_forget_hash_val(Z_STR_P(str));
2167
0
  }
2168
2169
0
  Z_STRVAL_P(str)[offset] = c;
2170
2171
0
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2172
    /* Return the new character */
2173
0
    ZVAL_CHAR(EX_VAR(opline->result.var), c);
2174
0
  }
2175
0
}
2176
2177
static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *ref)
2178
0
{
2179
0
  zend_property_info *prop;
2180
0
  ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
2181
0
    if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) {
2182
0
      return prop;
2183
0
    }
2184
0
  } ZEND_REF_FOREACH_TYPE_SOURCES_END();
2185
0
  return NULL;
2186
0
}
2187
2188
static ZEND_COLD zend_long zend_throw_incdec_ref_error(
2189
    zend_reference *ref, zend_property_info *error_prop OPLINE_DC)
2190
0
{
2191
0
  zend_string *type_str = zend_type_to_string(error_prop->type);
2192
0
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2193
0
    zend_type_error(
2194
0
      "Cannot increment a reference held by property %s::$%s of type %s past its maximal value",
2195
0
      ZSTR_VAL(error_prop->ce->name),
2196
0
      zend_get_unmangled_property_name(error_prop->name),
2197
0
      ZSTR_VAL(type_str));
2198
0
    zend_string_release(type_str);
2199
0
    return ZEND_LONG_MAX;
2200
0
  } else {
2201
0
    zend_type_error(
2202
0
      "Cannot decrement a reference held by property %s::$%s of type %s past its minimal value",
2203
0
      ZSTR_VAL(error_prop->ce->name),
2204
0
      zend_get_unmangled_property_name(error_prop->name),
2205
0
      ZSTR_VAL(type_str));
2206
0
    zend_string_release(type_str);
2207
0
    return ZEND_LONG_MIN;
2208
0
  }
2209
0
}
2210
2211
0
static ZEND_COLD zend_long zend_throw_incdec_prop_error(zend_property_info *prop OPLINE_DC) {
2212
0
  zend_string *type_str = zend_type_to_string(prop->type);
2213
0
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2214
0
    zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value",
2215
0
      ZSTR_VAL(prop->ce->name),
2216
0
      zend_get_unmangled_property_name(prop->name),
2217
0
      ZSTR_VAL(type_str));
2218
0
    zend_string_release(type_str);
2219
0
    return ZEND_LONG_MAX;
2220
0
  } else {
2221
0
    zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value",
2222
0
      ZSTR_VAL(prop->ce->name),
2223
0
      zend_get_unmangled_property_name(prop->name),
2224
0
      ZSTR_VAL(type_str));
2225
0
    zend_string_release(type_str);
2226
0
    return ZEND_LONG_MIN;
2227
0
  }
2228
0
}
2229
2230
static void zend_incdec_typed_ref(zend_reference *ref, zval *copy OPLINE_DC EXECUTE_DATA_DC)
2231
0
{
2232
0
  zval tmp;
2233
0
  zval *var_ptr = &ref->val;
2234
2235
0
  if (!copy) {
2236
0
    copy = &tmp;
2237
0
  }
2238
2239
0
  ZVAL_COPY(copy, var_ptr);
2240
2241
0
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2242
0
    increment_function(var_ptr);
2243
0
  } else {
2244
0
    decrement_function(var_ptr);
2245
0
  }
2246
2247
0
  if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) {
2248
0
    zend_property_info *error_prop = zend_get_prop_not_accepting_double(ref);
2249
0
    if (UNEXPECTED(error_prop)) {
2250
0
      zend_long val = zend_throw_incdec_ref_error(ref, error_prop OPLINE_CC);
2251
0
      ZVAL_LONG(var_ptr, val);
2252
0
    }
2253
0
  } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, EX_USES_STRICT_TYPES()))) {
2254
0
    zval_ptr_dtor(var_ptr);
2255
0
    ZVAL_COPY_VALUE(var_ptr, copy);
2256
0
    ZVAL_UNDEF(copy);
2257
0
  } else if (copy == &tmp) {
2258
0
    zval_ptr_dtor(&tmp);
2259
0
  }
2260
0
}
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
0
{
2294
0
  if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
2295
0
    if (ZEND_IS_INCREMENT(opline->opcode)) {
2296
0
      fast_long_increment_function(prop);
2297
0
    } else {
2298
0
      fast_long_decrement_function(prop);
2299
0
    }
2300
0
    if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info
2301
0
        && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2302
0
      zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
2303
0
      ZVAL_LONG(prop, val);
2304
0
    }
2305
0
  } else {
2306
0
    do {
2307
0
      if (Z_ISREF_P(prop)) {
2308
0
        zend_reference *ref = Z_REF_P(prop);
2309
0
        prop = Z_REFVAL_P(prop);
2310
0
        if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
2311
0
          zend_incdec_typed_ref(ref, NULL OPLINE_CC EXECUTE_DATA_CC);
2312
0
          break;
2313
0
        }
2314
0
      }
2315
2316
0
      if (prop_info) {
2317
0
        zend_incdec_typed_prop(prop_info, prop, NULL OPLINE_CC EXECUTE_DATA_CC);
2318
0
      } else if (ZEND_IS_INCREMENT(opline->opcode)) {
2319
0
        increment_function(prop);
2320
0
      } else {
2321
0
        decrement_function(prop);
2322
0
      }
2323
0
    } while (0);
2324
0
  }
2325
0
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2326
0
    ZVAL_COPY(EX_VAR(opline->result.var), prop);
2327
0
  }
2328
0
}
2329
2330
static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC)
2331
0
{
2332
0
  if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
2333
0
    ZVAL_LONG(EX_VAR(opline->result.var), Z_LVAL_P(prop));
2334
0
    if (ZEND_IS_INCREMENT(opline->opcode)) {
2335
0
      fast_long_increment_function(prop);
2336
0
    } else {
2337
0
      fast_long_decrement_function(prop);
2338
0
    }
2339
0
    if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info
2340
0
        && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2341
0
      zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
2342
0
      ZVAL_LONG(prop, val);
2343
0
    }
2344
0
  } else {
2345
0
    if (Z_ISREF_P(prop)) {
2346
0
      zend_reference *ref = Z_REF_P(prop);
2347
0
      prop = Z_REFVAL_P(prop);
2348
0
      if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
2349
0
        zend_incdec_typed_ref(ref, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC);
2350
0
        return;
2351
0
      }
2352
0
    }
2353
2354
0
    if (prop_info) {
2355
0
      zend_incdec_typed_prop(prop_info, prop, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC);
2356
0
    } else {
2357
0
      ZVAL_COPY(EX_VAR(opline->result.var), prop);
2358
0
      if (ZEND_IS_INCREMENT(opline->opcode)) {
2359
0
        increment_function(prop);
2360
0
      } else {
2361
0
        decrement_function(prop);
2362
0
      }
2363
0
    }
2364
0
  }
2365
0
}
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
0
{
2369
0
  zval rv;
2370
0
  zval *z;
2371
0
  zval z_copy;
2372
2373
0
  GC_ADDREF(object);
2374
0
  z =object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
2375
0
  if (UNEXPECTED(EG(exception))) {
2376
0
    OBJ_RELEASE(object);
2377
0
    ZVAL_UNDEF(EX_VAR(opline->result.var));
2378
0
    return;
2379
0
  }
2380
2381
0
  ZVAL_COPY_DEREF(&z_copy, z);
2382
0
  ZVAL_COPY(EX_VAR(opline->result.var), &z_copy);
2383
0
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2384
0
    increment_function(&z_copy);
2385
0
  } else {
2386
0
    decrement_function(&z_copy);
2387
0
  }
2388
0
  object->handlers->write_property(object, name, &z_copy, cache_slot);
2389
0
  OBJ_RELEASE(object);
2390
0
  zval_ptr_dtor(&z_copy);
2391
0
  if (z == &rv) {
2392
0
    zval_ptr_dtor(z);
2393
0
  }
2394
0
}
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
0
{
2431
0
  zval *z;
2432
0
  zval rv, res;
2433
2434
0
  GC_ADDREF(object);
2435
0
  z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
2436
0
  if (UNEXPECTED(EG(exception))) {
2437
0
    OBJ_RELEASE(object);
2438
0
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2439
0
      ZVAL_UNDEF(EX_VAR(opline->result.var));
2440
0
    }
2441
0
    return;
2442
0
  }
2443
0
  if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) {
2444
0
    object->handlers->write_property(object, name, &res, cache_slot);
2445
0
  }
2446
0
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2447
0
    ZVAL_COPY(EX_VAR(opline->result.var), &res);
2448
0
  }
2449
0
  if (z == &rv) {
2450
0
    zval_ptr_dtor(z);
2451
0
  }
2452
0
  zval_ptr_dtor(&res);
2453
0
  OBJ_RELEASE(object);
2454
0
}
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
0
{
2483
0
  HashTable *ht;
2484
2485
0
  if (EXPECTED(fetch_type & (ZEND_FETCH_GLOBAL_LOCK | ZEND_FETCH_GLOBAL))) {
2486
0
    ht = &EG(symbol_table);
2487
0
  } else {
2488
0
    ZEND_ASSERT(fetch_type & ZEND_FETCH_LOCAL);
2489
0
    if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
2490
0
      zend_rebuild_symbol_table();
2491
0
    }
2492
0
    ht = EX(symbol_table);
2493
0
  }
2494
0
  return ht;
2495
0
}
2496
2497
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_offset(zend_long lval)
2498
0
{
2499
0
  zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, lval);
2500
0
}
2501
2502
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_index(const zend_string *offset)
2503
0
{
2504
0
  zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset));
2505
0
}
2506
2507
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval)
2508
0
{
2509
  /* The array may be destroyed while throwing the notice.
2510
   * Temporarily increase the refcount to detect this situation. */
2511
0
  if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2512
0
    GC_ADDREF(ht);
2513
0
  }
2514
0
  zend_undefined_offset(lval);
2515
0
  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
0
  if (EG(exception)) {
2522
0
    return NULL;
2523
0
  }
2524
0
  return zend_hash_index_add_new(ht, lval, &EG(uninitialized_zval));
2525
0
}
2526
2527
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset)
2528
0
{
2529
0
  zval *retval;
2530
2531
  /* The array may be destroyed while throwing the notice.
2532
   * Temporarily increase the refcount to detect this situation. */
2533
0
  if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2534
0
    GC_ADDREF(ht);
2535
0
  }
2536
  /* Key may be released while throwing the undefined index warning. */
2537
0
  zend_string_addref(offset);
2538
0
  zend_undefined_index(offset);
2539
0
  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
0
  } else if (EG(exception)) {
2545
0
    retval = NULL;
2546
0
  } else {
2547
0
    retval = zend_hash_add_new(ht, offset, &EG(uninitialized_zval));
2548
0
  }
2549
0
  zend_string_release(offset);
2550
0
  return retval;
2551
0
}
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
0
{
2555
0
  zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method));
2556
0
}
2557
2558
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_invalid_method_call(zval *object, zval *function_name)
2559
0
{
2560
0
  zend_throw_error(NULL, "Call to a member function %s() on %s",
2561
0
    Z_STRVAL_P(function_name), zend_zval_value_name(object));
2562
0
}
2563
2564
ZEND_API void ZEND_FASTCALL zend_non_static_method_call(const zend_function *fbc)
2565
0
{
2566
0
  zend_throw_error(
2567
0
    zend_ce_error,
2568
0
    "Non-static method %s::%s() cannot be called statically",
2569
0
    ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2570
0
}
2571
2572
ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num)
2573
0
{
2574
0
  const char *arg_name = get_function_arg_name(func, arg_num);
2575
2576
0
  zend_error(E_WARNING, "%s%s%s(): Argument #%d%s%s%s must be passed by reference, value given",
2577
0
    func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
2578
0
    func->common.scope ? "::" : "",
2579
0
    ZSTR_VAL(func->common.function_name),
2580
0
    arg_num,
2581
0
    arg_name ? " ($" : "",
2582
0
    arg_name ? arg_name : "",
2583
0
    arg_name ? ")" : ""
2584
0
  );
2585
0
}
2586
2587
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(void)
2588
0
{
2589
0
  zend_throw_error(NULL, "Cannot use a scalar value as an array");
2590
0
}
2591
2592
ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void)
2593
0
{
2594
0
  zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
2595
0
}
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
0
{
2606
0
  zend_throw_error(NULL, "[] operator not supported for strings");
2607
0
}
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
0
{
2624
0
  if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
2625
0
    if (opline->op2_type == IS_UNUSED) {
2626
0
      zend_use_new_element_for_string();
2627
0
    } else {
2628
0
      zend_check_string_offset(dim, BP_VAR_RW EXECUTE_DATA_CC);
2629
0
      zend_wrong_string_offset_error();
2630
0
    }
2631
0
  } else {
2632
0
    zend_use_scalar_as_array();
2633
0
  }
2634
0
}
2635
2636
static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC)
2637
0
{
2638
0
  switch (Z_TYPE_P(dim)) {
2639
0
    case IS_UNDEF: {
2640
      /* The array may be destroyed while throwing the notice.
2641
       * Temporarily increase the refcount to detect this situation. */
2642
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2643
0
        GC_ADDREF(ht);
2644
0
      }
2645
0
      ZVAL_UNDEFINED_OP2();
2646
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
2647
0
        zend_array_destroy(ht);
2648
0
        return IS_NULL;
2649
0
      }
2650
0
      if (EG(exception)) {
2651
0
        return IS_NULL;
2652
0
      }
2653
0
      ZEND_FALLTHROUGH;
2654
0
    }
2655
0
    case IS_NULL:
2656
      /* The array may be destroyed while throwing the notice.
2657
       * Temporarily increase the refcount to detect this situation. */
2658
0
      GC_TRY_ADDREF(ht);
2659
2660
0
      zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
2661
2662
0
      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
0
      if (EG(exception)) {
2668
0
        return IS_NULL;
2669
0
      }
2670
2671
0
      value->str = ZSTR_EMPTY_ALLOC();
2672
0
      return IS_STRING;
2673
0
    case IS_DOUBLE:
2674
      /* The array may be destroyed while throwing the notice.
2675
       * Temporarily increase the refcount to detect this situation. */
2676
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2677
0
        GC_ADDREF(ht);
2678
0
      }
2679
0
      value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
2680
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
2681
0
        zend_array_destroy(ht);
2682
0
        return IS_NULL;
2683
0
      }
2684
0
      if (EG(exception)) {
2685
0
        return IS_NULL;
2686
0
      }
2687
0
      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
0
    case IS_FALSE:
2705
0
      value->lval = 0;
2706
0
      return IS_LONG;
2707
0
    case IS_TRUE:
2708
0
      value->lval = 1;
2709
0
      return IS_LONG;
2710
0
    default:
2711
0
      zend_illegal_array_offset_access(dim);
2712
0
      return IS_NULL;
2713
0
  }
2714
0
}
2715
2716
static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC)
2717
0
{
2718
0
  switch (Z_TYPE_P(dim)) {
2719
0
    case IS_UNDEF: {
2720
      /* The array may be destroyed while throwing the notice.
2721
       * Temporarily increase the refcount to detect this situation. */
2722
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2723
0
        GC_ADDREF(ht);
2724
0
      }
2725
0
      ZVAL_UNDEFINED_OP2();
2726
0
      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
0
      if (EG(exception)) {
2733
0
        return IS_NULL;
2734
0
      }
2735
0
      ZEND_FALLTHROUGH;
2736
0
    }
2737
0
    case IS_NULL:
2738
      /* The array may be destroyed while throwing the notice.
2739
       * Temporarily increase the refcount to detect this situation. */
2740
0
      GC_TRY_ADDREF(ht);
2741
2742
0
      zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
2743
2744
0
      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
0
      if (EG(exception)) {
2751
0
        return IS_NULL;
2752
0
      }
2753
0
      value->str = ZSTR_EMPTY_ALLOC();
2754
0
      return IS_STRING;
2755
0
    case IS_DOUBLE:
2756
      /* The array may be destroyed while throwing the notice.
2757
       * Temporarily increase the refcount to detect this situation. */
2758
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2759
0
        GC_ADDREF(ht);
2760
0
      }
2761
0
      value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
2762
0
      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
0
      if (EG(exception)) {
2769
0
        return IS_NULL;
2770
0
      }
2771
0
      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
0
    case IS_FALSE:
2791
0
      value->lval = 0;
2792
0
      return IS_LONG;
2793
0
    case IS_TRUE:
2794
0
      value->lval = 1;
2795
0
      return IS_LONG;
2796
0
    default:
2797
0
      zend_illegal_array_offset_access(dim);
2798
0
      return IS_NULL;
2799
0
  }
2800
0
}
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
0
{
2804
0
  zval *retval = NULL;
2805
0
  zend_string *offset_key;
2806
0
  zend_ulong hval;
2807
2808
0
try_again:
2809
0
  if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
2810
0
    hval = Z_LVAL_P(dim);
2811
0
num_index:
2812
0
    if (type != BP_VAR_W) {
2813
0
      ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
2814
0
      return retval;
2815
0
num_undef:
2816
0
      switch (type) {
2817
0
        case BP_VAR_R:
2818
0
          zend_undefined_offset(hval);
2819
0
          ZEND_FALLTHROUGH;
2820
0
        case BP_VAR_UNSET:
2821
0
        case BP_VAR_IS:
2822
0
          retval = &EG(uninitialized_zval);
2823
0
          break;
2824
0
        case BP_VAR_RW:
2825
0
          retval = zend_undefined_offset_write(ht, hval);
2826
0
          break;
2827
0
        }
2828
0
    } else {
2829
0
      ZEND_HASH_INDEX_LOOKUP(ht, hval, retval);
2830
0
    }
2831
0
  } else if (EXPECTED(Z_TYPE_P(dim) == IS_STRING)) {
2832
0
    offset_key = Z_STR_P(dim);
2833
0
    if (ZEND_CONST_COND(dim_type != IS_CONST, 1)) {
2834
0
      if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
2835
0
        goto num_index;
2836
0
      }
2837
0
    }
2838
0
str_index:
2839
0
    if (type != BP_VAR_W) {
2840
0
      retval = zend_hash_find_ex(ht, offset_key, ZEND_CONST_COND(dim_type == IS_CONST, 0));
2841
0
      if (!retval) {
2842
0
        switch (type) {
2843
0
          case BP_VAR_R:
2844
0
            zend_undefined_index(offset_key);
2845
0
            ZEND_FALLTHROUGH;
2846
0
          case BP_VAR_UNSET:
2847
0
          case BP_VAR_IS:
2848
0
            retval = &EG(uninitialized_zval);
2849
0
            break;
2850
0
          case BP_VAR_RW:
2851
0
            retval = zend_undefined_index_write(ht, offset_key);
2852
0
            break;
2853
0
        }
2854
0
      }
2855
0
    } else {
2856
0
      retval = zend_hash_lookup(ht, offset_key);
2857
0
    }
2858
0
  } else if (EXPECTED(Z_TYPE_P(dim) == IS_REFERENCE)) {
2859
0
    dim = Z_REFVAL_P(dim);
2860
0
    goto try_again;
2861
0
  } else {
2862
0
    zend_value val;
2863
0
    uint8_t t;
2864
2865
0
    if (type != BP_VAR_W && type != BP_VAR_RW) {
2866
0
      t = slow_index_convert(ht, dim, &val EXECUTE_DATA_CC);
2867
0
    } else {
2868
0
      t = slow_index_convert_w(ht, dim, &val EXECUTE_DATA_CC);
2869
0
    }
2870
0
    if (t == IS_STRING) {
2871
0
      offset_key = val.str;
2872
0
      goto str_index;
2873
0
    } else if (t == IS_LONG) {
2874
0
      hval = val.lval;
2875
0
      goto num_index;
2876
0
    } else {
2877
0
      retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
2878
0
          NULL : &EG(uninitialized_zval);
2879
0
    }
2880
0
  }
2881
0
  return retval;
2882
0
}
2883
2884
static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W(HashTable *ht, const zval *dim EXECUTE_DATA_DC)
2885
0
{
2886
0
  return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_W EXECUTE_DATA_CC);
2887
0
}
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
0
{
2891
0
  return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_W EXECUTE_DATA_CC);
2892
0
}
2893
2894
static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW(HashTable *ht, const zval *dim EXECUTE_DATA_DC)
2895
0
{
2896
0
  return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_RW EXECUTE_DATA_CC);
2897
0
}
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
0
{
2901
0
  return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_RW EXECUTE_DATA_CC);
2902
0
}
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
0
{
2906
0
  zval *retval;
2907
2908
0
  if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
2909
0
try_array:
2910
0
    SEPARATE_ARRAY(container);
2911
0
fetch_from_array:
2912
0
    if (dim == NULL) {
2913
0
      retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
2914
0
      if (UNEXPECTED(retval == NULL)) {
2915
0
        zend_cannot_add_element();
2916
0
        ZVAL_UNDEF(result);
2917
0
        return;
2918
0
      }
2919
0
    } else {
2920
0
      retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC);
2921
0
      if (UNEXPECTED(!retval)) {
2922
        /* This may fail without throwing if the array was modified while throwing an
2923
         * undefined index error. */
2924
0
        ZVAL_NULL(result);
2925
0
        return;
2926
0
      }
2927
0
    }
2928
0
    ZVAL_INDIRECT(result, retval);
2929
0
    return;
2930
0
  } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) {
2931
0
    zend_reference *ref = Z_REF_P(container);
2932
0
    container = Z_REFVAL_P(container);
2933
0
    if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
2934
0
      goto try_array;
2935
0
    } else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
2936
0
      if (type != BP_VAR_UNSET) {
2937
0
        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
0
        array_init(container);
2944
0
        goto fetch_from_array;
2945
0
      } else {
2946
0
        goto return_null;
2947
0
      }
2948
0
    }
2949
0
  }
2950
0
  if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
2951
0
    if (dim == NULL) {
2952
0
      zend_use_new_element_for_string();
2953
0
    } else {
2954
0
      zend_check_string_offset(dim, type EXECUTE_DATA_CC);
2955
0
      zend_wrong_string_offset_error();
2956
0
    }
2957
0
    ZVAL_UNDEF(result);
2958
0
  } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
2959
0
    zend_object *obj = Z_OBJ_P(container);
2960
0
    GC_ADDREF(obj);
2961
0
    if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
2962
0
      dim = ZVAL_UNDEFINED_OP2();
2963
0
    } else if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
2964
0
      dim++;
2965
0
    }
2966
0
    retval = obj->handlers->read_dimension(obj, dim, type, result);
2967
2968
0
    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
0
    } else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) {
2974
0
      if (!Z_ISREF_P(retval)) {
2975
0
        if (result != retval) {
2976
0
          ZVAL_COPY(result, retval);
2977
0
          retval = result;
2978
0
        }
2979
0
        if (Z_TYPE_P(retval) != IS_OBJECT) {
2980
0
          zend_class_entry *ce = obj->ce;
2981
0
          zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
2982
0
        }
2983
0
      } else if (UNEXPECTED(Z_REFCOUNT_P(retval) == 1)) {
2984
0
        ZVAL_UNREF(retval);
2985
0
      }
2986
0
      if (result != retval) {
2987
0
        ZVAL_INDIRECT(result, retval);
2988
0
      }
2989
0
    } else {
2990
0
      ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception");
2991
0
      ZVAL_UNDEF(result);
2992
0
    }
2993
0
    if (UNEXPECTED(GC_DELREF(obj) == 0)) {
2994
0
      zend_objects_store_del(obj);
2995
0
    }
2996
0
  } else {
2997
0
    if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
2998
0
      if (type != BP_VAR_W && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
2999
0
        ZVAL_UNDEFINED_OP1();
3000
0
      }
3001
0
      if (type != BP_VAR_UNSET) {
3002
0
        HashTable *ht = zend_new_array(0);
3003
0
        uint8_t old_type = Z_TYPE_P(container);
3004
3005
0
        ZVAL_ARR(container, ht);
3006
0
        if (UNEXPECTED(old_type == IS_FALSE)) {
3007
0
          GC_ADDREF(ht);
3008
0
          zend_false_to_array_deprecated();
3009
0
          if (UNEXPECTED(GC_DELREF(ht) == 0)) {
3010
0
            zend_array_destroy(ht);
3011
0
            goto return_null;
3012
0
          }
3013
0
        }
3014
0
        goto fetch_from_array;
3015
0
      } else {
3016
0
        if (UNEXPECTED(Z_TYPE_P(container) == IS_FALSE)) {
3017
0
          zend_false_to_array_deprecated();
3018
0
        }
3019
0
return_null:
3020
        /* for read-mode only */
3021
0
        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
0
        ZVAL_NULL(result);
3025
0
      }
3026
0
    } else {
3027
0
      if (type == BP_VAR_UNSET) {
3028
0
        zend_throw_error(NULL, "Cannot unset offset in a non-array variable");
3029
0
        ZVAL_UNDEF(result);
3030
0
      } else {
3031
0
        zend_use_scalar_as_array();
3032
0
        ZVAL_UNDEF(result);
3033
0
      }
3034
0
    }
3035
0
  }
3036
0
}
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
0
{
3040
0
  zval *result = EX_VAR(opline->result.var);
3041
0
  zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W EXECUTE_DATA_CC);
3042
0
}
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
0
{
3046
0
  zval *result = EX_VAR(opline->result.var);
3047
0
  zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_RW EXECUTE_DATA_CC);
3048
0
}
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
0
{
3052
0
  zval *result = EX_VAR(opline->result.var);
3053
0
  zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_UNSET EXECUTE_DATA_CC);
3054
0
}
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
0
{
3058
0
  zval *retval;
3059
3060
0
  if (!slow) {
3061
0
    if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
3062
0
try_array:
3063
0
      retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC);
3064
0
      ZVAL_COPY_DEREF(result, retval);
3065
0
      return;
3066
0
    } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) {
3067
0
      container = Z_REFVAL_P(container);
3068
0
      if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
3069
0
        goto try_array;
3070
0
      }
3071
0
    }
3072
0
  }
3073
0
  if (!is_list && EXPECTED(Z_TYPE_P(container) == IS_STRING)) {
3074
0
    zend_string *str = Z_STR_P(container);
3075
0
    zend_long offset;
3076
3077
0
try_string_offset:
3078
0
    if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
3079
0
      switch (Z_TYPE_P(dim)) {
3080
0
        case IS_STRING:
3081
0
        {
3082
0
          bool trailing_data = false;
3083
          /* For BC reasons we allow errors so that we can warn on leading numeric string */
3084
0
          if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset,
3085
0
              NULL, /* allow errors */ true, NULL, &trailing_data)) {
3086
0
            if (UNEXPECTED(trailing_data)) {
3087
0
              zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
3088
0
            }
3089
0
            goto out;
3090
0
          }
3091
0
          if (type == BP_VAR_IS) {
3092
0
            ZVAL_NULL(result);
3093
0
            return;
3094
0
          }
3095
0
          zend_illegal_string_offset(dim, BP_VAR_R);
3096
0
          ZVAL_NULL(result);
3097
0
          return;
3098
0
        }
3099
0
        case IS_UNDEF:
3100
          /* The string may be destroyed while throwing the notice.
3101
           * Temporarily increase the refcount to detect this situation. */
3102
0
          if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
3103
0
            GC_ADDREF(str);
3104
0
          }
3105
0
          ZVAL_UNDEFINED_OP2();
3106
0
          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
0
          ZEND_FALLTHROUGH;
3112
0
        case IS_DOUBLE:
3113
0
        case IS_NULL:
3114
0
        case IS_FALSE:
3115
0
        case IS_TRUE:
3116
0
          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
0
            if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
3120
0
              GC_ADDREF(str);
3121
0
            }
3122
0
            zend_error(E_WARNING, "String offset cast occurred");
3123
0
            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
0
          }
3129
          /* To prevent double warning */
3130
0
          if (Z_TYPE_P(dim) == IS_DOUBLE) {
3131
0
            offset = zend_dval_to_lval_silent(Z_DVAL_P(dim));
3132
0
            goto out;
3133
0
          }
3134
0
          break;
3135
0
        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
0
      }
3143
3144
0
      offset = zval_get_long_func(dim, /* is_strict */ false);
3145
0
    } else {
3146
0
      offset = Z_LVAL_P(dim);
3147
0
    }
3148
0
    out:
3149
3150
0
    if (UNEXPECTED(ZSTR_LEN(str) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) {
3151
0
      if (type != BP_VAR_IS) {
3152
0
        zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
3153
0
        ZVAL_EMPTY_STRING(result);
3154
0
      } else {
3155
0
        ZVAL_NULL(result);
3156
0
      }
3157
0
    } else {
3158
0
      zend_uchar c;
3159
0
      zend_long real_offset;
3160
3161
0
      real_offset = (UNEXPECTED(offset < 0)) /* Handle negative offset */
3162
0
        ? (zend_long)ZSTR_LEN(str) + offset : offset;
3163
0
      c = (zend_uchar)ZSTR_VAL(str)[real_offset];
3164
3165
0
      ZVAL_CHAR(result, c);
3166
0
    }
3167
0
  } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
3168
0
    zend_object *obj = Z_OBJ_P(container);
3169
3170
0
    GC_ADDREF(obj);
3171
0
    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
0
    if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
3175
0
      dim++;
3176
0
    }
3177
0
    retval = obj->handlers->read_dimension(obj, dim, type, result);
3178
3179
0
    ZEND_ASSERT(result != NULL);
3180
0
    if (retval) {
3181
0
      if (result != retval) {
3182
0
        ZVAL_COPY_DEREF(result, retval);
3183
0
      } else if (UNEXPECTED(Z_ISREF_P(retval))) {
3184
0
        zend_unwrap_reference(result);
3185
0
      }
3186
0
    } else {
3187
0
      ZVAL_NULL(result);
3188
0
    }
3189
0
    if (UNEXPECTED(GC_DELREF(obj) == 0)) {
3190
0
      zend_objects_store_del(obj);
3191
0
    }
3192
0
  } else {
3193
0
    if (type != BP_VAR_IS && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
3194
0
      container = ZVAL_UNDEFINED_OP1();
3195
0
    }
3196
0
    if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
3197
0
      ZVAL_UNDEFINED_OP2();
3198
0
    }
3199
0
    if (is_list && Z_TYPE_P(container) > IS_NULL) {
3200
0
      zend_error(E_WARNING, "Cannot use %s as array", zend_zval_type_name(container));
3201
0
    }
3202
0
    if (!is_list && type != BP_VAR_IS) {
3203
0
      zend_error(E_WARNING, "Trying to access array offset on %s",
3204
0
        zend_zval_value_name(container));
3205
0
    }
3206
0
    ZVAL_NULL(result);
3207
0
  }
3208
0
}
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
0
{
3212
0
  zval *result = EX_VAR(opline->result.var);
3213
0
  zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 0, 0 EXECUTE_DATA_CC);
3214
0
}
3215
3216
static zend_never_inline void zend_fetch_dimension_address_read_R_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC)
3217
0
{
3218
0
  zval *result = EX_VAR(opline->result.var);
3219
0
  zend_fetch_dimension_address_read(result, container, dim, IS_CV, BP_VAR_R, 0, 1 EXECUTE_DATA_CC);
3220
0
}
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
0
{
3224
0
  zval *result = EX_VAR(opline->result.var);
3225
0
  zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_IS, 0, 0 EXECUTE_DATA_CC);
3226
0
}
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
0
{
3230
0
  zval *result = EX_VAR(opline->result.var);
3231
0
  zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 1, 0 EXECUTE_DATA_CC);
3232
0
}
3233
3234
ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *dim, int type)
3235
0
{
3236
0
  zend_fetch_dimension_address_read(result, container, dim, IS_TMP_VAR, type, 0, 0 NO_EXECUTE_DATA_CC);
3237
0
}
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
0
{
3296
0
  if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
3297
0
    offset = ZVAL_UNDEFINED_OP2();
3298
0
  }
3299
3300
0
  if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
3301
0
    return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0);
3302
0
  } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
3303
0
    zend_long lval;
3304
3305
0
    if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
3306
0
      lval = Z_LVAL_P(offset);
3307
0
str_offset:
3308
0
      if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
3309
0
        lval += (zend_long)Z_STRLEN_P(container);
3310
0
      }
3311
0
      if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3312
0
        return 1;
3313
0
      } else {
3314
0
        return 0;
3315
0
      }
3316
0
    } else {
3317
      /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/
3318
0
        ZVAL_DEREF(offset);
3319
      /*}*/
3320
0
      if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
3321
0
          || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
3322
0
            && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
3323
0
        lval = zval_get_long_ex(offset, /* is_strict */ true);
3324
0
        goto str_offset;
3325
0
      }
3326
0
      return 0;
3327
0
    }
3328
0
  } else {
3329
0
    return 0;
3330
0
  }
3331
0
}
3332
3333
static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC)
3334
0
{
3335
0
  if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
3336
0
    offset = ZVAL_UNDEFINED_OP2();
3337
0
  }
3338
3339
0
  if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
3340
0
    return !Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 1);
3341
0
  } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
3342
0
    zend_long lval;
3343
3344
0
    if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
3345
0
      lval = Z_LVAL_P(offset);
3346
0
str_offset:
3347
0
      if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
3348
0
        lval += (zend_long)Z_STRLEN_P(container);
3349
0
      }
3350
0
      if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3351
0
        return (Z_STRVAL_P(container)[lval] == '0');
3352
0
      } else {
3353
0
        return 1;
3354
0
      }
3355
0
    } else {
3356
      /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/
3357
0
        ZVAL_DEREF(offset);
3358
      /*}*/
3359
0
      if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
3360
0
          || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
3361
0
            && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
3362
0
        lval = zval_get_long_ex(offset, /* is_strict */ true);
3363
0
        goto str_offset;
3364
0
      }
3365
0
      return 1;
3366
0
    }
3367
0
  } else {
3368
0
    return 1;
3369
0
  }
3370
0
}
3371
3372
static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable *ht, zval *key OPLINE_DC EXECUTE_DATA_DC)
3373
0
{
3374
0
  zend_string *str;
3375
0
  zend_ulong hval;
3376
3377
0
try_again:
3378
0
  if (EXPECTED(Z_TYPE_P(key) == IS_STRING)) {
3379
0
    str = Z_STR_P(key);
3380
0
    if (ZEND_HANDLE_NUMERIC(str, hval)) {
3381
0
      goto num_key;
3382
0
    }
3383
0
str_key:
3384
0
    return zend_hash_exists(ht, str);
3385
0
  } else if (EXPECTED(Z_TYPE_P(key) == IS_LONG)) {
3386
0
    hval = Z_LVAL_P(key);
3387
0
num_key:
3388
0
    return zend_hash_index_exists(ht, hval);
3389
0
  } else if (EXPECTED(Z_ISREF_P(key))) {
3390
0
    key = Z_REFVAL_P(key);
3391
0
    goto try_again;
3392
0
  } 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
0
  } else if (Z_TYPE_P(key) == IS_FALSE) {
3406
0
    hval = 0;
3407
0
    goto num_key;
3408
0
  } else if (Z_TYPE_P(key) == IS_TRUE) {
3409
0
    hval = 1;
3410
0
    goto num_key;
3411
0
  } 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
0
  } else if (Z_TYPE_P(key) <= IS_NULL) {
3416
0
    if (UNEXPECTED(Z_TYPE_P(key) == IS_UNDEF)) {
3417
0
      ZVAL_UNDEFINED_OP1();
3418
0
    } else {
3419
0
      ZEND_ASSERT(Z_TYPE_P(key) == IS_NULL);
3420
0
      zend_error(E_DEPRECATED, "Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead");
3421
0
    }
3422
0
    str = ZSTR_EMPTY_ALLOC();
3423
0
    goto str_key;
3424
0
  } else {
3425
0
    zend_illegal_array_offset_access(key);
3426
0
    return 0;
3427
0
  }
3428
0
}
3429
3430
static ZEND_COLD void ZEND_FASTCALL zend_array_key_exists_error(
3431
    zval *subject, zval *key OPLINE_DC EXECUTE_DATA_DC)
3432
0
{
3433
0
  if (Z_TYPE_P(key) == IS_UNDEF) {
3434
0
    ZVAL_UNDEFINED_OP1();
3435
0
  }
3436
0
  if (Z_TYPE_P(subject) == IS_UNDEF) {
3437
0
    ZVAL_UNDEFINED_OP2();
3438
0
  }
3439
0
  if (!EG(exception)) {
3440
0
    zend_type_error("array_key_exists(): Argument #2 ($array) must be of type array, %s given",
3441
0
      zend_zval_value_name(subject));
3442
0
  }
3443
0
}
3444
3445
0
static zend_always_inline bool promotes_to_array(zval *val) {
3446
0
  return Z_TYPE_P(val) <= IS_FALSE
3447
0
    || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE);
3448
0
}
3449
3450
0
static zend_always_inline bool check_type_array_assignable(zend_type type) {
3451
0
  if (!ZEND_TYPE_IS_SET(type)) {
3452
0
    return 1;
3453
0
  }
3454
0
  return (ZEND_TYPE_FULL_MASK(type) & MAY_BE_ARRAY) != 0;
3455
0
}
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
0
{
3473
0
  switch (flags) {
3474
0
    case ZEND_FETCH_DIM_WRITE:
3475
0
      if (promotes_to_array(ptr)) {
3476
0
        if (!prop_info) {
3477
0
          break;
3478
0
        }
3479
0
        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
0
      }
3485
0
      break;
3486
0
    case ZEND_FETCH_REF:
3487
0
      if (Z_TYPE_P(ptr) != IS_REFERENCE) {
3488
0
        if (!prop_info) {
3489
0
          break;
3490
0
        }
3491
0
        if (Z_TYPE_P(ptr) == IS_UNDEF) {
3492
0
          if (!ZEND_TYPE_ALLOW_NULL(prop_info->type)) {
3493
0
            zend_throw_access_uninit_prop_by_ref_error(prop_info);
3494
0
            if (result) ZVAL_ERROR(result);
3495
0
            return 0;
3496
0
          }
3497
0
          ZVAL_NULL(ptr);
3498
0
        }
3499
3500
0
        ZVAL_NEW_REF(ptr, ptr);
3501
0
        ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(ptr), prop_info);
3502
0
      }
3503
0
      break;
3504
0
    EMPTY_SWITCH_DEFAULT_CASE()
3505
0
  }
3506
0
  return 1;
3507
0
}
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
0
{
3511
0
  zval *ptr;
3512
0
  zend_object *zobj;
3513
0
  zend_string *name, *tmp_name;
3514
0
  void *_cache_slot[3] = {0};
3515
0
  if (prop_op_type != IS_CONST) {
3516
0
    cache_slot = _cache_slot;
3517
0
  } else {
3518
0
    ZEND_ASSERT(cache_slot);
3519
0
  }
3520
3521
0
  if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
3522
0
    do {
3523
0
      if (Z_ISREF_P(container) && Z_TYPE_P(Z_REFVAL_P(container)) == IS_OBJECT) {
3524
0
        container = Z_REFVAL_P(container);
3525
0
        break;
3526
0
      }
3527
3528
0
      if (container_op_type == IS_CV
3529
0
       && type != BP_VAR_W
3530
0
       && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
3531
0
        ZVAL_UNDEFINED_OP1();
3532
0
      }
3533
3534
      /* this should modify object only if it's empty */
3535
0
      if (type == BP_VAR_UNSET) {
3536
0
        ZVAL_NULL(result);
3537
0
        return;
3538
0
      }
3539
3540
0
      zend_throw_non_object_error(container, prop_ptr OPLINE_CC EXECUTE_DATA_CC);
3541
0
      ZVAL_ERROR(result);
3542
0
      return;
3543
0
    } while (0);
3544
0
  }
3545
3546
0
  zobj = Z_OBJ_P(container);
3547
0
  if (prop_op_type == IS_CONST &&
3548
0
      EXPECTED(zobj->ce == CACHED_PTR_EX(cache_slot))) {
3549
0
    uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1);
3550
0
    if (prop_info_p) {
3551
0
      *prop_info_p = CACHED_PTR_EX(cache_slot + 2);
3552
0
    }
3553
3554
0
    if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
3555
0
      ptr = OBJ_PROP(zobj, prop_offset);
3556
0
      if (EXPECTED(Z_TYPE_P(ptr) != IS_UNDEF)) {
3557
0
        ZVAL_INDIRECT(result, ptr);
3558
0
        zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);
3559
0
        if (prop_info) {
3560
0
          if (UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))
3561
0
           && ((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
0
            ZEND_ASSERT(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET);
3566
0
            if (Z_TYPE_P(ptr) == IS_OBJECT) {
3567
0
              ZVAL_COPY(result, ptr);
3568
0
            } else {
3569
0
              if (prop_info->flags & ZEND_ACC_READONLY) {
3570
0
                zend_readonly_property_indirect_modification_error(prop_info);
3571
0
              } else {
3572
0
                zend_asymmetric_visibility_property_modification_error(prop_info, "indirectly modify");
3573
0
              }
3574
0
              ZVAL_ERROR(result);
3575
0
            }
3576
0
            return;
3577
0
          }
3578
0
          flags &= ZEND_FETCH_OBJ_FLAGS;
3579
0
          if (flags) {
3580
0
            zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags);
3581
0
          }
3582
0
        }
3583
0
        return;
3584
0
      }
3585
0
    } else if (UNEXPECTED(IS_HOOKED_PROPERTY_OFFSET(prop_offset))) {
3586
      /* Fall through to read_property for hooks. */
3587
0
    } else if (EXPECTED(zobj->properties != NULL)) {
3588
0
      ZEND_ASSERT(IS_DYNAMIC_PROPERTY_OFFSET(prop_offset));
3589
0
      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
0
      ptr = zend_hash_find_known_hash(zobj->properties, Z_STR_P(prop_ptr));
3596
0
      if (EXPECTED(ptr)) {
3597
0
        ZVAL_INDIRECT(result, ptr);
3598
0
        return;
3599
0
      }
3600
0
    }
3601
0
  } else if (prop_op_type == IS_CONST) {
3602
    /* CE mismatch, make cache slot consistent */
3603
0
    cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
3604
0
  }
3605
3606
  /* Pointer on property callback is required */
3607
0
  ZEND_ASSERT(zobj->handlers->get_property_ptr_ptr != NULL);
3608
3609
0
  if (prop_op_type == IS_CONST) {
3610
0
    name = Z_STR_P(prop_ptr);
3611
0
  } else {
3612
0
    name = zval_get_tmp_string(prop_ptr, &tmp_name);
3613
0
  }
3614
0
  ptr = zobj->handlers->get_property_ptr_ptr(zobj, name, type, cache_slot);
3615
0
  if (NULL == ptr) {
3616
0
    ptr = zobj->handlers->read_property(zobj, name, type, cache_slot, result);
3617
0
    if (ptr == result) {
3618
0
      if (UNEXPECTED(Z_ISREF_P(ptr) && Z_REFCOUNT_P(ptr) == 1)) {
3619
0
        ZVAL_UNREF(ptr);
3620
0
      }
3621
0
      goto end;
3622
0
    }
3623
0
    if (UNEXPECTED(EG(exception))) {
3624
0
      ZVAL_ERROR(result);
3625
0
      goto end;
3626
0
    }
3627
0
  } else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
3628
0
    ZVAL_ERROR(result);
3629
0
    goto end;
3630
0
  } else if (type == BP_VAR_UNSET && UNEXPECTED(Z_TYPE_P(ptr) == IS_UNDEF)) {
3631
0
    ZVAL_NULL(result);
3632
0
    goto end;
3633
0
  }
3634
3635
0
  ZVAL_INDIRECT(result, ptr);
3636
0
  flags &= ZEND_FETCH_OBJ_FLAGS;
3637
0
  if (flags) {
3638
0
    zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);
3639
0
    if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
3640
0
      if (UNEXPECTED(!zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags))) {
3641
0
        goto end;
3642
0
      }
3643
0
    }
3644
0
  }
3645
3646
0
end:
3647
0
  if (prop_info_p) {
3648
0
    *prop_info_p = CACHED_PTR_EX(cache_slot + 2);
3649
0
  }
3650
0
  if (prop_op_type != IS_CONST) {
3651
0
    zend_tmp_string_release(tmp_name);
3652
0
  }
3653
0
}
3654
3655
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)
3656
0
{
3657
0
  zval variable, *variable_ptr = &variable;
3658
0
  void **cache_addr = (prop_op_type == IS_CONST) ? CACHE_ADDR(opline->extended_value & ~ZEND_RETURNS_FUNCTION) : NULL;
3659
0
  zend_refcounted *garbage = NULL;
3660
0
  zend_property_info *prop_info = NULL;
3661
3662
0
  zend_fetch_property_address(variable_ptr, container, container_op_type, prop_ptr, prop_op_type,
3663
0
    cache_addr, BP_VAR_W, 0, &prop_info OPLINE_CC EXECUTE_DATA_CC);
3664
3665
0
  if (EXPECTED(Z_TYPE_P(variable_ptr) == IS_INDIRECT)) {
3666
0
    variable_ptr = Z_INDIRECT_P(variable_ptr);
3667
0
    if (/*OP_DATA_TYPE == IS_VAR &&*/
3668
0
           (opline->extended_value & ZEND_RETURNS_FUNCTION) &&
3669
0
           UNEXPECTED(!Z_ISREF_P(value_ptr))) {
3670
3671
0
      variable_ptr = zend_wrong_assign_to_variable_reference(
3672
0
        variable_ptr, value_ptr, &garbage OPLINE_CC EXECUTE_DATA_CC);
3673
0
    } else if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
3674
0
      variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr, &garbage EXECUTE_DATA_CC);
3675
0
    } else {
3676
0
      zend_assign_to_variable_reference(variable_ptr, value_ptr, &garbage);
3677
0
    }
3678
0
  } else if (Z_ISERROR_P(variable_ptr)) {
3679
0
    variable_ptr = &EG(uninitialized_zval);
3680
0
  } else {
3681
0
    zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
3682
0
    zval_ptr_dtor(&variable);
3683
0
    variable_ptr = &EG(uninitialized_zval);
3684
0
  }
3685
3686
0
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
3687
0
    ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
3688
0
  }
3689
0
  if (garbage) {
3690
0
    GC_DTOR(garbage);
3691
0
  }
3692
0
}
3693
3694
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)
3695
0
{
3696
0
  zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_CONST, value_ptr
3697
0
    OPLINE_CC EXECUTE_DATA_CC);
3698
0
}
3699
3700
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)
3701
0
{
3702
0
  zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_CONST, value_ptr
3703
0
    OPLINE_CC EXECUTE_DATA_CC);
3704
0
}
3705
3706
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)
3707
0
{
3708
0
  zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_VAR, value_ptr
3709
0
    OPLINE_CC EXECUTE_DATA_CC);
3710
0
}
3711
3712
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)
3713
0
{
3714
0
  zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_VAR, value_ptr
3715
0
    OPLINE_CC EXECUTE_DATA_CC);
3716
0
}
3717
3718
0
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) {
3719
0
  zval *result;
3720
0
  zend_string *name;
3721
0
  zend_class_entry *ce;
3722
0
  zend_property_info *property_info;
3723
3724
0
  uint8_t op1_type = opline->op1_type, op2_type = opline->op2_type;
3725
3726
0
  if (EXPECTED(op2_type == IS_CONST)) {
3727
0
    zval *class_name = RT_CONSTANT(opline, opline->op2);
3728
3729
0
    ZEND_ASSERT(op1_type != IS_CONST || CACHED_PTR(cache_slot) == NULL);
3730
3731
0
    if (EXPECTED((ce = CACHED_PTR(cache_slot)) == NULL)) {
3732
0
      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);
3733
0
      if (UNEXPECTED(ce == NULL)) {
3734
0
        FREE_OP(op1_type, opline->op1.var);
3735
0
        return NULL;
3736
0
      }
3737
0
      if (UNEXPECTED(op1_type != IS_CONST)) {
3738
0
        CACHE_PTR(cache_slot, ce);
3739
0
      }
3740
0
    }
3741
0
  } else {
3742
0
    if (EXPECTED(op2_type == IS_UNUSED)) {
3743
0
      ce = zend_fetch_class(NULL, opline->op2.num);
3744
0
      if (UNEXPECTED(ce == NULL)) {
3745
0
        FREE_OP(op1_type, opline->op1.var);
3746
0
        return NULL;
3747
0
      }
3748
0
    } else {
3749
0
      ce = Z_CE_P(EX_VAR(opline->op2.var));
3750
0
    }
3751
0
    if (EXPECTED(op1_type == IS_CONST) && EXPECTED(CACHED_PTR(cache_slot) == ce)) {
3752
0
      result = CACHED_PTR(cache_slot + sizeof(void *));
3753
0
      *prop_info = CACHED_PTR(cache_slot + sizeof(void *) * 2);
3754
0
      return result;
3755
0
    }
3756
0
  }
3757
3758
0
  if (EXPECTED(op1_type == IS_CONST)) {
3759
0
    name = Z_STR_P(RT_CONSTANT(opline, opline->op1));
3760
0
    result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info);
3761
0
  } else {
3762
0
    zend_string *tmp_name;
3763
0
    zval *varname = get_zval_ptr_undef(opline->op1_type, opline->op1, BP_VAR_R);
3764
0
    if (EXPECTED(Z_TYPE_P(varname) == IS_STRING)) {
3765
0
      name = Z_STR_P(varname);
3766
0
      tmp_name = NULL;
3767
0
    } else {
3768
0
      if (op1_type == IS_CV && UNEXPECTED(Z_TYPE_P(varname) == IS_UNDEF)) {
3769
0
        zval_undefined_cv(opline->op1.var EXECUTE_DATA_CC);
3770
0
      }
3771
0
      name = zval_get_tmp_string(varname, &tmp_name);
3772
0
    }
3773
0
    result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info);
3774
3775
0
    zend_tmp_string_release(tmp_name);
3776
3777
0
    FREE_OP(op1_type, opline->op1.var);
3778
0
  }
3779
3780
0
  if (UNEXPECTED(result == NULL)) {
3781
0
    return NULL;
3782
0
  }
3783
3784
0
  if (UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF)
3785
0
   && (fetch_type == BP_VAR_IS || fetch_type == BP_VAR_UNSET)) {
3786
0
    return NULL;
3787
0
   }
3788
3789
0
  *prop_info = property_info;
3790
3791
0
  if (EXPECTED(op1_type == IS_CONST)
3792
0
      && EXPECTED(!(property_info->ce->ce_flags & ZEND_ACC_TRAIT))) {
3793
0
    CACHE_POLYMORPHIC_PTR(cache_slot, ce, result);
3794
0
    CACHE_PTR(cache_slot + sizeof(void *) * 2, property_info);
3795
0
  }
3796
3797
0
  return result;
3798
0
}
3799
3800
3801
0
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) {
3802
0
  zval *result;
3803
0
  zend_property_info *property_info;
3804
3805
0
  if (opline->op1_type == IS_CONST
3806
0
   && (opline->op2_type == IS_CONST
3807
0
    || (opline->op2_type == IS_UNUSED
3808
0
     && ((opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
3809
0
      || (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT)))
3810
0
   && EXPECTED(CACHED_PTR(cache_slot + sizeof(void *)) != NULL)) {
3811
0
    result = CACHED_PTR(cache_slot + sizeof(void *));
3812
0
    property_info = CACHED_PTR(cache_slot + sizeof(void *) * 2);
3813
3814
0
    if ((fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW)
3815
0
        && UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF)
3816
0
        && ZEND_TYPE_IS_SET(property_info->type)) {
3817
0
      zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization",
3818
0
        ZSTR_VAL(property_info->ce->name),
3819
0
        zend_get_unmangled_property_name(property_info->name));
3820
0
      return NULL;
3821
0
    }
3822
0
  } else {
3823
0
    result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC);
3824
0
    if (UNEXPECTED(!result)) {
3825
0
      return NULL;
3826
0
    }
3827
0
  }
3828
3829
0
  flags &= ZEND_FETCH_OBJ_FLAGS;
3830
0
  if (flags && ZEND_TYPE_IS_SET(property_info->type)) {
3831
0
    zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags);
3832
0
  }
3833
3834
0
  if (prop_info) {
3835
0
    *prop_info = property_info;
3836
0
  }
3837
3838
0
  return result;
3839
0
}
3840
3841
0
ZEND_API zval* ZEND_FASTCALL zend_fetch_static_property(zend_execute_data *ex, int fetch_type) {
3842
0
  zval *result;
3843
0
  zend_property_info *property_info;
3844
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3845
  zend_execute_data *orig_execute_data = execute_data;
3846
#else
3847
0
  zend_execute_data *execute_data;
3848
0
#endif
3849
0
  execute_data = ex;
3850
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3851
  const zend_op *orig_opline = opline;
3852
#else
3853
0
  const zend_op *opline;
3854
0
#endif
3855
0
  opline = execute_data->opline;
3856
3857
0
  uint32_t cache_slot = opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS;
3858
0
  uint32_t flags = 0;
3859
3860
0
  if (fetch_type == BP_VAR_W) {
3861
0
    flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS;
3862
0
  }
3863
0
  result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC);
3864
0
  if (EXPECTED(result)) {
3865
0
    if (flags && ZEND_TYPE_IS_SET(property_info->type)) {
3866
0
      zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags);
3867
0
    }
3868
0
  } else {
3869
0
    result = &EG(uninitialized_zval);
3870
0
  }
3871
3872
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3873
  EX(opline) = opline;
3874
  opline = orig_opline;
3875
#endif
3876
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3877
  execute_data = orig_execute_data;
3878
#endif
3879
3880
0
  return result;
3881
0
}
3882
3883
0
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) {
3884
0
  zend_string *type1_str = zend_type_to_string(prop1->type);
3885
0
  zend_string *type2_str = zend_type_to_string(prop2->type);
3886
0
  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",
3887
0
    zend_zval_type_name(zv),
3888
0
    ZSTR_VAL(prop1->ce->name),
3889
0
    zend_get_unmangled_property_name(prop1->name),
3890
0
    ZSTR_VAL(type1_str),
3891
0
    ZSTR_VAL(prop2->ce->name),
3892
0
    zend_get_unmangled_property_name(prop2->name),
3893
0
    ZSTR_VAL(type2_str)
3894
0
  );
3895
0
  zend_string_release(type1_str);
3896
0
  zend_string_release(type2_str);
3897
0
}
3898
3899
0
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv) {
3900
0
  zend_string *type_str = zend_type_to_string(prop->type);
3901
0
  zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s",
3902
0
    zend_zval_value_name(zv),
3903
0
    ZSTR_VAL(prop->ce->name),
3904
0
    zend_get_unmangled_property_name(prop->name),
3905
0
    ZSTR_VAL(type_str)
3906
0
  );
3907
0
  zend_string_release(type_str);
3908
0
}
3909
3910
0
ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) {
3911
0
  zend_string *type1_str = zend_type_to_string(prop1->type);
3912
0
  zend_string *type2_str = zend_type_to_string(prop2->type);
3913
0
  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",
3914
0
    zend_zval_value_name(zv),
3915
0
    ZSTR_VAL(prop1->ce->name),
3916
0
    zend_get_unmangled_property_name(prop1->name),
3917
0
    ZSTR_VAL(type1_str),
3918
0
    ZSTR_VAL(prop2->ce->name),
3919
0
    zend_get_unmangled_property_name(prop2->name),
3920
0
    ZSTR_VAL(type2_str)
3921
0
  );
3922
0
  zend_string_release(type1_str);
3923
0
  zend_string_release(type2_str);
3924
0
}
3925
3926
/* 1: valid, 0: invalid, -1: may be valid after type coercion */
3927
static zend_always_inline int i_zend_verify_type_assignable_zval(
3928
0
    const zend_property_info *info, const zval *zv, bool strict) {
3929
0
  zend_type type = info->type;
3930
0
  uint32_t type_mask;
3931
0
  uint8_t zv_type = Z_TYPE_P(zv);
3932
3933
0
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(type, zv_type))) {
3934
0
    return 1;
3935
0
  }
3936
3937
0
  if (ZEND_TYPE_IS_COMPLEX(type) && zv_type == IS_OBJECT
3938
0
      && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(zv))) {
3939
0
    return 1;
3940
0
  }
3941
3942
0
  type_mask = ZEND_TYPE_FULL_MASK(type);
3943
0
  ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC)));
3944
3945
  /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */
3946
0
  if (strict) {
3947
0
    if ((type_mask & MAY_BE_DOUBLE) && zv_type == IS_LONG) {
3948
0
      return -1;
3949
0
    }
3950
0
    return 0;
3951
0
  }
3952
3953
  /* NULL may be accepted only by nullable hints (this is already checked) */
3954
0
  if (zv_type == IS_NULL) {
3955
0
    return 0;
3956
0
  }
3957
3958
  /* Does not contain any type to which a coercion is possible */
3959
0
  if (!(type_mask & (MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING))
3960
0
      && (type_mask & MAY_BE_BOOL) != MAY_BE_BOOL) {
3961
0
    return 0;
3962
0
  }
3963
3964
  /* Coercion may be necessary, check separately */
3965
0
  return -1;
3966
0
}
3967
3968
ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict)
3969
0
{
3970
0
  const zend_property_info *prop;
3971
3972
  /* The value must satisfy each property type, and coerce to the same value for each property
3973
   * type. Remember the first coerced type and value we've seen for this purpose. */
3974
0
  const zend_property_info *first_prop = NULL;
3975
0
  zval coerced_value;
3976
0
  ZVAL_UNDEF(&coerced_value);
3977
3978
0
  ZEND_ASSERT(Z_TYPE_P(zv) != IS_REFERENCE);
3979
0
  ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
3980
0
    int result = i_zend_verify_type_assignable_zval(prop, zv, strict);
3981
0
    if (result == 0) {
3982
0
type_error:
3983
0
      zend_throw_ref_type_error_zval(prop, zv);
3984
0
      zval_ptr_dtor(&coerced_value);
3985
0
      return 0;
3986
0
    }
3987
3988
0
    if (result < 0) {
3989
0
      if (!first_prop) {
3990
0
        first_prop = prop;
3991
0
        ZVAL_COPY(&coerced_value, zv);
3992
0
        if (!zend_verify_weak_scalar_type_hint(
3993
0
            ZEND_TYPE_FULL_MASK(prop->type), &coerced_value)) {
3994
0
          goto type_error;
3995
0
        }
3996
0
      } else if (Z_ISUNDEF(coerced_value)) {
3997
        /* A previous property did not require coercion, but this one does,
3998
         * so they are incompatible. */
3999
0
        goto conflicting_coercion_error;
4000
0
      } else {
4001
0
        zval tmp;
4002
0
        ZVAL_COPY(&tmp, zv);
4003
0
        if (!zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop->type), &tmp)) {
4004
0
          zval_ptr_dtor(&tmp);
4005
0
          goto type_error;
4006
0
        }
4007
0
        if (!zend_is_identical(&coerced_value, &tmp)) {
4008
0
          zval_ptr_dtor(&tmp);
4009
0
          goto conflicting_coercion_error;
4010
0
        }
4011
0
        zval_ptr_dtor(&tmp);
4012
0
      }
4013
0
    } else {
4014
0
      if (!first_prop) {
4015
0
        first_prop = prop;
4016
0
      } else if (!Z_ISUNDEF(coerced_value)) {
4017
        /* A previous property required coercion, but this one doesn't,
4018
         * so they are incompatible. */
4019
0
conflicting_coercion_error:
4020
0
        zend_throw_conflicting_coercion_error(first_prop, prop, zv);
4021
0
        zval_ptr_dtor(&coerced_value);
4022
0
        return 0;
4023
0
      }
4024
0
    }
4025
0
  } ZEND_REF_FOREACH_TYPE_SOURCES_END();
4026
4027
0
  if (!Z_ISUNDEF(coerced_value)) {
4028
0
    zval_ptr_dtor(zv);
4029
0
    ZVAL_COPY_VALUE(zv, &coerced_value);
4030
0
  }
4031
4032
0
  return 1;
4033
0
}
4034
4035
0
static zend_always_inline void i_zval_ptr_dtor_noref(zval *zval_ptr) {
4036
0
  if (Z_REFCOUNTED_P(zval_ptr)) {
4037
0
    zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
4038
0
    ZEND_ASSERT(Z_TYPE_P(zval_ptr) != IS_REFERENCE);
4039
0
    GC_DTOR_NO_REF(ref);
4040
0
  }
4041
0
}
4042
4043
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)
4044
0
{
4045
0
  bool ret;
4046
0
  zval value;
4047
0
  zend_refcounted *ref = NULL;
4048
4049
0
  if (Z_ISREF_P(orig_value)) {
4050
0
    ref = Z_COUNTED_P(orig_value);
4051
0
    orig_value = Z_REFVAL_P(orig_value);
4052
0
  }
4053
4054
0
  ZVAL_COPY(&value, orig_value);
4055
0
  ret = zend_verify_ref_assignable_zval(Z_REF_P(variable_ptr), &value, strict);
4056
0
  variable_ptr = Z_REFVAL_P(variable_ptr);
4057
0
  if (EXPECTED(ret)) {
4058
0
    if (Z_REFCOUNTED_P(variable_ptr)) {
4059
0
      *garbage_ptr = Z_COUNTED_P(variable_ptr);
4060
0
    }
4061
0
    ZVAL_COPY_VALUE(variable_ptr, &value);
4062
0
  } else {
4063
0
    zval_ptr_dtor_nogc(&value);
4064
0
  }
4065
0
  if (value_type & (IS_VAR|IS_TMP_VAR)) {
4066
0
    if (UNEXPECTED(ref)) {
4067
0
      if (UNEXPECTED(GC_DELREF(ref) == 0)) {
4068
0
        zval_ptr_dtor(orig_value);
4069
0
        efree_size(ref, sizeof(zend_reference));
4070
0
      }
4071
0
    } else {
4072
0
      i_zval_ptr_dtor_noref(orig_value);
4073
0
    }
4074
0
  }
4075
0
  return variable_ptr;
4076
0
}
4077
4078
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict)
4079
0
{
4080
0
  zend_refcounted *garbage = NULL;
4081
0
  zval *result = zend_assign_to_typed_ref_ex(variable_ptr, orig_value, value_type, strict, &garbage);
4082
0
  if (garbage) {
4083
0
    GC_DTOR_NO_REF(garbage);
4084
0
  }
4085
0
  return result;
4086
0
}
4087
4088
0
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) {
4089
0
  zval *val = orig_val;
4090
0
  if (Z_ISREF_P(val) && ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(val))) {
4091
0
    int result;
4092
4093
0
    val = Z_REFVAL_P(val);
4094
0
    result = i_zend_verify_type_assignable_zval(prop_info, val, strict);
4095
0
    if (result > 0) {
4096
0
      return 1;
4097
0
    }
4098
4099
0
    if (result < 0) {
4100
      /* This is definitely an error, but we still need to determined why: Either because
4101
       * the value is simply illegal for the type, or because or a conflicting coercion. */
4102
0
      zval tmp;
4103
0
      ZVAL_COPY(&tmp, val);
4104
0
      if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop_info->type), &tmp)) {
4105
0
        const zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val));
4106
0
        zend_throw_ref_type_error_type(ref_prop, prop_info, val);
4107
0
        zval_ptr_dtor(&tmp);
4108
0
        return 0;
4109
0
      }
4110
0
      zval_ptr_dtor(&tmp);
4111
0
    }
4112
0
  } else {
4113
0
    ZVAL_DEREF(val);
4114
0
    if (i_zend_check_property_type(prop_info, val, strict)) {
4115
0
      return 1;
4116
0
    }
4117
0
  }
4118
4119
0
  if (EXPECTED(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT)) {
4120
0
    zend_verify_property_type_error(prop_info, val);
4121
0
  } else {
4122
0
    ZEND_ASSERT(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET);
4123
0
    zend_magic_get_property_type_inconsistency_error(prop_info, val);
4124
0
  }
4125
4126
0
  return 0;
4127
0
}
4128
4129
0
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict) {
4130
0
  return zend_verify_prop_assignable_by_ref_ex(prop_info, orig_val, strict, ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT);
4131
0
}
4132
4133
ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop)
4134
0
{
4135
0
  zend_property_info_list *list;
4136
0
  if (source_list->ptr == NULL) {
4137
0
    source_list->ptr = prop;
4138
0
    return;
4139
0
  }
4140
4141
0
  list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list);
4142
0
  if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) {
4143
0
    list = emalloc(sizeof(zend_property_info_list) + (4 - 1) * sizeof(zend_property_info *));
4144
0
    list->ptr[0] = source_list->ptr;
4145
0
    list->num_allocated = 4;
4146
0
    list->num = 1;
4147
0
  } else if (list->num_allocated == list->num) {
4148
0
    list->num_allocated = list->num * 2;
4149
0
    list = erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *));
4150
0
  }
4151
4152
0
  list->ptr[list->num++] = prop;
4153
0
  source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(list);
4154
0
}
4155
4156
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop)
4157
0
{
4158
0
  zend_property_info_list *list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list);
4159
0
  zend_property_info **ptr, **end;
4160
4161
0
  ZEND_ASSERT(prop);
4162
0
  if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) {
4163
0
    ZEND_ASSERT(source_list->ptr == prop);
4164
0
    source_list->ptr = NULL;
4165
0
    return;
4166
0
  }
4167
4168
0
  if (list->num == 1) {
4169
0
    ZEND_ASSERT(*list->ptr == prop);
4170
0
    efree(list);
4171
0
    source_list->ptr = NULL;
4172
0
    return;
4173
0
  }
4174
4175
  /* Checking against end here to get a more graceful failure mode if we missed adding a type
4176
   * source at some point. */
4177
0
  ptr = list->ptr;
4178
0
  end = ptr + list->num;
4179
0
  while (ptr < end && *ptr != prop) {
4180
0
    ptr++;
4181
0
  }
4182
0
  ZEND_ASSERT(*ptr == prop);
4183
4184
  /* Copy the last list element into the deleted slot. */
4185
0
  *ptr = list->ptr[--list->num];
4186
4187
0
  if (list->num >= 4 && list->num * 4 == list->num_allocated) {
4188
0
    list->num_allocated = list->num * 2;
4189
0
    source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *)));
4190
0
  }
4191
0
}
4192
4193
static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DATA_DC)
4194
0
{
4195
0
  zval *result = EX_VAR(opline->result.var);
4196
4197
0
  switch (type) {
4198
0
    case BP_VAR_R:
4199
0
      if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
4200
0
        ZVAL_OBJ(result, Z_OBJ(EX(This)));
4201
0
        Z_ADDREF_P(result);
4202
0
      } else {
4203
0
        ZVAL_NULL(result);
4204
0
        zend_error_unchecked(E_WARNING, "Undefined variable $this");
4205
0
      }
4206
0
      break;
4207
0
    case BP_VAR_IS:
4208
0
      if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
4209
0
        ZVAL_OBJ(result, Z_OBJ(EX(This)));
4210
0
        Z_ADDREF_P(result);
4211
0
      } else {
4212
0
        ZVAL_NULL(result);
4213
0
      }
4214
0
      break;
4215
0
    case BP_VAR_RW:
4216
0
    case BP_VAR_W:
4217
0
      ZVAL_UNDEF(result);
4218
0
      zend_throw_error(NULL, "Cannot re-assign $this");
4219
0
      break;
4220
0
    case BP_VAR_UNSET:
4221
0
      ZVAL_UNDEF(result);
4222
0
      zend_throw_error(NULL, "Cannot unset $this");
4223
0
      break;
4224
0
    EMPTY_SWITCH_DEFAULT_CASE()
4225
0
  }
4226
0
}
4227
4228
#if ZEND_INTENSIVE_DEBUGGING
4229
4230
#define CHECK_SYMBOL_TABLES()                         \
4231
  zend_hash_apply(&EG(symbol_table), zend_check_symbol);      \
4232
  if (&EG(symbol_table)!=EX(symbol_table)) {              \
4233
    zend_hash_apply(EX(symbol_table), zend_check_symbol); \
4234
  }
4235
4236
static void zend_check_symbol(zval *pz)
4237
{
4238
  if (Z_TYPE_P(pz) == IS_INDIRECT) {
4239
    pz = Z_INDIRECT_P(pz);
4240
  }
4241
  if (Z_TYPE_P(pz) > 10) {
4242
    fprintf(stderr, "Warning!  %x has invalid type!\n", *pz);
4243
/* See http://support.microsoft.com/kb/190351 */
4244
#ifdef ZEND_WIN32
4245
    fflush(stderr);
4246
#endif
4247
  } else if (Z_TYPE_P(pz) == IS_ARRAY) {
4248
    zend_hash_apply(Z_ARRVAL_P(pz), zend_check_symbol);
4249
  } else if (Z_TYPE_P(pz) == IS_OBJECT) {
4250
    /* OBJ-TBI - doesn't support new object model! */
4251
    zend_hash_apply(Z_OBJPROP_P(pz), zend_check_symbol);
4252
  }
4253
}
4254
4255
4256
#else
4257
#define CHECK_SYMBOL_TABLES()
4258
#endif
4259
4260
ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value)
4261
0
{
4262
0
  execute_data->func->internal_function.handler(execute_data, return_value);
4263
0
}
4264
4265
ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table) /* {{{ */
4266
0
{
4267
  /* Clean before putting into the cache, since clean could call dtors,
4268
   * which could use the cached hash. Also do this before the check for
4269
   * available cache slots, as those may be used by a dtor as well. */
4270
0
  zend_symtable_clean(symbol_table);
4271
0
  if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) {
4272
0
    zend_array_destroy(symbol_table);
4273
0
  } else {
4274
0
    *(EG(symtable_cache_ptr)++) = symbol_table;
4275
0
  }
4276
0
}
4277
/* }}} */
4278
4279
static zend_always_inline void i_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */
4280
0
{
4281
0
  zval *cv = EX_VAR_NUM(0);
4282
0
  int count = EX(func)->op_array.last_var;
4283
0
  while (EXPECTED(count != 0)) {
4284
0
    i_zval_ptr_dtor(cv);
4285
0
    cv++;
4286
0
    count--;
4287
0
  }
4288
0
}
4289
/* }}} */
4290
4291
ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */
4292
0
{
4293
0
  i_free_compiled_variables(execute_data);
4294
0
}
4295
/* }}} */
4296
4297
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data *call)
4298
0
{
4299
0
  zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
4300
0
  if (zend_atomic_bool_load_ex(&EG(timed_out))) {
4301
0
    zend_timeout();
4302
0
  } else if (zend_interrupt_function) {
4303
0
    zend_interrupt_function(call);
4304
0
  }
4305
0
}
4306
4307
0
#define ZEND_VM_INTERRUPT_CHECK() do { \
4308
0
    if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
4309
0
      ZEND_VM_INTERRUPT(); \
4310
0
    } \
4311
0
  } while (0)
4312
4313
0
#define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \
4314
0
    if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
4315
0
      ZEND_VM_LOOP_INTERRUPT(); \
4316
0
    } \
4317
0
  } while (0)
4318
4319
0
#define ZEND_VM_FCALL_INTERRUPT_CHECK(call) do { \
4320
0
    if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
4321
0
      zend_fcall_interrupt(call); \
4322
0
    } \
4323
0
  } while (0)
4324
4325
/*
4326
 * Stack Frame Layout (the whole stack frame is allocated at once)
4327
 * ==================
4328
 *
4329
 *                             +========================================+
4330
 * EG(current_execute_data) -> | zend_execute_data                      |
4331
 *                             +----------------------------------------+
4332
 *     EX_VAR_NUM(0) --------> | VAR[0] = ARG[1]                        |
4333
 *                             | ...                                    |
4334
 *                             | VAR[op_array->num_args-1] = ARG[N]     |
4335
 *                             | ...                                    |
4336
 *                             | VAR[op_array->last_var-1]              |
4337
 *                             | VAR[op_array->last_var] = TMP[0]       |
4338
 *                             | ...                                    |
4339
 *                             | VAR[op_array->last_var+op_array->T-1]  |
4340
 *                             | ARG[N+1] (extra_args)                  |
4341
 *                             | ...                                    |
4342
 *                             +----------------------------------------+
4343
 */
4344
4345
/* zend_copy_extra_args is used when the actually passed number of arguments
4346
 * (EX_NUM_ARGS) is greater than what the function defined (op_array->num_args).
4347
 *
4348
 * The extra arguments will be copied into the call frame after all the compiled variables.
4349
 *
4350
 * If there are extra arguments copied, a flag "ZEND_CALL_FREE_EXTRA_ARGS" will be set
4351
 * on the zend_execute_data, and when the executor leaves the function, the
4352
 * args will be freed in zend_leave_helper.
4353
 */
4354
static zend_never_inline void zend_copy_extra_args(EXECUTE_DATA_D)
4355
0
{
4356
0
  const zend_op_array *op_array = &EX(func)->op_array;
4357
0
  uint32_t first_extra_arg = op_array->num_args;
4358
0
  uint32_t num_args = EX_NUM_ARGS();
4359
0
  zval *src;
4360
0
  size_t delta;
4361
0
  uint32_t count;
4362
0
  uint32_t type_flags = 0;
4363
4364
0
  if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
4365
    /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
4366
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4367
    opline += first_extra_arg;
4368
#else
4369
0
    EX(opline) += first_extra_arg;
4370
0
#endif
4371
4372
0
  }
4373
4374
  /* move extra args into separate array after all CV and TMP vars */
4375
0
  src = EX_VAR_NUM(num_args - 1);
4376
0
  delta = op_array->last_var + op_array->T - first_extra_arg;
4377
0
  count = num_args - first_extra_arg;
4378
0
  if (EXPECTED(delta != 0)) {
4379
0
    delta *= sizeof(zval);
4380
0
    do {
4381
0
      type_flags |= Z_TYPE_INFO_P(src);
4382
0
      ZVAL_COPY_VALUE((zval*)(((char*)src) + delta), src);
4383
0
      ZVAL_UNDEF(src);
4384
0
      src--;
4385
0
    } while (--count);
4386
0
    if (Z_TYPE_INFO_REFCOUNTED(type_flags)) {
4387
0
      ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS);
4388
0
    }
4389
0
  } else {
4390
0
    do {
4391
0
      if (Z_REFCOUNTED_P(src)) {
4392
0
        ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS);
4393
0
        break;
4394
0
      }
4395
0
      src--;
4396
0
    } while (--count);
4397
0
  }
4398
0
}
4399
4400
static zend_always_inline void zend_init_cvs(uint32_t first, uint32_t last EXECUTE_DATA_DC)
4401
0
{
4402
0
  if (EXPECTED(first < last)) {
4403
0
    uint32_t count = last - first;
4404
0
    zval *var = EX_VAR_NUM(first);
4405
4406
0
    do {
4407
0
      ZVAL_UNDEF(var);
4408
0
      var++;
4409
0
    } while (--count);
4410
0
  }
4411
0
}
4412
4413
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) /* {{{ */
4414
0
{
4415
0
  uint32_t first_extra_arg, num_args;
4416
0
  ZEND_ASSERT(EX(func) == (zend_function*)op_array);
4417
4418
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4419
  opline = op_array->opcodes;
4420
#else
4421
0
  EX(opline) = op_array->opcodes;
4422
0
#endif
4423
0
  EX(call) = NULL;
4424
0
  EX(return_value) = return_value;
4425
4426
  /* Handle arguments */
4427
0
  first_extra_arg = op_array->num_args;
4428
0
  num_args = EX_NUM_ARGS();
4429
0
  if (UNEXPECTED(num_args > first_extra_arg)) {
4430
0
    if (!may_be_trampoline || EXPECTED(!(op_array->fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) {
4431
0
      zend_copy_extra_args(EXECUTE_DATA_C);
4432
0
    }
4433
0
  } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
4434
    /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
4435
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4436
    opline += num_args;
4437
#else
4438
0
    EX(opline) += num_args;
4439
0
#endif
4440
0
  }
4441
4442
  /* Initialize CV variables (skip arguments) */
4443
0
  zend_init_cvs(num_args, op_array->last_var EXECUTE_DATA_CC);
4444
4445
0
  EX(run_time_cache) = RUN_TIME_CACHE(op_array);
4446
4447
0
  EG(current_execute_data) = execute_data;
4448
0
}
4449
/* }}} */
4450
4451
static zend_always_inline void init_func_run_time_cache_i(zend_op_array *op_array) /* {{{ */
4452
0
{
4453
0
  void **run_time_cache;
4454
4455
0
  ZEND_ASSERT(RUN_TIME_CACHE(op_array) == NULL);
4456
0
  run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size);
4457
0
  memset(run_time_cache, 0, op_array->cache_size);
4458
0
  ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache);
4459
0
}
4460
/* }}} */
4461
4462
static zend_never_inline void ZEND_FASTCALL init_func_run_time_cache(zend_op_array *op_array) /* {{{ */
4463
0
{
4464
0
  init_func_run_time_cache_i(op_array);
4465
0
}
4466
/* }}} */
4467
4468
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /* {{{ */
4469
0
{
4470
0
  zval *zv = zend_hash_find(EG(function_table), name);
4471
4472
0
  if (EXPECTED(zv != NULL)) {
4473
0
    zend_function *fbc = Z_FUNC_P(zv);
4474
4475
0
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
4476
0
      init_func_run_time_cache_i(&fbc->op_array);
4477
0
    }
4478
0
    return fbc;
4479
0
  }
4480
0
  return NULL;
4481
0
} /* }}} */
4482
4483
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len) /* {{{ */
4484
0
{
4485
0
  zval *zv = zend_hash_str_find(EG(function_table), name, len);
4486
4487
0
  if (EXPECTED(zv != NULL)) {
4488
0
    zend_function *fbc = Z_FUNC_P(zv);
4489
4490
0
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
4491
0
      init_func_run_time_cache_i(&fbc->op_array);
4492
0
    }
4493
0
    return fbc;
4494
0
  }
4495
0
  return NULL;
4496
0
} /* }}} */
4497
4498
ZEND_API void ZEND_FASTCALL zend_init_func_run_time_cache(zend_op_array *op_array) /* {{{ */
4499
0
{
4500
0
  if (!RUN_TIME_CACHE(op_array)) {
4501
0
    init_func_run_time_cache_i(op_array);
4502
0
  }
4503
0
} /* }}} */
4504
4505
static zend_always_inline void i_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
4506
0
{
4507
0
  ZEND_ASSERT(EX(func) == (zend_function*)op_array);
4508
4509
0
  EX(opline) = op_array->opcodes;
4510
0
  EX(call) = NULL;
4511
0
  EX(return_value) = return_value;
4512
4513
0
  if (op_array->last_var) {
4514
0
    zend_attach_symbol_table(execute_data);
4515
0
  }
4516
4517
0
  if (!ZEND_MAP_PTR(op_array->run_time_cache)) {
4518
0
    void *ptr;
4519
4520
0
    ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_HEAP_RT_CACHE);
4521
0
    ptr = emalloc(op_array->cache_size);
4522
0
    ZEND_MAP_PTR_INIT(op_array->run_time_cache, ptr);
4523
0
    memset(ptr, 0, op_array->cache_size);
4524
0
  }
4525
0
  EX(run_time_cache) = RUN_TIME_CACHE(op_array);
4526
4527
0
  EG(current_execute_data) = execute_data;
4528
0
}
4529
/* }}} */
4530
4531
ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *op_array, zval *return_value) /* {{{ */
4532
0
{
4533
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4534
  zend_execute_data *orig_execute_data = execute_data;
4535
#endif
4536
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4537
  const zend_op *orig_opline = opline;
4538
#endif
4539
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4540
  execute_data = ex;
4541
#else
4542
0
  zend_execute_data *execute_data = ex;
4543
0
#endif
4544
4545
0
  EX(prev_execute_data) = EG(current_execute_data);
4546
0
  if (!RUN_TIME_CACHE(op_array)) {
4547
0
    init_func_run_time_cache(op_array);
4548
0
  }
4549
0
  i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC);
4550
4551
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4552
  EX(opline) = opline;
4553
  opline = orig_opline;
4554
#endif
4555
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4556
  execute_data = orig_execute_data;
4557
#endif
4558
0
}
4559
/* }}} */
4560
4561
ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
4562
0
{
4563
0
  EX(prev_execute_data) = EG(current_execute_data);
4564
0
  i_init_code_execute_data(execute_data, op_array, return_value);
4565
0
}
4566
/* }}} */
4567
4568
ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
4569
0
{
4570
0
  if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) {
4571
0
    zend_init_code_execute_data(execute_data, op_array, return_value);
4572
0
  } else {
4573
0
    zend_init_func_execute_data(execute_data, op_array, return_value);
4574
0
  }
4575
0
}
4576
/* }}} */
4577
4578
zend_execute_data *zend_vm_stack_copy_call_frame(zend_execute_data *call, uint32_t passed_args, uint32_t additional_args) /* {{{ */
4579
0
{
4580
0
  zend_execute_data *new_call;
4581
0
  int used_stack = (EG(vm_stack_top) - (zval*)call) + additional_args;
4582
4583
  /* copy call frame into new stack segment */
4584
0
  new_call = zend_vm_stack_extend(used_stack * sizeof(zval));
4585
0
  *new_call = *call;
4586
0
  ZEND_ADD_CALL_FLAG(new_call, ZEND_CALL_ALLOCATED);
4587
4588
0
  if (passed_args) {
4589
0
    zval *src = ZEND_CALL_ARG(call, 1);
4590
0
    zval *dst = ZEND_CALL_ARG(new_call, 1);
4591
0
    do {
4592
0
      ZVAL_COPY_VALUE(dst, src);
4593
0
      passed_args--;
4594
0
      src++;
4595
0
      dst++;
4596
0
    } while (passed_args);
4597
0
  }
4598
4599
  /* delete old call_frame from previous stack segment */
4600
0
  EG(vm_stack)->prev->top = (zval*)call;
4601
4602
  /* delete previous stack segment if it became empty */
4603
0
  if (UNEXPECTED(EG(vm_stack)->prev->top == ZEND_VM_STACK_ELEMENTS(EG(vm_stack)->prev))) {
4604
0
    zend_vm_stack r = EG(vm_stack)->prev;
4605
4606
0
    EG(vm_stack)->prev = r->prev;
4607
0
    efree(r);
4608
0
  }
4609
4610
0
  return new_call;
4611
0
}
4612
/* }}} */
4613
4614
static zend_always_inline zend_generator *zend_get_running_generator(EXECUTE_DATA_D) /* {{{ */
4615
0
{
4616
  /* The generator object is stored in EX(return_value) */
4617
0
  zend_generator *generator = (zend_generator *) EX(return_value);
4618
  /* However control may currently be delegated to another generator.
4619
   * That's the one we're interested in. */
4620
0
  return generator;
4621
0
}
4622
/* }}} */
4623
4624
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) /* {{{ */
4625
0
{
4626
0
  zend_op *opline = EX(func)->op_array.opcodes + op_num;
4627
0
  int level;
4628
0
  int do_exit;
4629
0
  uint32_t num_args;
4630
4631
0
  if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL ||
4632
0
    opline->opcode == ZEND_INIT_FCALL_BY_NAME ||
4633
0
    opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME ||
4634
0
    opline->opcode == ZEND_INIT_DYNAMIC_CALL ||
4635
0
    opline->opcode == ZEND_INIT_USER_CALL ||
4636
0
    opline->opcode == ZEND_INIT_METHOD_CALL ||
4637
0
    opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
4638
0
    opline->opcode == ZEND_NEW)) {
4639
0
    ZEND_ASSERT(op_num);
4640
0
    opline--;
4641
0
  }
4642
4643
0
  do {
4644
    /* find the number of actually passed arguments */
4645
0
    level = 0;
4646
0
    do_exit = 0;
4647
0
    num_args = ZEND_CALL_NUM_ARGS(call);
4648
0
    do {
4649
0
      switch (opline->opcode) {
4650
0
        case ZEND_DO_FCALL:
4651
0
        case ZEND_DO_ICALL:
4652
0
        case ZEND_DO_UCALL:
4653
0
        case ZEND_DO_FCALL_BY_NAME:
4654
0
        case ZEND_CALLABLE_CONVERT:
4655
0
          level++;
4656
0
          break;
4657
0
        case ZEND_INIT_FCALL:
4658
0
        case ZEND_INIT_FCALL_BY_NAME:
4659
0
        case ZEND_INIT_NS_FCALL_BY_NAME:
4660
0
        case ZEND_INIT_DYNAMIC_CALL:
4661
0
        case ZEND_INIT_USER_CALL:
4662
0
        case ZEND_INIT_METHOD_CALL:
4663
0
        case ZEND_INIT_STATIC_METHOD_CALL:
4664
0
        case ZEND_NEW:
4665
0
          if (level == 0) {
4666
0
            num_args = 0;
4667
0
            do_exit = 1;
4668
0
          }
4669
0
          level--;
4670
0
          break;
4671
0
        case ZEND_SEND_VAL:
4672
0
        case ZEND_SEND_VAL_EX:
4673
0
        case ZEND_SEND_VAR:
4674
0
        case ZEND_SEND_VAR_EX:
4675
0
        case ZEND_SEND_FUNC_ARG:
4676
0
        case ZEND_SEND_REF:
4677
0
        case ZEND_SEND_VAR_NO_REF:
4678
0
        case ZEND_SEND_VAR_NO_REF_EX:
4679
0
        case ZEND_SEND_USER:
4680
0
          if (level == 0) {
4681
            /* For named args, the number of arguments is up to date. */
4682
0
            if (opline->op2_type != IS_CONST) {
4683
0
              num_args = opline->op2.num;
4684
0
            }
4685
0
            do_exit = 1;
4686
0
          }
4687
0
          break;
4688
0
        case ZEND_SEND_ARRAY:
4689
0
        case ZEND_SEND_UNPACK:
4690
0
        case ZEND_CHECK_UNDEF_ARGS:
4691
0
          if (level == 0) {
4692
0
            do_exit = 1;
4693
0
          }
4694
0
          break;
4695
0
      }
4696
0
      if (!do_exit) {
4697
0
        opline--;
4698
0
      }
4699
0
    } while (!do_exit);
4700
0
    if (call->prev_execute_data) {
4701
      /* skip current call region */
4702
0
      level = 0;
4703
0
      do_exit = 0;
4704
0
      do {
4705
0
        switch (opline->opcode) {
4706
0
          case ZEND_DO_FCALL:
4707
0
          case ZEND_DO_ICALL:
4708
0
          case ZEND_DO_UCALL:
4709
0
          case ZEND_DO_FCALL_BY_NAME:
4710
0
          case ZEND_CALLABLE_CONVERT:
4711
0
            level++;
4712
0
            break;
4713
0
          case ZEND_INIT_FCALL:
4714
0
          case ZEND_INIT_FCALL_BY_NAME:
4715
0
          case ZEND_INIT_NS_FCALL_BY_NAME:
4716
0
          case ZEND_INIT_DYNAMIC_CALL:
4717
0
          case ZEND_INIT_USER_CALL:
4718
0
          case ZEND_INIT_METHOD_CALL:
4719
0
          case ZEND_INIT_STATIC_METHOD_CALL:
4720
0
          case ZEND_NEW:
4721
0
            if (level == 0) {
4722
0
              do_exit = 1;
4723
0
            }
4724
0
            level--;
4725
0
            break;
4726
0
        }
4727
0
        opline--;
4728
0
      } while (!do_exit);
4729
0
    }
4730
4731
0
    if (EXPECTED(num_args > 0)) {
4732
0
      zval *p = ZEND_CALL_ARG(call, 1);
4733
0
      do {
4734
0
        zend_get_gc_buffer_add_zval(buf, p);
4735
0
        p++;
4736
0
      } while (--num_args);
4737
0
    }
4738
0
    if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) {
4739
0
      zend_get_gc_buffer_add_obj(buf, Z_OBJ(call->This));
4740
0
    }
4741
0
    if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
4742
0
      zval *val;
4743
0
      ZEND_HASH_FOREACH_VAL(call->extra_named_params, val) {
4744
0
        zend_get_gc_buffer_add_zval(buf, val);
4745
0
      } ZEND_HASH_FOREACH_END();
4746
0
    }
4747
0
    if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) {
4748
0
      zend_get_gc_buffer_add_obj(buf, ZEND_CLOSURE_OBJECT(call->func));
4749
0
    }
4750
4751
0
    call = call->prev_execute_data;
4752
0
  } while (call);
4753
0
}
4754
/* }}} */
4755
4756
static void cleanup_unfinished_calls(zend_execute_data *execute_data, uint32_t op_num) /* {{{ */
4757
0
{
4758
0
  if (UNEXPECTED(EX(call))) {
4759
0
    zend_execute_data *call = EX(call);
4760
0
    zend_op *opline = EX(func)->op_array.opcodes + op_num;
4761
0
    int level;
4762
0
    int do_exit;
4763
4764
0
    if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL ||
4765
0
      opline->opcode == ZEND_INIT_FCALL_BY_NAME ||
4766
0
      opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME ||
4767
0
      opline->opcode == ZEND_INIT_DYNAMIC_CALL ||
4768
0
      opline->opcode == ZEND_INIT_USER_CALL ||
4769
0
      opline->opcode == ZEND_INIT_METHOD_CALL ||
4770
0
      opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
4771
0
      opline->opcode == ZEND_INIT_PARENT_PROPERTY_HOOK_CALL ||
4772
0
      opline->opcode == ZEND_NEW)) {
4773
0
      ZEND_ASSERT(op_num);
4774
0
      opline--;
4775
0
    }
4776
4777
0
    do {
4778
      /* If the exception was thrown during a function call there might be
4779
       * arguments pushed to the stack that have to be dtor'ed. */
4780
4781
      /* find the number of actually passed arguments */
4782
0
      level = 0;
4783
0
      do_exit = 0;
4784
0
      do {
4785
0
        switch (opline->opcode) {
4786
0
          case ZEND_DO_FCALL:
4787
0
          case ZEND_DO_ICALL:
4788
0
          case ZEND_DO_UCALL:
4789
0
          case ZEND_DO_FCALL_BY_NAME:
4790
0
          case ZEND_CALLABLE_CONVERT:
4791
0
            level++;
4792
0
            break;
4793
0
          case ZEND_INIT_FCALL:
4794
0
          case ZEND_INIT_FCALL_BY_NAME:
4795
0
          case ZEND_INIT_NS_FCALL_BY_NAME:
4796
0
          case ZEND_INIT_DYNAMIC_CALL:
4797
0
          case ZEND_INIT_USER_CALL:
4798
0
          case ZEND_INIT_METHOD_CALL:
4799
0
          case ZEND_INIT_STATIC_METHOD_CALL:
4800
0
          case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
4801
0
          case ZEND_NEW:
4802
0
            if (level == 0) {
4803
0
              ZEND_CALL_NUM_ARGS(call) = 0;
4804
0
              do_exit = 1;
4805
0
            }
4806
0
            level--;
4807
0
            break;
4808
0
          case ZEND_SEND_VAL:
4809
0
          case ZEND_SEND_VAL_EX:
4810
0
          case ZEND_SEND_VAR:
4811
0
          case ZEND_SEND_VAR_EX:
4812
0
          case ZEND_SEND_FUNC_ARG:
4813
0
          case ZEND_SEND_REF:
4814
0
          case ZEND_SEND_VAR_NO_REF:
4815
0
          case ZEND_SEND_VAR_NO_REF_EX:
4816
0
          case ZEND_SEND_USER:
4817
0
            if (level == 0) {
4818
              /* For named args, the number of arguments is up to date. */
4819
0
              if (opline->op2_type != IS_CONST) {
4820
0
                ZEND_CALL_NUM_ARGS(call) = opline->op2.num;
4821
0
              }
4822
0
              do_exit = 1;
4823
0
            }
4824
0
            break;
4825
0
          case ZEND_SEND_ARRAY:
4826
0
          case ZEND_SEND_UNPACK:
4827
0
          case ZEND_CHECK_UNDEF_ARGS:
4828
0
            if (level == 0) {
4829
0
              do_exit = 1;
4830
0
            }
4831
0
            break;
4832
0
        }
4833
0
        if (!do_exit) {
4834
0
          opline--;
4835
0
        }
4836
0
      } while (!do_exit);
4837
0
      if (call->prev_execute_data) {
4838
        /* skip current call region */
4839
0
        level = 0;
4840
0
        do_exit = 0;
4841
0
        do {
4842
0
          switch (opline->opcode) {
4843
0
            case ZEND_DO_FCALL:
4844
0
            case ZEND_DO_ICALL:
4845
0
            case ZEND_DO_UCALL:
4846
0
            case ZEND_DO_FCALL_BY_NAME:
4847
0
            case ZEND_CALLABLE_CONVERT:
4848
0
              level++;
4849
0
              break;
4850
0
            case ZEND_INIT_FCALL:
4851
0
            case ZEND_INIT_FCALL_BY_NAME:
4852
0
            case ZEND_INIT_NS_FCALL_BY_NAME:
4853
0
            case ZEND_INIT_DYNAMIC_CALL:
4854
0
            case ZEND_INIT_USER_CALL:
4855
0
            case ZEND_INIT_METHOD_CALL:
4856
0
            case ZEND_INIT_STATIC_METHOD_CALL:
4857
0
            case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
4858
0
            case ZEND_NEW:
4859
0
              if (level == 0) {
4860
0
                do_exit = 1;
4861
0
              }
4862
0
              level--;
4863
0
              break;
4864
0
          }
4865
0
          opline--;
4866
0
        } while (!do_exit);
4867
0
      }
4868
4869
0
      zend_vm_stack_free_args(EX(call));
4870
4871
0
      if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) {
4872
0
        OBJ_RELEASE(Z_OBJ(call->This));
4873
0
      }
4874
0
      if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
4875
0
        zend_free_extra_named_params(call->extra_named_params);
4876
0
      }
4877
0
      if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) {
4878
0
        zend_object_release(ZEND_CLOSURE_OBJECT(call->func));
4879
0
      } else if (call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
4880
0
        zend_string_release_ex(call->func->common.function_name, 0);
4881
0
        zend_free_trampoline(call->func);
4882
0
      }
4883
4884
0
      EX(call) = call->prev_execute_data;
4885
0
      zend_vm_stack_free_call_frame(call);
4886
0
      call = EX(call);
4887
0
    } while (call);
4888
0
  }
4889
0
}
4890
/* }}} */
4891
4892
static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) /* {{{ */
4893
0
{
4894
0
  int i;
4895
4896
0
  for (i = 0; i < EX(func)->op_array.last_live_range; i++) {
4897
0
    const zend_live_range *range = &EX(func)->op_array.live_range[i];
4898
0
    if (range->start > op_num) {
4899
      /* further blocks will not be relevant... */
4900
0
      break;
4901
0
    } else if (op_num < range->end) {
4902
0
      if (!catch_op_num || catch_op_num >= range->end) {
4903
0
        uint32_t kind = range->var & ZEND_LIVE_MASK;
4904
0
        uint32_t var_num = range->var & ~ZEND_LIVE_MASK;
4905
0
        zval *var = EX_VAR(var_num);
4906
4907
        /* Handle the split range for loop vars */
4908
0
        if (catch_op_num) {
4909
0
          zend_op *final_op = EX(func)->op_array.opcodes + range->end;
4910
0
          if (final_op->extended_value & ZEND_FREE_ON_RETURN && (final_op->opcode == ZEND_FE_FREE || final_op->opcode == ZEND_FREE)) {
4911
0
            if (catch_op_num < range->end + final_op->op2.num) {
4912
0
              continue;
4913
0
            }
4914
0
          }
4915
0
        }
4916
4917
0
        if (kind == ZEND_LIVE_TMPVAR) {
4918
0
          zval_ptr_dtor_nogc(var);
4919
0
        } else if (kind == ZEND_LIVE_NEW) {
4920
0
          zend_object *obj;
4921
0
          ZEND_ASSERT(Z_TYPE_P(var) == IS_OBJECT);
4922
0
          obj = Z_OBJ_P(var);
4923
0
          zend_object_store_ctor_failed(obj);
4924
0
          OBJ_RELEASE(obj);
4925
0
        } else if (kind == ZEND_LIVE_LOOP) {
4926
0
          if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) {
4927
0
            zend_hash_iterator_del(Z_FE_ITER_P(var));
4928
0
          }
4929
0
          zval_ptr_dtor_nogc(var);
4930
0
        } else if (kind == ZEND_LIVE_ROPE) {
4931
0
          zend_string **rope = (zend_string **)var;
4932
0
          const zend_op *last = EX(func)->op_array.opcodes + op_num;
4933
0
          while ((last->opcode != ZEND_ROPE_ADD && last->opcode != ZEND_ROPE_INIT)
4934
0
              || last->result.var != var_num) {
4935
0
            ZEND_ASSERT(last >= EX(func)->op_array.opcodes);
4936
0
            last--;
4937
0
          }
4938
0
          if (last->opcode == ZEND_ROPE_INIT) {
4939
0
            zend_string_release_ex(*rope, 0);
4940
0
          } else {
4941
0
            uint32_t j = last->extended_value;
4942
0
            do {
4943
0
              zend_string_release_ex(rope[j], 0);
4944
0
            } while (j--);
4945
0
          }
4946
0
        } else if (kind == ZEND_LIVE_SILENCE) {
4947
          /* restore previous error_reporting value */
4948
0
          if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
4949
0
              && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) {
4950
0
            EG(error_reporting) = Z_LVAL_P(var);
4951
0
          }
4952
0
        }
4953
0
      }
4954
0
    }
4955
0
  }
4956
0
}
4957
/* }}} */
4958
4959
0
ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) {
4960
0
  cleanup_unfinished_calls(execute_data, op_num);
4961
0
  cleanup_live_vars(execute_data, op_num, catch_op_num);
4962
0
}
4963
4964
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)
4965
0
{
4966
0
  return zend_unfinished_execution_gc_ex(execute_data, call, gc_buffer, false);
4967
0
}
4968
4969
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)
4970
0
{
4971
0
  if (!EX(func)) {
4972
0
    return NULL;
4973
0
  }
4974
4975
0
  if (EX_CALL_INFO() & ZEND_CALL_RELEASE_THIS) {
4976
0
    zend_get_gc_buffer_add_obj(gc_buffer, Z_OBJ(execute_data->This));
4977
0
  }
4978
4979
0
  if (EX_CALL_INFO() & ZEND_CALL_CLOSURE) {
4980
0
    zend_get_gc_buffer_add_obj(gc_buffer, ZEND_CLOSURE_OBJECT(EX(func)));
4981
0
  }
4982
4983
0
  if (!ZEND_USER_CODE(EX(func)->common.type)) {
4984
0
    ZEND_ASSERT(!(EX_CALL_INFO() & (ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)));
4985
0
    return NULL;
4986
0
  }
4987
4988
0
  const zend_op_array *op_array = &EX(func)->op_array;
4989
4990
0
  if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
4991
0
    uint32_t i, num_cvs = EX(func)->op_array.last_var;
4992
0
    for (i = 0; i < num_cvs; i++) {
4993
0
      zend_get_gc_buffer_add_zval(gc_buffer, EX_VAR_NUM(i));
4994
0
    }
4995
0
  }
4996
4997
0
  if (EX_CALL_INFO() & ZEND_CALL_FREE_EXTRA_ARGS) {
4998
0
    zval *zv = EX_VAR_NUM(op_array->last_var + op_array->T);
4999
0
    const zval *end = zv + (EX_NUM_ARGS() - op_array->num_args);
5000
0
    while (zv != end) {
5001
0
      zend_get_gc_buffer_add_zval(gc_buffer, zv++);
5002
0
    }
5003
0
  }
5004
5005
0
  if (EX_CALL_INFO() & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
5006
0
    zval extra_named_params;
5007
0
    ZVAL_ARR(&extra_named_params, EX(extra_named_params));
5008
0
    zend_get_gc_buffer_add_zval(gc_buffer, &extra_named_params);
5009
0
  }
5010
5011
0
  uint32_t op_num;
5012
0
  if (UNEXPECTED(execute_data->opline->opcode == ZEND_HANDLE_EXCEPTION)) {
5013
0
    op_num = EG(opline_before_exception) - op_array->opcodes;
5014
0
  } else {
5015
0
    op_num = execute_data->opline - op_array->opcodes;
5016
0
  }
5017
0
  ZEND_ASSERT(op_num < op_array->last);
5018
5019
0
  if (call) {
5020
0
    zend_unfinished_calls_gc(execute_data, call, op_num, gc_buffer);
5021
0
  }
5022
5023
0
  if (execute_data->opline != op_array->opcodes) {
5024
0
    uint32_t i;
5025
0
    for (i = 0; i < op_array->last_live_range; i++) {
5026
0
      const zend_live_range *range = &op_array->live_range[i];
5027
0
      if (range->start > op_num) {
5028
0
        break;
5029
0
      } else if (op_num < range->end) {
5030
0
        uint32_t kind = range->var & ZEND_LIVE_MASK;
5031
0
        uint32_t var_num = range->var & ~ZEND_LIVE_MASK;
5032
0
        zval *var = EX_VAR(var_num);
5033
0
        if (kind == ZEND_LIVE_TMPVAR || kind == ZEND_LIVE_LOOP) {
5034
0
          zend_get_gc_buffer_add_zval(gc_buffer, var);
5035
0
        }
5036
0
      }
5037
0
    }
5038
0
  }
5039
5040
0
  if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) {
5041
0
    return execute_data->symbol_table;
5042
0
  } else {
5043
0
    return NULL;
5044
0
  }
5045
0
}
5046
5047
#if ZEND_VM_SPEC
5048
static void zend_swap_operands(zend_op *op) /* {{{ */
5049
140k
{
5050
140k
  znode_op     tmp;
5051
140k
  uint8_t   tmp_type;
5052
5053
140k
  tmp          = op->op1;
5054
140k
  tmp_type     = op->op1_type;
5055
140k
  op->op1      = op->op2;
5056
140k
  op->op1_type = op->op2_type;
5057
140k
  op->op2      = tmp;
5058
140k
  op->op2_type = tmp_type;
5059
5060
#ifdef ZEND_VERIFY_TYPE_INFERENCE
5061
  uint32_t tmp_info;
5062
  tmp_info = op->op1_use_type;
5063
  op->op1_use_type = op->op2_use_type;
5064
  op->op2_use_type = tmp_info;
5065
  tmp_info = op->op1_def_type;
5066
  op->op1_def_type = op->op2_def_type;
5067
  op->op2_def_type = tmp_info;
5068
#endif
5069
140k
}
5070
/* }}} */
5071
#endif
5072
5073
static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_string *function, uint32_t num_args) /* {{{ */
5074
0
{
5075
0
  zend_function *fbc;
5076
0
  zval *func;
5077
0
  zend_class_entry *called_scope;
5078
0
  zend_string *lcname;
5079
0
  const char *colon;
5080
5081
0
  if ((colon = zend_memrchr(ZSTR_VAL(function), ':', ZSTR_LEN(function))) != NULL &&
5082
0
    colon > ZSTR_VAL(function) &&
5083
0
    *(colon-1) == ':'
5084
0
  ) {
5085
0
    zend_string *mname;
5086
0
    size_t cname_length = colon - ZSTR_VAL(function) - 1;
5087
0
    size_t mname_length = ZSTR_LEN(function) - cname_length - (sizeof("::") - 1);
5088
5089
0
    lcname = zend_string_init(ZSTR_VAL(function), cname_length, 0);
5090
5091
0
    called_scope = zend_fetch_class_by_name(lcname, NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION);
5092
0
    if (UNEXPECTED(called_scope == NULL)) {
5093
0
      zend_string_release_ex(lcname, 0);
5094
0
      return NULL;
5095
0
    }
5096
5097
0
    mname = zend_string_init(ZSTR_VAL(function) + (cname_length + sizeof("::") - 1), mname_length, 0);
5098
5099
0
    if (called_scope->get_static_method) {
5100
0
      fbc = called_scope->get_static_method(called_scope, mname);
5101
0
    } else {
5102
0
      fbc = zend_std_get_static_method(called_scope, mname, NULL);
5103
0
    }
5104
0
    if (UNEXPECTED(fbc == NULL)) {
5105
0
      if (EXPECTED(!EG(exception))) {
5106
0
        zend_undefined_method(called_scope, mname);
5107
0
      }
5108
0
      zend_string_release_ex(lcname, 0);
5109
0
      zend_string_release_ex(mname, 0);
5110
0
      return NULL;
5111
0
    }
5112
5113
0
    zend_string_release_ex(lcname, 0);
5114
0
    zend_string_release_ex(mname, 0);
5115
5116
0
    if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
5117
0
      zend_non_static_method_call(fbc);
5118
0
      if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
5119
0
        zend_string_release_ex(fbc->common.function_name, 0);
5120
0
        zend_free_trampoline(fbc);
5121
0
      }
5122
0
      return NULL;
5123
0
    }
5124
0
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5125
0
      init_func_run_time_cache(&fbc->op_array);
5126
0
    }
5127
0
  } else {
5128
0
    if (ZSTR_VAL(function)[0] == '\\') {
5129
0
      lcname = zend_string_alloc(ZSTR_LEN(function) - 1, 0);
5130
0
      zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(function) + 1, ZSTR_LEN(function) - 1);
5131
0
    } else {
5132
0
      lcname = zend_string_tolower(function);
5133
0
    }
5134
0
    if (UNEXPECTED((func = zend_hash_find(EG(function_table), lcname)) == NULL)) {
5135
0
      zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(function));
5136
0
      zend_string_release_ex(lcname, 0);
5137
0
      return NULL;
5138
0
    }
5139
0
    zend_string_release_ex(lcname, 0);
5140
5141
0
    fbc = Z_FUNC_P(func);
5142
0
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5143
0
      init_func_run_time_cache(&fbc->op_array);
5144
0
    }
5145
0
    called_scope = NULL;
5146
0
  }
5147
5148
0
  return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC,
5149
0
    fbc, num_args, called_scope);
5150
0
}
5151
/* }}} */
5152
5153
static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_object *function, uint32_t num_args) /* {{{ */
5154
0
{
5155
0
  zend_function *fbc;
5156
0
  void *object_or_called_scope;
5157
0
  zend_class_entry *called_scope;
5158
0
  zend_object *object;
5159
0
  uint32_t call_info;
5160
5161
0
  if (EXPECTED(function->handlers->get_closure) &&
5162
0
      EXPECTED(function->handlers->get_closure(function, &called_scope, &fbc, &object, 0) == SUCCESS)) {
5163
5164
0
    object_or_called_scope = called_scope;
5165
0
    if (EXPECTED(fbc->common.fn_flags & ZEND_ACC_CLOSURE)) {
5166
      /* Delay closure destruction until its invocation */
5167
0
      GC_ADDREF(ZEND_CLOSURE_OBJECT(fbc));
5168
0
      ZEND_ASSERT(ZEND_ACC_FAKE_CLOSURE == ZEND_CALL_FAKE_CLOSURE);
5169
0
      call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_CLOSURE |
5170
0
        (fbc->common.fn_flags & ZEND_ACC_FAKE_CLOSURE);
5171
0
      if (object) {
5172
0
        call_info |= ZEND_CALL_HAS_THIS;
5173
0
        object_or_called_scope = object;
5174
0
      }
5175
0
    } else {
5176
0
      call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
5177
0
      if (object) {
5178
0
        call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
5179
0
        GC_ADDREF(object); /* For $this pointer */
5180
0
        object_or_called_scope = object;
5181
0
      }
5182
0
    }
5183
0
  } else {
5184
0
    zend_throw_error(NULL, "Object of type %s is not callable", ZSTR_VAL(function->ce->name));
5185
0
    return NULL;
5186
0
  }
5187
5188
0
  if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5189
0
    init_func_run_time_cache(&fbc->op_array);
5190
0
  }
5191
5192
0
  return zend_vm_stack_push_call_frame(call_info,
5193
0
    fbc, num_args, object_or_called_scope);
5194
0
}
5195
/* }}} */
5196
5197
static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_array *function, uint32_t num_args) /* {{{ */
5198
0
{
5199
0
  zend_function *fbc;
5200
0
  void *object_or_called_scope;
5201
0
  uint32_t call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
5202
5203
0
  if (zend_hash_num_elements(function) == 2) {
5204
0
    zval *obj;
5205
0
    zval *method;
5206
0
    obj = zend_hash_index_find(function, 0);
5207
0
    method = zend_hash_index_find(function, 1);
5208
5209
0
    if (UNEXPECTED(!obj) || UNEXPECTED(!method)) {
5210
0
      zend_throw_error(NULL, "Array callback has to contain indices 0 and 1");
5211
0
      return NULL;
5212
0
    }
5213
5214
0
    ZVAL_DEREF(obj);
5215
0
    if (UNEXPECTED(Z_TYPE_P(obj) != IS_STRING) && UNEXPECTED(Z_TYPE_P(obj) != IS_OBJECT)) {
5216
0
      zend_throw_error(NULL, "First array member is not a valid class name or object");
5217
0
      return NULL;
5218
0
    }
5219
5220
0
    ZVAL_DEREF(method);
5221
0
    if (UNEXPECTED(Z_TYPE_P(method) != IS_STRING)) {
5222
0
      zend_throw_error(NULL, "Second array member is not a valid method");
5223
0
      return NULL;
5224
0
    }
5225
5226
0
    if (Z_TYPE_P(obj) == IS_STRING) {
5227
0
      zend_class_entry *called_scope = zend_fetch_class_by_name(Z_STR_P(obj), NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION);
5228
5229
0
      if (UNEXPECTED(called_scope == NULL)) {
5230
0
        return NULL;
5231
0
      }
5232
5233
0
      if (called_scope->get_static_method) {
5234
0
        fbc = called_scope->get_static_method(called_scope, Z_STR_P(method));
5235
0
      } else {
5236
0
        fbc = zend_std_get_static_method(called_scope, Z_STR_P(method), NULL);
5237
0
      }
5238
0
      if (UNEXPECTED(fbc == NULL)) {
5239
0
        if (EXPECTED(!EG(exception))) {
5240
0
          zend_undefined_method(called_scope, Z_STR_P(method));
5241
0
        }
5242
0
        return NULL;
5243
0
      }
5244
0
      if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
5245
0
        zend_non_static_method_call(fbc);
5246
0
        if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
5247
0
          zend_string_release_ex(fbc->common.function_name, 0);
5248
0
          zend_free_trampoline(fbc);
5249
0
        }
5250
0
        return NULL;
5251
0
      }
5252
0
      object_or_called_scope = called_scope;
5253
0
    } else {
5254
0
      zend_object *object = Z_OBJ_P(obj);
5255
5256
0
      fbc = Z_OBJ_HT_P(obj)->get_method(&object, Z_STR_P(method), NULL);
5257
0
      if (UNEXPECTED(fbc == NULL)) {
5258
0
        if (EXPECTED(!EG(exception))) {
5259
0
          zend_undefined_method(object->ce, Z_STR_P(method));
5260
0
        }
5261
0
        return NULL;
5262
0
      }
5263
5264
0
      if ((fbc->common.fn_flags & ZEND_ACC_STATIC) != 0) {
5265
0
        object_or_called_scope = object->ce;
5266
0
      } else {
5267
0
        call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
5268
0
        GC_ADDREF(object); /* For $this pointer */
5269
0
        object_or_called_scope = object;
5270
0
      }
5271
0
    }
5272
0
  } else {
5273
0
    zend_throw_error(NULL, "Array callback must have exactly two elements");
5274
0
    return NULL;
5275
0
  }
5276
5277
0
  if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5278
0
    init_func_run_time_cache(&fbc->op_array);
5279
0
  }
5280
5281
0
  return zend_vm_stack_push_call_frame(call_info,
5282
0
    fbc, num_args, object_or_called_scope);
5283
0
}
5284
/* }}} */
5285
5286
0
#define ZEND_FAKE_OP_ARRAY ((zend_op_array*)(intptr_t)-1)
5287
5288
static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval *inc_filename_zv, int type) /* {{{ */
5289
0
{
5290
0
  zend_op_array *new_op_array = NULL;
5291
0
  zend_string *tmp_inc_filename;
5292
0
  zend_string *inc_filename = zval_try_get_tmp_string(inc_filename_zv, &tmp_inc_filename);
5293
0
  if (UNEXPECTED(!inc_filename)) {
5294
0
    return NULL;
5295
0
  }
5296
5297
0
  switch (type) {
5298
0
    case ZEND_INCLUDE_ONCE:
5299
0
    case ZEND_REQUIRE_ONCE: {
5300
0
        zend_file_handle file_handle;
5301
0
        zend_string *resolved_path;
5302
5303
0
        resolved_path = zend_resolve_path(inc_filename);
5304
0
        if (EXPECTED(resolved_path)) {
5305
0
          if (zend_hash_exists(&EG(included_files), resolved_path)) {
5306
0
            new_op_array = ZEND_FAKE_OP_ARRAY;
5307
0
            zend_string_release_ex(resolved_path, 0);
5308
0
            break;
5309
0
          }
5310
0
        } else if (UNEXPECTED(EG(exception))) {
5311
0
          break;
5312
0
        } else if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) {
5313
0
          zend_message_dispatcher(
5314
0
            (type == ZEND_INCLUDE_ONCE) ?
5315
0
              ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,
5316
0
              ZSTR_VAL(inc_filename));
5317
0
          break;
5318
0
        } else {
5319
0
          resolved_path = zend_string_copy(inc_filename);
5320
0
        }
5321
5322
0
        zend_stream_init_filename_ex(&file_handle, resolved_path);
5323
0
        if (SUCCESS == zend_stream_open(&file_handle)) {
5324
5325
0
          if (!file_handle.opened_path) {
5326
0
            file_handle.opened_path = zend_string_copy(resolved_path);
5327
0
          }
5328
5329
0
          if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) {
5330
0
            new_op_array = zend_compile_file(&file_handle, (type==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE));
5331
0
          } else {
5332
0
            new_op_array = ZEND_FAKE_OP_ARRAY;
5333
0
          }
5334
0
        } else if (!EG(exception)) {
5335
0
          zend_message_dispatcher(
5336
0
            (type == ZEND_INCLUDE_ONCE) ?
5337
0
              ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,
5338
0
              ZSTR_VAL(inc_filename));
5339
0
        }
5340
0
        zend_destroy_file_handle(&file_handle);
5341
0
        zend_string_release_ex(resolved_path, 0);
5342
0
      }
5343
0
      break;
5344
0
    case ZEND_INCLUDE:
5345
0
    case ZEND_REQUIRE:
5346
0
      if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) {
5347
0
        zend_message_dispatcher(
5348
0
          (type == ZEND_INCLUDE) ?
5349
0
            ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,
5350
0
            ZSTR_VAL(inc_filename));
5351
0
        break;
5352
0
      }
5353
0
      new_op_array = compile_filename(type, inc_filename);
5354
0
      break;
5355
0
    case ZEND_EVAL: {
5356
0
        char *eval_desc = zend_make_compiled_string_description("eval()'d code");
5357
0
        new_op_array = zend_compile_string(inc_filename, eval_desc, ZEND_COMPILE_POSITION_AFTER_OPEN_TAG);
5358
0
        efree(eval_desc);
5359
0
      }
5360
0
      break;
5361
0
    EMPTY_SWITCH_DEFAULT_CASE()
5362
0
  }
5363
5364
0
  zend_tmp_string_release(tmp_inc_filename);
5365
0
  return new_op_array;
5366
0
}
5367
/* }}} */
5368
5369
static zend_never_inline bool ZEND_FASTCALL zend_fe_reset_iterator(zval *array_ptr, int by_ref OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5370
0
{
5371
0
  zend_class_entry *ce = Z_OBJCE_P(array_ptr);
5372
0
  zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, by_ref);
5373
0
  bool is_empty;
5374
5375
0
  if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) {
5376
0
    if (iter) {
5377
0
      OBJ_RELEASE(&iter->std);
5378
0
    }
5379
0
    if (!EG(exception)) {
5380
0
      zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name));
5381
0
    }
5382
0
    ZVAL_UNDEF(EX_VAR(opline->result.var));
5383
0
    return 1;
5384
0
  }
5385
5386
0
  iter->index = 0;
5387
0
  if (iter->funcs->rewind) {
5388
0
    iter->funcs->rewind(iter);
5389
0
    if (UNEXPECTED(EG(exception) != NULL)) {
5390
0
      OBJ_RELEASE(&iter->std);
5391
0
      ZVAL_UNDEF(EX_VAR(opline->result.var));
5392
0
      return 1;
5393
0
    }
5394
0
  }
5395
5396
0
  is_empty = iter->funcs->valid(iter) != SUCCESS;
5397
5398
0
  if (UNEXPECTED(EG(exception) != NULL)) {
5399
0
    OBJ_RELEASE(&iter->std);
5400
0
    ZVAL_UNDEF(EX_VAR(opline->result.var));
5401
0
    return 1;
5402
0
  }
5403
0
  iter->index = -1; /* will be set to 0 before using next handler */
5404
5405
0
  ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std);
5406
0
  Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
5407
5408
0
  return is_empty;
5409
0
}
5410
/* }}} */
5411
5412
static zend_always_inline zend_result _zend_quick_get_constant(
5413
    const zval *key, uint32_t flags, bool check_defined_only OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5414
0
{
5415
0
  zval *zv;
5416
0
  zend_constant *c = NULL;
5417
5418
  /* null/true/false are resolved during compilation, so don't check for them here. */
5419
0
  zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
5420
0
  if (zv) {
5421
0
    c = (zend_constant*)Z_PTR_P(zv);
5422
0
  } else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
5423
0
    key++;
5424
0
    zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
5425
0
    if (zv) {
5426
0
      c = (zend_constant*)Z_PTR_P(zv);
5427
0
    }
5428
0
  }
5429
5430
0
  if (!c) {
5431
0
    if (!check_defined_only) {
5432
0
      zend_throw_error(NULL, "Undefined constant \"%s\"", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
5433
0
      ZVAL_UNDEF(EX_VAR(opline->result.var));
5434
0
    }
5435
0
    return FAILURE;
5436
0
  }
5437
5438
0
  if (!check_defined_only) {
5439
0
    ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
5440
0
    if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) {
5441
0
      if (!CONST_IS_RECURSIVE(c)) {
5442
0
        CONST_PROTECT_RECURSION(c);
5443
0
        zend_deprecated_constant(c, c->name);
5444
0
        CONST_UNPROTECT_RECURSION(c);
5445
0
      }
5446
0
      return SUCCESS;
5447
0
    }
5448
0
  }
5449
5450
0
  CACHE_PTR(opline->extended_value, c);
5451
0
  return SUCCESS;
5452
0
}
5453
/* }}} */
5454
5455
static zend_never_inline void ZEND_FASTCALL zend_quick_get_constant(
5456
    const zval *key, uint32_t flags OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5457
0
{
5458
0
  _zend_quick_get_constant(key, flags, 0 OPLINE_CC EXECUTE_DATA_CC);
5459
0
} /* }}} */
5460
5461
static zend_never_inline zend_result ZEND_FASTCALL zend_quick_check_constant(
5462
    const zval *key OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5463
0
{
5464
0
  return _zend_quick_get_constant(key, 0, 1 OPLINE_CC EXECUTE_DATA_CC);
5465
0
} /* }}} */
5466
5467
static zend_always_inline uint32_t zend_get_arg_offset_by_name(
5468
0
    const zend_function *fbc, const zend_string *arg_name, void **cache_slot) {
5469
  /* Due to closures, the `fbc` address isn't unique if the memory address is reused.
5470
   * The argument info will be however and uniquely positions the arguments.
5471
   * We do support NULL arg_info, so we have to distinguish that from an uninitialized cache slot. */
5472
0
  void *unique_id = (void *) ((uintptr_t) fbc->common.arg_info | 1);
5473
5474
0
  if (EXPECTED(*cache_slot == unique_id)) {
5475
0
    return *(uintptr_t *)(cache_slot + 1);
5476
0
  }
5477
5478
  // TODO: Use a hash table?
5479
0
  uint32_t num_args = fbc->common.num_args;
5480
0
  for (uint32_t i = 0; i < num_args; i++) {
5481
0
    const zend_arg_info *arg_info = &fbc->common.arg_info[i];
5482
0
    if (zend_string_equals(arg_name, arg_info->name)) {
5483
0
      if ((fbc->type == ZEND_USER_FUNCTION
5484
0
        && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE)))
5485
0
       || (fbc->type == ZEND_INTERNAL_FUNCTION
5486
0
        && !(fbc->common.fn_flags & ZEND_ACC_NEVER_CACHE))) {
5487
0
        *cache_slot = unique_id;
5488
0
        *(uintptr_t *)(cache_slot + 1) = i;
5489
0
      }
5490
0
      return i;
5491
0
    }
5492
0
  }
5493
5494
0
  if (fbc->common.fn_flags & ZEND_ACC_VARIADIC) {
5495
0
    if ((fbc->type == ZEND_USER_FUNCTION
5496
0
      && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE)))
5497
0
     || (fbc->type == ZEND_INTERNAL_FUNCTION
5498
0
      && !(fbc->common.fn_flags & ZEND_ACC_NEVER_CACHE))) {
5499
0
      *cache_slot = unique_id;
5500
0
      *(uintptr_t *)(cache_slot + 1) = fbc->common.num_args;
5501
0
    }
5502
0
    return fbc->common.num_args;
5503
0
  }
5504
5505
0
  return (uint32_t) -1;
5506
0
}
5507
5508
zval * ZEND_FASTCALL zend_handle_named_arg(
5509
    zend_execute_data **call_ptr, zend_string *arg_name,
5510
0
    uint32_t *arg_num_ptr, void **cache_slot) {
5511
0
  zend_execute_data *call = *call_ptr;
5512
0
  const zend_function *fbc = call->func;
5513
0
  uint32_t arg_offset = zend_get_arg_offset_by_name(fbc, arg_name, cache_slot);
5514
0
  if (UNEXPECTED(arg_offset == (uint32_t) -1)) {
5515
0
    zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name));
5516
0
    return NULL;
5517
0
  }
5518
5519
0
  zval *arg;
5520
0
  if (UNEXPECTED(arg_offset == fbc->common.num_args)) {
5521
    /* Unknown named parameter that will be collected into a variadic. */
5522
0
    if (!(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) {
5523
0
      ZEND_ADD_CALL_FLAG(call, ZEND_CALL_HAS_EXTRA_NAMED_PARAMS);
5524
0
      call->extra_named_params = zend_new_array(0);
5525
0
    }
5526
5527
0
    arg = zend_hash_add_empty_element(call->extra_named_params, arg_name);
5528
0
    if (!arg) {
5529
0
      zend_throw_error(NULL, "Named parameter $%s overwrites previous argument",
5530
0
        ZSTR_VAL(arg_name));
5531
0
      return NULL;
5532
0
    }
5533
0
    *arg_num_ptr = arg_offset + 1;
5534
0
    return arg;
5535
0
  }
5536
5537
0
  uint32_t current_num_args = ZEND_CALL_NUM_ARGS(call);
5538
  // TODO: We may wish to optimize the arg_offset == current_num_args case,
5539
  // which is probably common (if the named parameters are in order of declaration).
5540
0
  if (arg_offset >= current_num_args) {
5541
0
    uint32_t new_num_args = arg_offset + 1;
5542
0
    ZEND_CALL_NUM_ARGS(call) = new_num_args;
5543
5544
0
    uint32_t num_extra_args = new_num_args - current_num_args;
5545
0
    zend_vm_stack_extend_call_frame(call_ptr, current_num_args, num_extra_args);
5546
0
    call = *call_ptr;
5547
5548
0
    arg = ZEND_CALL_VAR_NUM(call, arg_offset);
5549
0
    if (num_extra_args > 1) {
5550
0
      zval *zv = ZEND_CALL_VAR_NUM(call, current_num_args);
5551
0
      do {
5552
0
        ZVAL_UNDEF(zv);
5553
0
        zv++;
5554
0
      } while (zv != arg);
5555
0
      ZEND_ADD_CALL_FLAG(call, ZEND_CALL_MAY_HAVE_UNDEF);
5556
0
    }
5557
0
  } else {
5558
0
    arg = ZEND_CALL_VAR_NUM(call, arg_offset);
5559
0
    if (UNEXPECTED(!Z_ISUNDEF_P(arg))) {
5560
0
      zend_throw_error(NULL, "Named parameter $%s overwrites previous argument",
5561
0
        ZSTR_VAL(arg_name));
5562
0
      return NULL;
5563
0
    }
5564
0
  }
5565
5566
0
  *arg_num_ptr = arg_offset + 1;
5567
0
  return arg;
5568
0
}
5569
5570
0
static zend_execute_data *start_fake_frame(zend_execute_data *call, const zend_op *opline) {
5571
0
  zend_execute_data *old_prev_execute_data = call->prev_execute_data;
5572
0
  call->prev_execute_data = EG(current_execute_data);
5573
0
  call->opline = opline;
5574
0
  EG(current_execute_data) = call;
5575
0
  return old_prev_execute_data;
5576
0
}
5577
5578
0
static void end_fake_frame(zend_execute_data *call, zend_execute_data *old_prev_execute_data) {
5579
0
  zend_execute_data *prev_execute_data = call->prev_execute_data;
5580
0
  EG(current_execute_data) = prev_execute_data;
5581
0
  call->prev_execute_data = old_prev_execute_data;
5582
0
  if (UNEXPECTED(EG(exception)) && ZEND_USER_CODE(prev_execute_data->func->common.type)) {
5583
0
    zend_rethrow_exception(prev_execute_data);
5584
0
  }
5585
0
}
5586
5587
0
ZEND_API zend_result ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call) {
5588
0
  zend_function *fbc = call->func;
5589
0
  if (fbc->type == ZEND_USER_FUNCTION) {
5590
0
    zend_op_array *op_array = &fbc->op_array;
5591
0
    uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
5592
0
    for (uint32_t i = 0; i < num_args; i++) {
5593
0
      zval *arg = ZEND_CALL_VAR_NUM(call, i);
5594
0
      if (!Z_ISUNDEF_P(arg)) {
5595
0
        continue;
5596
0
      }
5597
5598
0
      const zend_op *opline = &op_array->opcodes[i];
5599
0
      if (EXPECTED(opline->opcode == ZEND_RECV_INIT)) {
5600
0
        zval *default_value = RT_CONSTANT(opline, opline->op2);
5601
0
        if (Z_OPT_TYPE_P(default_value) == IS_CONSTANT_AST) {
5602
0
          if (UNEXPECTED(!RUN_TIME_CACHE(op_array))) {
5603
0
            init_func_run_time_cache(op_array);
5604
0
          }
5605
5606
0
          void *run_time_cache = RUN_TIME_CACHE(op_array);
5607
0
          zval *cache_val =
5608
0
            (zval *) ((char *) run_time_cache + Z_CACHE_SLOT_P(default_value));
5609
5610
0
          if (Z_TYPE_P(cache_val) != IS_UNDEF) {
5611
            /* We keep in cache only not refcounted values */
5612
0
            ZVAL_COPY_VALUE(arg, cache_val);
5613
0
          } else {
5614
            /* Update constant inside a temporary zval, to make sure the CONSTANT_AST
5615
             * value is not accessible through back traces. */
5616
0
            zval tmp;
5617
0
            ZVAL_COPY(&tmp, default_value);
5618
0
            zend_execute_data *old = start_fake_frame(call, opline);
5619
0
            zend_result ret = zval_update_constant_ex(&tmp, fbc->op_array.scope);
5620
0
            end_fake_frame(call, old);
5621
0
            if (UNEXPECTED(ret == FAILURE)) {
5622
0
              zval_ptr_dtor_nogc(&tmp);
5623
0
              return FAILURE;
5624
0
            }
5625
0
            ZVAL_COPY_VALUE(arg, &tmp);
5626
0
            if (!Z_REFCOUNTED(tmp)) {
5627
0
              ZVAL_COPY_VALUE(cache_val, &tmp);
5628
0
            }
5629
0
          }
5630
0
        } else {
5631
0
          ZVAL_COPY(arg, default_value);
5632
0
        }
5633
0
      } else {
5634
0
        ZEND_ASSERT(opline->opcode == ZEND_RECV);
5635
0
        zend_execute_data *old = start_fake_frame(call, opline);
5636
0
        zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed");
5637
0
        end_fake_frame(call, old);
5638
0
        return FAILURE;
5639
0
      }
5640
0
    }
5641
5642
0
    return SUCCESS;
5643
0
  } else {
5644
0
    if (fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO) {
5645
      /* Magic function, let it deal with it. */
5646
0
      return SUCCESS;
5647
0
    }
5648
5649
0
    uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
5650
0
    for (uint32_t i = 0; i < num_args; i++) {
5651
0
      zval *arg = ZEND_CALL_VAR_NUM(call, i);
5652
0
      if (!Z_ISUNDEF_P(arg)) {
5653
0
        continue;
5654
0
      }
5655
5656
0
      zend_arg_info *arg_info = &fbc->internal_function.arg_info[i];
5657
0
      if (i < fbc->common.required_num_args) {
5658
0
        zend_execute_data *old = start_fake_frame(call, NULL);
5659
0
        zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed");
5660
0
        end_fake_frame(call, old);
5661
0
        return FAILURE;
5662
0
      }
5663
5664
0
      zval default_value;
5665
0
      if (zend_get_default_from_internal_arg_info(&default_value, arg_info) == FAILURE) {
5666
0
        zend_execute_data *old = start_fake_frame(call, NULL);
5667
0
        zend_argument_error(zend_ce_argument_count_error, i + 1,
5668
0
          "must be passed explicitly, because the default value is not known");
5669
0
        end_fake_frame(call, old);
5670
0
        return FAILURE;
5671
0
      }
5672
5673
0
      if (Z_TYPE(default_value) == IS_CONSTANT_AST) {
5674
0
        zend_execute_data *old = start_fake_frame(call, NULL);
5675
0
        zend_result ret = zval_update_constant_ex(&default_value, fbc->common.scope);
5676
0
        end_fake_frame(call, old);
5677
0
        if (ret == FAILURE) {
5678
0
          return FAILURE;
5679
0
        }
5680
0
      }
5681
5682
0
      ZVAL_COPY_VALUE(arg, &default_value);
5683
0
      if (ZEND_ARG_SEND_MODE(arg_info) & ZEND_SEND_BY_REF) {
5684
0
        ZVAL_NEW_REF(arg, arg);
5685
0
      }
5686
0
    }
5687
0
  }
5688
5689
0
  return SUCCESS;
5690
0
}
5691
5692
ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named_params)
5693
0
{
5694
  /* Extra named params may be shared. */
5695
0
  zend_array_release(extra_named_params);
5696
0
}
5697
5698
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
5699
/* Special versions of functions that sets EX(opline) before calling zend_vm_stack_extend() */
5700
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) /* {{{ */
5701
{
5702
  zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
5703
5704
  ZEND_ASSERT_VM_STACK_GLOBAL;
5705
5706
  if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
5707
    EX(opline) = opline; /* this is the only difference */
5708
    call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
5709
    ZEND_ASSERT_VM_STACK_GLOBAL;
5710
    zend_vm_init_call_frame(call, call_info | ZEND_CALL_ALLOCATED, func, num_args, object_or_called_scope);
5711
    return call;
5712
  } else {
5713
    EG(vm_stack_top) = (zval*)((char*)call + used_stack);
5714
    zend_vm_init_call_frame(call, call_info, func, num_args, object_or_called_scope);
5715
    return call;
5716
  }
5717
} /* }}} */
5718
5719
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) /* {{{ */
5720
{
5721
  uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
5722
5723
  return _zend_vm_stack_push_call_frame_ex(used_stack, call_info,
5724
    func, num_args, object_or_called_scope);
5725
} /* }}} */
5726
#else
5727
0
# define _zend_vm_stack_push_call_frame_ex zend_vm_stack_push_call_frame_ex
5728
0
# define _zend_vm_stack_push_call_frame    zend_vm_stack_push_call_frame
5729
#endif
5730
5731
#ifdef ZEND_VM_TRACE_HANDLERS
5732
# include "zend_vm_trace_handlers.h"
5733
#elif defined(ZEND_VM_TRACE_LINES)
5734
# include "zend_vm_trace_lines.h"
5735
#elif defined(ZEND_VM_TRACE_MAP)
5736
# include "zend_vm_trace_map.h"
5737
#elif defined(ZEND_VERIFY_TYPE_INFERENCE)
5738
# include "zend_verify_type_inference.h"
5739
#endif
5740
5741
#define ZEND_VM_NEXT_OPCODE_EX(check_exception, skip) \
5742
0
  CHECK_SYMBOL_TABLES() \
5743
0
  if (check_exception) { \
5744
0
    OPLINE = EX(opline) + (skip); \
5745
0
  } else { \
5746
0
    ZEND_ASSERT(!EG(exception)); \
5747
0
    OPLINE = opline + (skip); \
5748
0
  } \
5749
0
  ZEND_VM_CONTINUE()
5750
5751
#define ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION() \
5752
0
  ZEND_VM_NEXT_OPCODE_EX(1, 1)
5753
5754
#define ZEND_VM_NEXT_OPCODE() \
5755
0
  ZEND_VM_NEXT_OPCODE_EX(0, 1)
5756
5757
#define ZEND_VM_SET_NEXT_OPCODE(new_op) \
5758
0
  CHECK_SYMBOL_TABLES() \
5759
0
  OPLINE = new_op
5760
5761
#define ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op) \
5762
0
  CHECK_SYMBOL_TABLES() \
5763
0
  OPLINE = new_op
5764
5765
#define ZEND_VM_SET_OPCODE(new_op) \
5766
0
  ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op); \
5767
0
  ZEND_VM_INTERRUPT_CHECK()
5768
5769
#define ZEND_VM_SET_RELATIVE_OPCODE(opline, offset) \
5770
0
  ZEND_VM_SET_OPCODE(ZEND_OFFSET_TO_OPLINE(opline, offset))
5771
5772
0
#define ZEND_VM_JMP_EX(new_op, check_exception) do { \
5773
0
    if (check_exception && UNEXPECTED(EG(exception))) { \
5774
0
      HANDLE_EXCEPTION(); \
5775
0
    } \
5776
0
    ZEND_VM_SET_OPCODE(new_op); \
5777
0
    ZEND_VM_CONTINUE(); \
5778
0
  } while (0)
5779
5780
#define ZEND_VM_JMP(new_op) \
5781
0
  ZEND_VM_JMP_EX(new_op, 1)
5782
5783
#define ZEND_VM_INC_OPCODE() \
5784
0
  OPLINE++
5785
5786
5787
#define ZEND_VM_REPEATABLE_OPCODE \
5788
0
  do {
5789
#define ZEND_VM_REPEAT_OPCODE(_opcode) \
5790
0
  } while (UNEXPECTED((++opline)->opcode == _opcode)); \
5791
0
  OPLINE = opline; \
5792
0
  ZEND_VM_CONTINUE()
5793
0
#define ZEND_VM_SMART_BRANCH(_result, _check) do { \
5794
0
    if ((_check) && UNEXPECTED(EG(exception))) { \
5795
0
      OPLINE = EX(opline); \
5796
0
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
5797
0
      if (_result) { \
5798
0
        ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5799
0
      } else { \
5800
0
        ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5801
0
      } \
5802
0
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
5803
0
      if (!(_result)) { \
5804
0
        ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5805
0
      } else { \
5806
0
        ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5807
0
      } \
5808
0
    } else { \
5809
0
      ZVAL_BOOL(EX_VAR(opline->result.var), _result); \
5810
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
5811
0
    } \
5812
0
    ZEND_VM_CONTINUE(); \
5813
0
  } while (0)
5814
0
#define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check) do { \
5815
0
    if ((_check) && UNEXPECTED(EG(exception))) { \
5816
0
      OPLINE = EX(opline); \
5817
0
    } else if (_result) { \
5818
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5819
0
    } else { \
5820
0
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5821
0
    } \
5822
0
    ZEND_VM_CONTINUE(); \
5823
0
  } while (0)
5824
0
#define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check) do { \
5825
0
    if ((_check) && UNEXPECTED(EG(exception))) { \
5826
0
      OPLINE = EX(opline); \
5827
0
    } else if (!(_result)) { \
5828
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5829
0
    } else { \
5830
0
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5831
0
    } \
5832
0
    ZEND_VM_CONTINUE(); \
5833
0
  } while (0)
5834
0
#define ZEND_VM_SMART_BRANCH_NONE(_result, _check) do { \
5835
0
    ZVAL_BOOL(EX_VAR(opline->result.var), _result); \
5836
0
    ZEND_VM_NEXT_OPCODE_EX(_check, 1); \
5837
0
    ZEND_VM_CONTINUE(); \
5838
0
  } while (0)
5839
0
#define ZEND_VM_SMART_BRANCH_TRUE() do { \
5840
0
    if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
5841
0
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5842
0
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
5843
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5844
0
    } else { \
5845
0
      ZVAL_TRUE(EX_VAR(opline->result.var)); \
5846
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
5847
0
    } \
5848
0
    ZEND_VM_CONTINUE(); \
5849
0
  } while (0)
5850
0
#define ZEND_VM_SMART_BRANCH_TRUE_JMPZ() do { \
5851
0
    ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5852
0
    ZEND_VM_CONTINUE(); \
5853
0
  } while (0)
5854
0
#define ZEND_VM_SMART_BRANCH_TRUE_JMPNZ() do { \
5855
0
    ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5856
0
    ZEND_VM_CONTINUE(); \
5857
0
  } while (0)
5858
0
#define ZEND_VM_SMART_BRANCH_TRUE_NONE() do { \
5859
0
    ZVAL_TRUE(EX_VAR(opline->result.var)); \
5860
0
    ZEND_VM_NEXT_OPCODE(); \
5861
0
  } while (0)
5862
0
#define ZEND_VM_SMART_BRANCH_FALSE() do { \
5863
0
    if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
5864
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5865
0
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
5866
0
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5867
0
    } else { \
5868
0
      ZVAL_FALSE(EX_VAR(opline->result.var)); \
5869
0
      ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
5870
0
    } \
5871
0
    ZEND_VM_CONTINUE(); \
5872
0
  } while (0)
5873
0
#define ZEND_VM_SMART_BRANCH_FALSE_JMPZ() do { \
5874
0
    ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5875
0
    ZEND_VM_CONTINUE(); \
5876
0
  } while (0)
5877
0
#define ZEND_VM_SMART_BRANCH_FALSE_JMPNZ() do { \
5878
0
    ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5879
0
    ZEND_VM_CONTINUE(); \
5880
0
  } while (0)
5881
0
#define ZEND_VM_SMART_BRANCH_FALSE_NONE() do { \
5882
0
    ZVAL_FALSE(EX_VAR(opline->result.var)); \
5883
0
    ZEND_VM_NEXT_OPCODE(); \
5884
0
  } while (0)
5885
5886
#ifdef __GNUC__
5887
# define ZEND_VM_GUARD(name) __asm__("#" #name)
5888
#else
5889
# define ZEND_VM_GUARD(name)
5890
#endif
5891
5892
0
#define UNDEF_RESULT() do { \
5893
0
    if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { \
5894
0
      ZVAL_UNDEF(EX_VAR(opline->result.var)); \
5895
0
    } \
5896
0
  } while (0)
5897
5898
/* This callback disables optimization of "vm_stack_data" variable in VM */
5899
ZEND_API void (ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data) = NULL;
5900
5901
#include "zend_vm_execute.h"
5902
5903
ZEND_API zend_result zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler)
5904
0
{
5905
0
  if (opcode != ZEND_USER_OPCODE) {
5906
0
    if (handler == NULL) {
5907
      /* restore the original handler */
5908
0
      zend_user_opcodes[opcode] = opcode;
5909
0
    } else {
5910
0
      zend_user_opcodes[opcode] = ZEND_USER_OPCODE;
5911
0
    }
5912
0
    zend_user_opcode_handlers[opcode] = handler;
5913
0
    return SUCCESS;
5914
0
  }
5915
0
  return FAILURE;
5916
0
}
5917
5918
ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode)
5919
512
{
5920
512
  return zend_user_opcode_handlers[opcode];
5921
512
}
5922
5923
ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data)
5924
0
{
5925
0
  zval *ret;
5926
5927
0
  switch (op_type) {
5928
0
    case IS_CONST:
5929
0
      ret = RT_CONSTANT(opline, *node);
5930
0
      break;
5931
0
    case IS_TMP_VAR:
5932
0
    case IS_VAR:
5933
0
    case IS_CV:
5934
0
      ret = EX_VAR(node->var);
5935
0
      break;
5936
0
    default:
5937
0
      ret = NULL;
5938
0
      break;
5939
0
  }
5940
0
  return ret;
5941
0
}