Coverage Report

Created: 2026-10-28 06:20

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