You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1309 lines
38 KiB

28 years ago
28 years ago
25 years ago
25 years ago
27 years ago
28 years ago
27 years ago
28 years ago
28 years ago
28 years ago
28 years ago
18 years ago
19 years ago
19 years ago
19 years ago
19 years ago
28 years ago
21 years ago
28 years ago
28 years ago
28 years ago
28 years ago
23 years ago
28 years ago
28 years ago
28 years ago
27 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
18 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
27 years ago
28 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
19 years ago
28 years ago
28 years ago
28 years ago
28 years ago
24 years ago
24 years ago
28 years ago
28 years ago
27 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
21 years ago
21 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2009 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@zend.com> |
  16. | Zeev Suraski <zeev@zend.com> |
  17. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #define ZEND_INTENSIVE_DEBUGGING 0
  21. #include <stdio.h>
  22. #include <signal.h>
  23. #include "zend.h"
  24. #include "zend_compile.h"
  25. #include "zend_execute.h"
  26. #include "zend_API.h"
  27. #include "zend_ptr_stack.h"
  28. #include "zend_constants.h"
  29. #include "zend_extensions.h"
  30. #include "zend_ini.h"
  31. #include "zend_exceptions.h"
  32. #include "zend_interfaces.h"
  33. #include "zend_closures.h"
  34. #include "zend_vm.h"
  35. /* Virtual current working directory support */
  36. #include "tsrm_virtual_cwd.h"
  37. #define _CONST_CODE 0
  38. #define _TMP_CODE 1
  39. #define _VAR_CODE 2
  40. #define _UNUSED_CODE 3
  41. #define _CV_CODE 4
  42. typedef int (*incdec_t)(zval *);
  43. #define get_zval_ptr(node, Ts, should_free, type) _get_zval_ptr(node, Ts, should_free, type TSRMLS_CC)
  44. #define get_zval_ptr_ptr(node, Ts, should_free, type) _get_zval_ptr_ptr(node, Ts, should_free, type TSRMLS_CC)
  45. #define get_obj_zval_ptr(node, Ts, should_free, type) _get_obj_zval_ptr(node, Ts, should_free, type TSRMLS_CC)
  46. #define get_obj_zval_ptr_ptr(node, Ts, should_free, type) _get_obj_zval_ptr_ptr(node, Ts, should_free, type TSRMLS_CC)
  47. /* Prototypes */
  48. static void zend_extension_statement_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC);
  49. static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC);
  50. static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC);
  51. #define RETURN_VALUE_USED(opline) (!((opline)->result.u.EA.type & EXT_TYPE_UNUSED))
  52. #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
  53. #define T(offset) (*(temp_variable *)((char *) Ts + offset))
  54. #define TEMP_VAR_STACK_LIMIT 2000
  55. static zend_always_inline void zend_pzval_unlock_func(zval *z, zend_free_op *should_free, int unref TSRMLS_DC)
  56. {
  57. if (!Z_DELREF_P(z)) {
  58. Z_SET_REFCOUNT_P(z, 1);
  59. Z_UNSET_ISREF_P(z);
  60. should_free->var = z;
  61. /* should_free->is_var = 1; */
  62. } else {
  63. should_free->var = 0;
  64. if (unref && Z_ISREF_P(z) && Z_REFCOUNT_P(z) == 1) {
  65. Z_UNSET_ISREF_P(z);
  66. }
  67. GC_ZVAL_CHECK_POSSIBLE_ROOT(z);
  68. }
  69. }
  70. static zend_always_inline void zend_pzval_unlock_free_func(zval *z TSRMLS_DC)
  71. {
  72. if (!Z_DELREF_P(z)) {
  73. if (z != &EG(uninitialized_zval)) {
  74. GC_REMOVE_ZVAL_FROM_BUFFER(z);
  75. zval_dtor(z);
  76. efree(z);
  77. }
  78. }
  79. }
  80. #define PZVAL_UNLOCK(z, f) zend_pzval_unlock_func(z, f, 1 TSRMLS_CC)
  81. #define PZVAL_UNLOCK_EX(z, f, u) zend_pzval_unlock_func(z, f, u TSRMLS_CC)
  82. #define PZVAL_UNLOCK_FREE(z) zend_pzval_unlock_free_func(z TSRMLS_CC)
  83. #define PZVAL_LOCK(z) Z_ADDREF_P((z))
  84. #define RETURN_VALUE_UNUSED(pzn) (((pzn)->u.EA.type & EXT_TYPE_UNUSED))
  85. #define SELECTIVE_PZVAL_LOCK(pzv, pzn) if (!RETURN_VALUE_UNUSED(pzn)) { PZVAL_LOCK(pzv); }
  86. #define AI_USE_PTR(ai) \
  87. if ((ai).ptr_ptr) { \
  88. (ai).ptr = *((ai).ptr_ptr); \
  89. (ai).ptr_ptr = &((ai).ptr); \
  90. } else { \
  91. (ai).ptr = NULL; \
  92. }
  93. #define AI_SET_PTR(ai, val) \
  94. (ai).ptr = (val); \
  95. (ai).ptr_ptr = &((ai).ptr);
  96. #define FREE_OP(should_free) \
  97. if (should_free.var) { \
  98. if ((zend_uintptr_t)should_free.var & 1L) { \
  99. zval_dtor((zval*)((zend_uintptr_t)should_free.var & ~1L)); \
  100. } else { \
  101. zval_ptr_dtor(&should_free.var); \
  102. } \
  103. }
  104. #define FREE_OP_IF_VAR(should_free) \
  105. if (should_free.var != NULL && (((zend_uintptr_t)should_free.var & 1L) == 0)) { \
  106. zval_ptr_dtor(&should_free.var); \
  107. }
  108. #define FREE_OP_VAR_PTR(should_free) \
  109. if (should_free.var) { \
  110. zval_ptr_dtor(&should_free.var); \
  111. }
  112. #define TMP_FREE(z) (zval*)(((zend_uintptr_t)(z)) | 1L)
  113. #define IS_TMP_FREE(should_free) ((zend_uintptr_t)should_free.var & 1L)
  114. #define INIT_PZVAL_COPY(z,v) \
  115. (z)->value = (v)->value; \
  116. Z_TYPE_P(z) = Z_TYPE_P(v); \
  117. Z_SET_REFCOUNT_P(z, 1); \
  118. Z_UNSET_ISREF_P(z);
  119. #define MAKE_REAL_ZVAL_PTR(val) \
  120. do { \
  121. zval *_tmp; \
  122. ALLOC_ZVAL(_tmp); \
  123. _tmp->value = (val)->value; \
  124. Z_TYPE_P(_tmp) = Z_TYPE_P(val); \
  125. Z_SET_REFCOUNT_P(_tmp, 1); \
  126. Z_UNSET_ISREF_P(_tmp); \
  127. val = _tmp; \
  128. } while (0)
  129. /* End of zend_execute_locks.h */
  130. #define CV_OF(i) (EG(current_execute_data)->CVs[i])
  131. #define CV_DEF_OF(i) (EG(active_op_array)->vars[i])
  132. #define CTOR_CALL_BIT 0x1
  133. #define CTOR_USED_BIT 0x2
  134. #define IS_CTOR_CALL(ce) (((zend_uintptr_t)(ce)) & CTOR_CALL_BIT)
  135. #define IS_CTOR_USED(ce) (((zend_uintptr_t)(ce)) & CTOR_USED_BIT)
  136. #define ENCODE_CTOR(ce, used) \
  137. ((zend_class_entry*)(((zend_uintptr_t)(ce)) | CTOR_CALL_BIT | ((used) ? CTOR_USED_BIT : 0)))
  138. #define DECODE_CTOR(ce) \
  139. ((zend_class_entry*)(((zend_uintptr_t)(ce)) & ~(CTOR_CALL_BIT|CTOR_USED_BIT)))
  140. ZEND_API zval** zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, zend_uint var)
  141. {
  142. return execute_data_ptr->CVs[var];
  143. }
  144. static zend_always_inline zval *_get_zval_ptr_tmp(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
  145. {
  146. return should_free->var = &T(node->u.var).tmp_var;
  147. }
  148. static zval *_get_zval_ptr_var_string_offset(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
  149. {
  150. temp_variable *T = &T(node->u.var);
  151. zval *str = T->str_offset.str;
  152. zval *ptr;
  153. /* string offset */
  154. ALLOC_ZVAL(ptr);
  155. T->str_offset.ptr = ptr;
  156. should_free->var = ptr;
  157. if (T->str_offset.str->type != IS_STRING
  158. || ((int)T->str_offset.offset < 0)
  159. || (T->str_offset.str->value.str.len <= (int)T->str_offset.offset)) {
  160. ptr->value.str.val = STR_EMPTY_ALLOC();
  161. ptr->value.str.len = 0;
  162. } else {
  163. ptr->value.str.val = estrndup(str->value.str.val + T->str_offset.offset, 1);
  164. ptr->value.str.len = 1;
  165. }
  166. PZVAL_UNLOCK_FREE(str);
  167. Z_SET_REFCOUNT_P(ptr, 1);
  168. Z_SET_ISREF_P(ptr);
  169. ptr->type = IS_STRING;
  170. return ptr;
  171. }
  172. static zend_always_inline zval *_get_zval_ptr_var(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
  173. {
  174. zval *ptr = T(node->u.var).var.ptr;
  175. if (EXPECTED(ptr != NULL)) {
  176. PZVAL_UNLOCK(ptr, should_free);
  177. return ptr;
  178. } else {
  179. return _get_zval_ptr_var_string_offset(node, Ts, should_free TSRMLS_CC);
  180. }
  181. }
  182. static zval **_get_zval_cv_lookup(zval ***ptr, zend_uint var, int type TSRMLS_DC)
  183. {
  184. zend_compiled_variable *cv = &CV_DEF_OF(var);
  185. if (!EG(active_symbol_table) ||
  186. zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
  187. switch (type) {
  188. case BP_VAR_R:
  189. case BP_VAR_UNSET:
  190. zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
  191. /* break missing intentionally */
  192. case BP_VAR_IS:
  193. return &EG(uninitialized_zval_ptr);
  194. break;
  195. case BP_VAR_RW:
  196. zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
  197. /* break missing intentionally */
  198. case BP_VAR_W:
  199. Z_ADDREF(EG(uninitialized_zval));
  200. if (!EG(active_symbol_table)) {
  201. *ptr = (zval**)EG(current_execute_data)->CVs + (EG(active_op_array)->last_var + var);
  202. **ptr = &EG(uninitialized_zval);
  203. } else {
  204. zend_hash_quick_update(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, &EG(uninitialized_zval_ptr), sizeof(zval *), (void **)ptr);
  205. }
  206. break;
  207. }
  208. }
  209. return *ptr;
  210. }
  211. static zend_always_inline zval *_get_zval_ptr_cv(const znode *node, const temp_variable *Ts, int type TSRMLS_DC)
  212. {
  213. zval ***ptr = &CV_OF(node->u.var);
  214. if (UNEXPECTED(*ptr == NULL)) {
  215. return *_get_zval_cv_lookup(ptr, node->u.var, type TSRMLS_CC);
  216. }
  217. return **ptr;
  218. }
  219. static inline zval *_get_zval_ptr(znode *node, const temp_variable *Ts, zend_free_op *should_free, int type TSRMLS_DC)
  220. {
  221. /* should_free->is_var = 0; */
  222. switch (node->op_type) {
  223. case IS_CONST:
  224. should_free->var = 0;
  225. return &node->u.constant;
  226. break;
  227. case IS_TMP_VAR:
  228. should_free->var = TMP_FREE(&T(node->u.var).tmp_var);
  229. return &T(node->u.var).tmp_var;
  230. break;
  231. case IS_VAR:
  232. return _get_zval_ptr_var(node, Ts, should_free TSRMLS_CC);
  233. break;
  234. case IS_UNUSED:
  235. should_free->var = 0;
  236. return NULL;
  237. break;
  238. case IS_CV:
  239. should_free->var = 0;
  240. return _get_zval_ptr_cv(node, Ts, type TSRMLS_CC);
  241. break;
  242. EMPTY_SWITCH_DEFAULT_CASE()
  243. }
  244. return NULL;
  245. }
  246. static zend_always_inline zval **_get_zval_ptr_ptr_var(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
  247. {
  248. zval** ptr_ptr = T(node->u.var).var.ptr_ptr;
  249. if (EXPECTED(ptr_ptr != NULL)) {
  250. PZVAL_UNLOCK(*ptr_ptr, should_free);
  251. } else {
  252. /* string offset */
  253. PZVAL_UNLOCK(T(node->u.var).str_offset.str, should_free);
  254. }
  255. return ptr_ptr;
  256. }
  257. static zend_always_inline zval **_get_zval_ptr_ptr_cv(const znode *node, const temp_variable *Ts, int type TSRMLS_DC)
  258. {
  259. zval ***ptr = &CV_OF(node->u.var);
  260. if (UNEXPECTED(*ptr == NULL)) {
  261. return _get_zval_cv_lookup(ptr, node->u.var, type TSRMLS_CC);
  262. }
  263. return *ptr;
  264. }
  265. static inline zval **_get_zval_ptr_ptr(const znode *node, const temp_variable *Ts, zend_free_op *should_free, int type TSRMLS_DC)
  266. {
  267. if (node->op_type == IS_CV) {
  268. should_free->var = 0;
  269. return _get_zval_ptr_ptr_cv(node, Ts, type TSRMLS_CC);
  270. } else if (node->op_type == IS_VAR) {
  271. return _get_zval_ptr_ptr_var(node, Ts, should_free TSRMLS_CC);
  272. } else {
  273. should_free->var = 0;
  274. return NULL;
  275. }
  276. }
  277. static zend_always_inline zval *_get_obj_zval_ptr_unused(TSRMLS_D)
  278. {
  279. if (EXPECTED(EG(This) != NULL)) {
  280. return EG(This);
  281. } else {
  282. zend_error_noreturn(E_ERROR, "Using $this when not in object context");
  283. return NULL;
  284. }
  285. }
  286. static inline zval **_get_obj_zval_ptr_ptr(const znode *op, const temp_variable *Ts, zend_free_op *should_free, int type TSRMLS_DC)
  287. {
  288. if (op->op_type == IS_UNUSED) {
  289. if (EXPECTED(EG(This) != NULL)) {
  290. /* this should actually never be modified, _ptr_ptr is modified only when
  291. the object is empty */
  292. should_free->var = 0;
  293. return &EG(This);
  294. } else {
  295. zend_error_noreturn(E_ERROR, "Using $this when not in object context");
  296. }
  297. }
  298. return get_zval_ptr_ptr(op, Ts, should_free, type);
  299. }
  300. static zend_always_inline zval **_get_obj_zval_ptr_ptr_unused(TSRMLS_D)
  301. {
  302. if (EXPECTED(EG(This) != NULL)) {
  303. return &EG(This);
  304. } else {
  305. zend_error_noreturn(E_ERROR, "Using $this when not in object context");
  306. return NULL;
  307. }
  308. }
  309. static inline zval *_get_obj_zval_ptr(znode *op, const temp_variable *Ts, zend_free_op *should_free, int type TSRMLS_DC)
  310. {
  311. if (op->op_type == IS_UNUSED) {
  312. if (EXPECTED(EG(This) != NULL)) {
  313. should_free->var = 0;
  314. return EG(This);
  315. } else {
  316. zend_error_noreturn(E_ERROR, "Using $this when not in object context");
  317. }
  318. }
  319. return get_zval_ptr(op, Ts, should_free, type);
  320. }
  321. static inline void zend_switch_free(temp_variable *T, int extended_value TSRMLS_DC)
  322. {
  323. if (T->var.ptr) {
  324. if (extended_value & ZEND_FE_RESET_VARIABLE) { /* foreach() free */
  325. Z_DELREF_P(T->var.ptr);
  326. }
  327. zval_ptr_dtor(&T->var.ptr);
  328. } else if (!T->var.ptr_ptr) {
  329. /* perform the equivalent of equivalent of a
  330. * quick & silent get_zval_ptr, and FREE_OP
  331. */
  332. PZVAL_UNLOCK_FREE(T->str_offset.str);
  333. }
  334. }
  335. static void zend_assign_to_variable_reference(zval **variable_ptr_ptr, zval **value_ptr_ptr TSRMLS_DC)
  336. {
  337. zval *variable_ptr = *variable_ptr_ptr;
  338. zval *value_ptr = *value_ptr_ptr;
  339. if (variable_ptr == EG(error_zval_ptr) || value_ptr==EG(error_zval_ptr)) {
  340. variable_ptr_ptr = &EG(uninitialized_zval_ptr);
  341. } else if (variable_ptr != value_ptr) {
  342. if (!PZVAL_IS_REF(value_ptr)) {
  343. /* break it away */
  344. Z_DELREF_P(value_ptr);
  345. if (Z_REFCOUNT_P(value_ptr)>0) {
  346. ALLOC_ZVAL(*value_ptr_ptr);
  347. **value_ptr_ptr = *value_ptr;
  348. value_ptr = *value_ptr_ptr;
  349. zendi_zval_copy_ctor(*value_ptr);
  350. }
  351. Z_SET_REFCOUNT_P(value_ptr, 1);
  352. Z_SET_ISREF_P(value_ptr);
  353. }
  354. *variable_ptr_ptr = value_ptr;
  355. Z_ADDREF_P(value_ptr);
  356. zval_ptr_dtor(&variable_ptr);
  357. } else if (!Z_ISREF_P(variable_ptr)) {
  358. if (variable_ptr_ptr == value_ptr_ptr) {
  359. SEPARATE_ZVAL(variable_ptr_ptr);
  360. } else if (variable_ptr==EG(uninitialized_zval_ptr)
  361. || Z_REFCOUNT_P(variable_ptr)>2) {
  362. /* we need to separate */
  363. Z_SET_REFCOUNT_P(variable_ptr, Z_REFCOUNT_P(variable_ptr) - 2);
  364. ALLOC_ZVAL(*variable_ptr_ptr);
  365. **variable_ptr_ptr = *variable_ptr;
  366. zval_copy_ctor(*variable_ptr_ptr);
  367. *value_ptr_ptr = *variable_ptr_ptr;
  368. Z_SET_REFCOUNT_PP(variable_ptr_ptr, 2);
  369. }
  370. Z_SET_ISREF_PP(variable_ptr_ptr);
  371. }
  372. }
  373. /* this should modify object only if it's empty */
  374. static inline void make_real_object(zval **object_ptr TSRMLS_DC)
  375. {
  376. if (Z_TYPE_PP(object_ptr) == IS_NULL
  377. || (Z_TYPE_PP(object_ptr) == IS_BOOL && Z_LVAL_PP(object_ptr) == 0)
  378. || (Z_TYPE_PP(object_ptr) == IS_STRING && Z_STRLEN_PP(object_ptr) == 0)
  379. ) {
  380. zend_error(E_STRICT, "Creating default object from empty value");
  381. SEPARATE_ZVAL_IF_NOT_REF(object_ptr);
  382. zval_dtor(*object_ptr);
  383. object_init(*object_ptr);
  384. }
  385. }
  386. static inline char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, ulong fetch_type, const char **class_name, zend_class_entry **pce TSRMLS_DC)
  387. {
  388. *pce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, (fetch_type | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD) TSRMLS_CC);
  389. *class_name = (*pce) ? (*pce)->name: cur_arg_info->class_name;
  390. if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) {
  391. return "implement interface ";
  392. } else {
  393. return "be an instance of ";
  394. }
  395. }
  396. static inline int zend_verify_arg_error(const zend_function *zf, zend_uint arg_num, const zend_arg_info *cur_arg_info, const char *need_msg, const char *need_kind, const char *given_msg, char *given_kind TSRMLS_DC)
  397. {
  398. zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
  399. char *fname = zf->common.function_name;
  400. char *fsep;
  401. char *fclass;
  402. if (zf->common.scope) {
  403. fsep = "::";
  404. fclass = zf->common.scope->name;
  405. } else {
  406. fsep = "";
  407. fclass = "";
  408. }
  409. if (ptr && ptr->op_array) {
  410. zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->op_array->filename, ptr->opline->lineno);
  411. } else {
  412. zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s%s, %s%s given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind);
  413. }
  414. return 0;
  415. }
  416. static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zval *arg, ulong fetch_type TSRMLS_DC)
  417. {
  418. zend_arg_info *cur_arg_info;
  419. char *need_msg;
  420. zend_class_entry *ce;
  421. if (!zf->common.arg_info
  422. || arg_num>zf->common.num_args) {
  423. return 1;
  424. }
  425. cur_arg_info = &zf->common.arg_info[arg_num-1];
  426. if (cur_arg_info->class_name) {
  427. const char *class_name;
  428. if (!arg) {
  429. need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
  430. return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, class_name, "none", "" TSRMLS_CC);
  431. }
  432. if (Z_TYPE_P(arg) == IS_OBJECT) {
  433. need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
  434. if (!ce || !instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) {
  435. return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, class_name, "instance of ", Z_OBJCE_P(arg)->name TSRMLS_CC);
  436. }
  437. } else if (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null) {
  438. need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
  439. return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, class_name, zend_zval_type_name(arg), "" TSRMLS_CC);
  440. }
  441. } else if (cur_arg_info->array_type_hint) {
  442. if (!arg) {
  443. return zend_verify_arg_error(zf, arg_num, cur_arg_info, "be an array", "", "none", "" TSRMLS_CC);
  444. }
  445. if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) {
  446. return zend_verify_arg_error(zf, arg_num, cur_arg_info, "be an array", "", zend_zval_type_name(arg), "" TSRMLS_CC);
  447. }
  448. }
  449. return 1;
  450. }
  451. static inline void zend_assign_to_object(znode *result, zval **object_ptr, zval *property_name, znode *value_op, const temp_variable *Ts, int opcode TSRMLS_DC)
  452. {
  453. zval *object = *object_ptr;
  454. zend_free_op free_value;
  455. zval *value = get_zval_ptr(value_op, Ts, &free_value, BP_VAR_R);
  456. zval **retval = &T(result->u.var).var.ptr;
  457. if (Z_TYPE_P(object) != IS_OBJECT) {
  458. if (object == EG(error_zval_ptr)) {
  459. if (!RETURN_VALUE_UNUSED(result)) {
  460. *retval = EG(uninitialized_zval_ptr);
  461. PZVAL_LOCK(*retval);
  462. }
  463. FREE_OP(free_value);
  464. return;
  465. }
  466. if (Z_TYPE_P(object) == IS_NULL ||
  467. (Z_TYPE_P(object) == IS_BOOL && Z_LVAL_P(object) == 0) ||
  468. (Z_TYPE_P(object) == IS_STRING && Z_STRLEN_P(object) == 0)) {
  469. SEPARATE_ZVAL_IF_NOT_REF(object_ptr);
  470. zval_dtor(*object_ptr);
  471. object_init(*object_ptr);
  472. object = *object_ptr;
  473. zend_error(E_STRICT, "Creating default object from empty value");
  474. } else {
  475. zend_error(E_WARNING, "Attempt to assign property of non-object");
  476. if (!RETURN_VALUE_UNUSED(result)) {
  477. *retval = EG(uninitialized_zval_ptr);
  478. PZVAL_LOCK(*retval);
  479. }
  480. FREE_OP(free_value);
  481. return;
  482. }
  483. }
  484. /* separate our value if necessary */
  485. if (value_op->op_type == IS_TMP_VAR) {
  486. zval *orig_value = value;
  487. ALLOC_ZVAL(value);
  488. *value = *orig_value;
  489. Z_UNSET_ISREF_P(value);
  490. Z_SET_REFCOUNT_P(value, 0);
  491. } else if (value_op->op_type == IS_CONST) {
  492. zval *orig_value = value;
  493. ALLOC_ZVAL(value);
  494. *value = *orig_value;
  495. Z_UNSET_ISREF_P(value);
  496. Z_SET_REFCOUNT_P(value, 0);
  497. zval_copy_ctor(value);
  498. }
  499. Z_ADDREF_P(value);
  500. if (opcode == ZEND_ASSIGN_OBJ) {
  501. if (!Z_OBJ_HT_P(object)->write_property) {
  502. zend_error(E_WARNING, "Attempt to assign property of non-object");
  503. if (!RETURN_VALUE_UNUSED(result)) {
  504. *retval = EG(uninitialized_zval_ptr);
  505. PZVAL_LOCK(*retval);
  506. }
  507. if (value_op->op_type == IS_TMP_VAR) {
  508. FREE_ZVAL(value);
  509. } else if (value_op->op_type == IS_CONST) {
  510. zval_ptr_dtor(&value);
  511. }
  512. FREE_OP(free_value);
  513. return;
  514. }
  515. Z_OBJ_HT_P(object)->write_property(object, property_name, value TSRMLS_CC);
  516. } else {
  517. /* Note: property_name in this case is really the array index! */
  518. if (!Z_OBJ_HT_P(object)->write_dimension) {
  519. zend_error_noreturn(E_ERROR, "Cannot use object as array");
  520. }
  521. Z_OBJ_HT_P(object)->write_dimension(object, property_name, value TSRMLS_CC);
  522. }
  523. if (!RETURN_VALUE_UNUSED(result) && !EG(exception)) {
  524. AI_SET_PTR(T(result->u.var).var, value);
  525. PZVAL_LOCK(value);
  526. }
  527. zval_ptr_dtor(&value);
  528. FREE_OP_IF_VAR(free_value);
  529. }
  530. static inline int zend_assign_to_string_offset(const temp_variable *T, const zval *value, int value_type TSRMLS_DC)
  531. {
  532. if (Z_TYPE_P(T->str_offset.str) == IS_STRING) {
  533. if (((int)T->str_offset.offset < 0)) {
  534. zend_error(E_WARNING, "Illegal string offset: %d", T->str_offset.offset);
  535. return 0;
  536. }
  537. if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) {
  538. Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1);
  539. memset(Z_STRVAL_P(T->str_offset.str) + Z_STRLEN_P(T->str_offset.str),
  540. ' ',
  541. T->str_offset.offset - Z_STRLEN_P(T->str_offset.str));
  542. Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0;
  543. Z_STRLEN_P(T->str_offset.str) = T->str_offset.offset+1;
  544. }
  545. if (Z_TYPE_P(value) != IS_STRING) {
  546. zval tmp = *value;
  547. if (value_type != IS_TMP_VAR) {
  548. zval_copy_ctor(&tmp);
  549. }
  550. convert_to_string(&tmp);
  551. Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL(tmp)[0];
  552. STR_FREE(Z_STRVAL(tmp));
  553. } else {
  554. Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(value)[0];
  555. if (value_type == IS_TMP_VAR) {
  556. /* we can safely free final_value here
  557. * because separation is done only
  558. * in case value_type == IS_VAR */
  559. STR_FREE(Z_STRVAL_P(value));
  560. }
  561. }
  562. /*
  563. * the value of an assignment to a string offset is undefined
  564. T(result->u.var).var = &T->str_offset.str;
  565. */
  566. }
  567. return 1;
  568. }
  569. static inline zval* zend_assign_to_variable(zval **variable_ptr_ptr, zval *value, int is_tmp_var TSRMLS_DC)
  570. {
  571. zval *variable_ptr = *variable_ptr_ptr;
  572. zval garbage;
  573. if (variable_ptr == EG(error_zval_ptr)) {
  574. if (is_tmp_var) {
  575. zval_dtor(value);
  576. }
  577. return EG(uninitialized_zval_ptr);
  578. }
  579. if (Z_TYPE_P(variable_ptr) == IS_OBJECT && Z_OBJ_HANDLER_P(variable_ptr, set)) {
  580. Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr_ptr, value TSRMLS_CC);
  581. return variable_ptr;
  582. }
  583. if (PZVAL_IS_REF(variable_ptr)) {
  584. if (variable_ptr!=value) {
  585. zend_uint refcount = Z_REFCOUNT_P(variable_ptr);
  586. garbage = *variable_ptr;
  587. *variable_ptr = *value;
  588. Z_SET_REFCOUNT_P(variable_ptr, refcount);
  589. Z_SET_ISREF_P(variable_ptr);
  590. if (!is_tmp_var) {
  591. zendi_zval_copy_ctor(*variable_ptr);
  592. }
  593. zendi_zval_dtor(garbage);
  594. return variable_ptr;
  595. }
  596. } else {
  597. if (Z_DELREF_P(variable_ptr)==0) {
  598. if (!is_tmp_var) {
  599. if (variable_ptr==value) {
  600. Z_ADDREF_P(variable_ptr);
  601. } else if (PZVAL_IS_REF(value)) {
  602. garbage = *variable_ptr;
  603. *variable_ptr = *value;
  604. INIT_PZVAL(variable_ptr);
  605. zval_copy_ctor(variable_ptr);
  606. zendi_zval_dtor(garbage);
  607. return variable_ptr;
  608. } else {
  609. Z_ADDREF_P(value);
  610. *variable_ptr_ptr = value;
  611. if (variable_ptr != &EG(uninitialized_zval)) {
  612. GC_REMOVE_ZVAL_FROM_BUFFER(variable_ptr);
  613. zval_dtor(variable_ptr);
  614. efree(variable_ptr);
  615. }
  616. return value;
  617. }
  618. } else {
  619. garbage = *variable_ptr;
  620. *variable_ptr = *value;
  621. INIT_PZVAL(variable_ptr);
  622. zendi_zval_dtor(garbage);
  623. return variable_ptr;
  624. }
  625. } else { /* we need to split */
  626. if (!is_tmp_var) {
  627. if (PZVAL_IS_REF(value) && Z_REFCOUNT_P(value) > 0) {
  628. ALLOC_ZVAL(variable_ptr);
  629. *variable_ptr_ptr = variable_ptr;
  630. *variable_ptr = *value;
  631. zval_copy_ctor(variable_ptr);
  632. Z_SET_REFCOUNT_P(variable_ptr, 1);
  633. } else {
  634. *variable_ptr_ptr = value;
  635. Z_ADDREF_P(value);
  636. }
  637. } else {
  638. ALLOC_ZVAL(*variable_ptr_ptr);
  639. Z_SET_REFCOUNT_P(value, 1);
  640. **variable_ptr_ptr = *value;
  641. }
  642. }
  643. Z_UNSET_ISREF_PP(variable_ptr_ptr);
  644. }
  645. return *variable_ptr_ptr;
  646. }
  647. /* Utility Functions for Extensions */
  648. static void zend_extension_statement_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
  649. {
  650. if (extension->statement_handler) {
  651. extension->statement_handler(op_array);
  652. }
  653. }
  654. static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
  655. {
  656. if (extension->fcall_begin_handler) {
  657. extension->fcall_begin_handler(op_array);
  658. }
  659. }
  660. static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
  661. {
  662. if (extension->fcall_end_handler) {
  663. extension->fcall_end_handler(op_array);
  664. }
  665. }
  666. static inline HashTable *zend_get_target_symbol_table(const zend_op *opline, const temp_variable *Ts, int type, const zval *variable TSRMLS_DC)
  667. {
  668. switch (opline->op2.u.EA.type) {
  669. case ZEND_FETCH_LOCAL:
  670. if (!EG(active_symbol_table)) {
  671. zend_rebuild_symbol_table(TSRMLS_C);
  672. }
  673. return EG(active_symbol_table);
  674. break;
  675. case ZEND_FETCH_GLOBAL:
  676. case ZEND_FETCH_GLOBAL_LOCK:
  677. return &EG(symbol_table);
  678. break;
  679. case ZEND_FETCH_STATIC:
  680. if (!EG(active_op_array)->static_variables) {
  681. ALLOC_HASHTABLE(EG(active_op_array)->static_variables);
  682. zend_hash_init(EG(active_op_array)->static_variables, 2, NULL, ZVAL_PTR_DTOR, 0);
  683. }
  684. return EG(active_op_array)->static_variables;
  685. break;
  686. EMPTY_SWITCH_DEFAULT_CASE()
  687. }
  688. return NULL;
  689. }
  690. static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int type TSRMLS_DC)
  691. {
  692. zval **retval;
  693. char *offset_key;
  694. int offset_key_length;
  695. long index;
  696. switch (dim->type) {
  697. case IS_NULL:
  698. offset_key = "";
  699. offset_key_length = 0;
  700. goto fetch_string_dim;
  701. case IS_STRING:
  702. offset_key = dim->value.str.val;
  703. offset_key_length = dim->value.str.len;
  704. fetch_string_dim:
  705. if (zend_symtable_find(ht, offset_key, offset_key_length+1, (void **) &retval) == FAILURE) {
  706. switch (type) {
  707. case BP_VAR_R:
  708. zend_error(E_NOTICE, "Undefined index: %s", offset_key);
  709. /* break missing intentionally */
  710. case BP_VAR_UNSET:
  711. case BP_VAR_IS:
  712. retval = &EG(uninitialized_zval_ptr);
  713. break;
  714. case BP_VAR_RW:
  715. zend_error(E_NOTICE,"Undefined index: %s", offset_key);
  716. /* break missing intentionally */
  717. case BP_VAR_W: {
  718. zval *new_zval = &EG(uninitialized_zval);
  719. Z_ADDREF_P(new_zval);
  720. zend_symtable_update(ht, offset_key, offset_key_length+1, &new_zval, sizeof(zval *), (void **) &retval);
  721. }
  722. break;
  723. }
  724. }
  725. break;
  726. case IS_DOUBLE:
  727. index = zend_dval_to_lval(Z_DVAL_P(dim));
  728. goto num_index;
  729. case IS_RESOURCE:
  730. zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(dim), Z_LVAL_P(dim));
  731. /* Fall Through */
  732. case IS_BOOL:
  733. case IS_LONG:
  734. index = Z_LVAL_P(dim);
  735. num_index:
  736. if (zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) {
  737. switch (type) {
  738. case BP_VAR_R:
  739. zend_error(E_NOTICE,"Undefined offset: %ld", index);
  740. /* break missing intentionally */
  741. case BP_VAR_UNSET:
  742. case BP_VAR_IS:
  743. retval = &EG(uninitialized_zval_ptr);
  744. break;
  745. case BP_VAR_RW:
  746. zend_error(E_NOTICE,"Undefined offset: %ld", index);
  747. /* break missing intentionally */
  748. case BP_VAR_W: {
  749. zval *new_zval = &EG(uninitialized_zval);
  750. Z_ADDREF_P(new_zval);
  751. zend_hash_index_update(ht, index, &new_zval, sizeof(zval *), (void **) &retval);
  752. }
  753. break;
  754. }
  755. }
  756. break;
  757. default:
  758. zend_error(E_WARNING, "Illegal offset type");
  759. return (type == BP_VAR_W || type == BP_VAR_RW) ?
  760. &EG(error_zval_ptr) : &EG(uninitialized_zval_ptr);
  761. }
  762. return retval;
  763. }
  764. static void zend_fetch_dimension_address(temp_variable *result, zval **container_ptr, zval *dim, int dim_is_tmp_var, int type TSRMLS_DC)
  765. {
  766. zval *container = *container_ptr;
  767. zval **retval;
  768. switch (Z_TYPE_P(container)) {
  769. case IS_ARRAY:
  770. if (type != BP_VAR_UNSET && Z_REFCOUNT_P(container)>1 && !PZVAL_IS_REF(container)) {
  771. SEPARATE_ZVAL(container_ptr);
  772. container = *container_ptr;
  773. }
  774. fetch_from_array:
  775. if (dim == NULL) {
  776. zval *new_zval = &EG(uninitialized_zval);
  777. Z_ADDREF_P(new_zval);
  778. if (zend_hash_next_index_insert(Z_ARRVAL_P(container), &new_zval, sizeof(zval *), (void **) &retval) == FAILURE) {
  779. zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
  780. retval = &EG(error_zval_ptr);
  781. Z_DELREF_P(new_zval);
  782. }
  783. } else {
  784. retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, type TSRMLS_CC);
  785. }
  786. result->var.ptr_ptr = retval;
  787. PZVAL_LOCK(*retval);
  788. return;
  789. break;
  790. case IS_NULL:
  791. if (container == EG(error_zval_ptr)) {
  792. result->var.ptr_ptr = &EG(error_zval_ptr);
  793. PZVAL_LOCK(EG(error_zval_ptr));
  794. } else if (type != BP_VAR_UNSET) {
  795. convert_to_array:
  796. if (!PZVAL_IS_REF(container)) {
  797. SEPARATE_ZVAL(container_ptr);
  798. container = *container_ptr;
  799. }
  800. zval_dtor(container);
  801. array_init(container);
  802. goto fetch_from_array;
  803. } else {
  804. /* for read-mode only */
  805. result->var.ptr_ptr = &EG(uninitialized_zval_ptr);
  806. PZVAL_LOCK(EG(uninitialized_zval_ptr));
  807. }
  808. return;
  809. break;
  810. case IS_STRING: {
  811. zval tmp;
  812. if (type != BP_VAR_UNSET && Z_STRLEN_P(container)==0) {
  813. goto convert_to_array;
  814. }
  815. if (dim == NULL) {
  816. zend_error_noreturn(E_ERROR, "[] operator not supported for strings");
  817. }
  818. if (Z_TYPE_P(dim) != IS_LONG) {
  819. switch(Z_TYPE_P(dim)) {
  820. /* case IS_LONG: */
  821. case IS_STRING:
  822. case IS_DOUBLE:
  823. case IS_NULL:
  824. case IS_BOOL:
  825. /* do nothing */
  826. break;
  827. default:
  828. zend_error(E_WARNING, "Illegal offset type");
  829. break;
  830. }
  831. tmp = *dim;
  832. zval_copy_ctor(&tmp);
  833. convert_to_long(&tmp);
  834. dim = &tmp;
  835. }
  836. if (type != BP_VAR_UNSET) {
  837. SEPARATE_ZVAL_IF_NOT_REF(container_ptr);
  838. }
  839. container = *container_ptr;
  840. result->str_offset.str = container;
  841. PZVAL_LOCK(container);
  842. result->str_offset.offset = Z_LVAL_P(dim);
  843. result->var.ptr_ptr = NULL;
  844. result->var.ptr = NULL;
  845. return;
  846. }
  847. break;
  848. case IS_OBJECT:
  849. if (!Z_OBJ_HT_P(container)->read_dimension) {
  850. zend_error_noreturn(E_ERROR, "Cannot use object as array");
  851. } else {
  852. zval *overloaded_result;
  853. if (dim_is_tmp_var) {
  854. zval *orig = dim;
  855. MAKE_REAL_ZVAL_PTR(dim);
  856. ZVAL_NULL(orig);
  857. }
  858. overloaded_result = Z_OBJ_HT_P(container)->read_dimension(container, dim, type TSRMLS_CC);
  859. if (overloaded_result) {
  860. if (!Z_ISREF_P(overloaded_result)) {
  861. if (Z_REFCOUNT_P(overloaded_result) > 0) {
  862. zval *tmp = overloaded_result;
  863. ALLOC_ZVAL(overloaded_result);
  864. *overloaded_result = *tmp;
  865. zval_copy_ctor(overloaded_result);
  866. Z_UNSET_ISREF_P(overloaded_result);
  867. Z_SET_REFCOUNT_P(overloaded_result, 0);
  868. }
  869. if (Z_TYPE_P(overloaded_result) != IS_OBJECT) {
  870. zend_class_entry *ce = Z_OBJCE_P(container);
  871. zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ce->name);
  872. }
  873. }
  874. retval = &overloaded_result;
  875. } else {
  876. retval = &EG(error_zval_ptr);
  877. }
  878. AI_SET_PTR(result->var, *retval);
  879. PZVAL_LOCK(*retval);
  880. if (dim_is_tmp_var) {
  881. zval_ptr_dtor(&dim);
  882. }
  883. }
  884. return;
  885. break;
  886. case IS_BOOL:
  887. if (type != BP_VAR_UNSET && Z_LVAL_P(container)==0) {
  888. goto convert_to_array;
  889. }
  890. /* break missing intentionally */
  891. default:
  892. if (type == BP_VAR_UNSET) {
  893. zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
  894. AI_SET_PTR(result->var, EG(uninitialized_zval_ptr));
  895. PZVAL_LOCK(EG(uninitialized_zval_ptr));
  896. } else {
  897. zend_error(E_WARNING, "Cannot use a scalar value as an array");
  898. result->var.ptr_ptr = &EG(error_zval_ptr);
  899. PZVAL_LOCK(EG(error_zval_ptr));
  900. }
  901. break;
  902. }
  903. }
  904. static void zend_fetch_dimension_address_read(temp_variable *result, zval **container_ptr, zval *dim, int dim_is_tmp_var, int type TSRMLS_DC)
  905. {
  906. zval *container = *container_ptr;
  907. zval **retval;
  908. switch (Z_TYPE_P(container)) {
  909. case IS_ARRAY:
  910. retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, type TSRMLS_CC);
  911. if (result) {
  912. AI_SET_PTR(result->var, *retval);
  913. PZVAL_LOCK(*retval);
  914. }
  915. return;
  916. break;
  917. case IS_NULL:
  918. if (result) {
  919. AI_SET_PTR(result->var, EG(uninitialized_zval_ptr));
  920. PZVAL_LOCK(EG(uninitialized_zval_ptr));
  921. }
  922. return;
  923. break;
  924. case IS_STRING: {
  925. zval tmp;
  926. if (Z_TYPE_P(dim) != IS_LONG) {
  927. switch(Z_TYPE_P(dim)) {
  928. /* case IS_LONG: */
  929. case IS_STRING:
  930. case IS_DOUBLE:
  931. case IS_NULL:
  932. case IS_BOOL:
  933. /* do nothing */
  934. break;
  935. default:
  936. zend_error(E_WARNING, "Illegal offset type");
  937. break;
  938. }
  939. tmp = *dim;
  940. zval_copy_ctor(&tmp);
  941. convert_to_long(&tmp);
  942. dim = &tmp;
  943. }
  944. if (result) {
  945. if (Z_LVAL_P(dim) < 0 || Z_STRLEN_P(container) <= Z_LVAL_P(dim)) {
  946. zend_error(E_NOTICE, "Uninitialized string offset: %ld", Z_LVAL_P(dim));
  947. }
  948. result->str_offset.str = container;
  949. PZVAL_LOCK(container);
  950. result->str_offset.offset = Z_LVAL_P(dim);
  951. result->var.ptr_ptr = NULL;
  952. result->var.ptr = NULL;
  953. }
  954. return;
  955. }
  956. break;
  957. case IS_OBJECT:
  958. if (!Z_OBJ_HT_P(container)->read_dimension) {
  959. zend_error_noreturn(E_ERROR, "Cannot use object as array");
  960. } else {
  961. zval *overloaded_result;
  962. if (dim_is_tmp_var) {
  963. zval *orig = dim;
  964. MAKE_REAL_ZVAL_PTR(dim);
  965. ZVAL_NULL(orig);
  966. }
  967. overloaded_result = Z_OBJ_HT_P(container)->read_dimension(container, dim, type TSRMLS_CC);
  968. if (overloaded_result) {
  969. if (result) {
  970. AI_SET_PTR(result->var, overloaded_result);
  971. PZVAL_LOCK(overloaded_result);
  972. } else if (Z_REFCOUNT_P(overloaded_result) == 0) {
  973. /* Destroy unused result from offsetGet() magic method */
  974. Z_SET_REFCOUNT_P(overloaded_result, 1);
  975. zval_ptr_dtor(&overloaded_result);
  976. }
  977. } else if (result) {
  978. AI_SET_PTR(result->var, EG(uninitialized_zval_ptr));
  979. PZVAL_LOCK(EG(uninitialized_zval_ptr));
  980. }
  981. if (dim_is_tmp_var) {
  982. zval_ptr_dtor(&dim);
  983. }
  984. }
  985. return;
  986. break;
  987. default:
  988. if (result) {
  989. AI_SET_PTR(result->var, EG(uninitialized_zval_ptr));
  990. PZVAL_LOCK(EG(uninitialized_zval_ptr));
  991. }
  992. return;
  993. break;
  994. }
  995. }
  996. static void zend_fetch_property_address(temp_variable *result, zval **container_ptr, zval *prop_ptr, int type TSRMLS_DC)
  997. {
  998. zval *container = *container_ptr;;
  999. if (Z_TYPE_P(container) != IS_OBJECT) {
  1000. if (container == EG(error_zval_ptr)) {
  1001. result->var.ptr_ptr = &EG(error_zval_ptr);
  1002. PZVAL_LOCK(*result->var.ptr_ptr);
  1003. return;
  1004. }
  1005. /* this should modify object only if it's empty */
  1006. if (type != BP_VAR_UNSET &&
  1007. ((Z_TYPE_P(container) == IS_NULL ||
  1008. (Z_TYPE_P(container) == IS_BOOL && Z_LVAL_P(container)==0) ||
  1009. (Z_TYPE_P(container) == IS_STRING && Z_STRLEN_P(container)==0)))) {
  1010. if (!PZVAL_IS_REF(container)) {
  1011. SEPARATE_ZVAL(container_ptr);
  1012. container = *container_ptr;
  1013. }
  1014. object_init(container);
  1015. } else {
  1016. zend_error(E_WARNING, "Attempt to modify property of non-object");
  1017. result->var.ptr_ptr = &EG(error_zval_ptr);
  1018. PZVAL_LOCK(EG(error_zval_ptr));
  1019. return;
  1020. }
  1021. }
  1022. if (Z_OBJ_HT_P(container)->get_property_ptr_ptr) {
  1023. zval **ptr_ptr = Z_OBJ_HT_P(container)->get_property_ptr_ptr(container, prop_ptr TSRMLS_CC);
  1024. if (NULL == ptr_ptr) {
  1025. zval *ptr;
  1026. if (Z_OBJ_HT_P(container)->read_property &&
  1027. (ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type TSRMLS_CC)) != NULL) {
  1028. AI_SET_PTR(result->var, ptr);
  1029. PZVAL_LOCK(ptr);
  1030. } else {
  1031. zend_error_noreturn(E_ERROR, "Cannot access undefined property for object with overloaded property access");
  1032. }
  1033. } else {
  1034. result->var.ptr_ptr = ptr_ptr;
  1035. PZVAL_LOCK(*ptr_ptr);
  1036. }
  1037. } else if (Z_OBJ_HT_P(container)->read_property) {
  1038. zval *ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type TSRMLS_CC);
  1039. AI_SET_PTR(result->var, ptr);
  1040. PZVAL_LOCK(ptr);
  1041. } else {
  1042. zend_error(E_WARNING, "This object doesn't support property references");
  1043. result->var.ptr_ptr = &EG(error_zval_ptr);
  1044. PZVAL_LOCK(EG(error_zval_ptr));
  1045. }
  1046. }
  1047. static inline zend_brk_cont_element* zend_brk_cont(const zval *nest_levels_zval, int array_offset, const zend_op_array *op_array, const temp_variable *Ts TSRMLS_DC)
  1048. {
  1049. zval tmp;
  1050. int nest_levels, original_nest_levels;
  1051. zend_brk_cont_element *jmp_to;
  1052. if (nest_levels_zval->type != IS_LONG) {
  1053. tmp = *nest_levels_zval;
  1054. zval_copy_ctor(&tmp);
  1055. convert_to_long(&tmp);
  1056. nest_levels = tmp.value.lval;
  1057. } else {
  1058. nest_levels = nest_levels_zval->value.lval;
  1059. }
  1060. original_nest_levels = nest_levels;
  1061. do {
  1062. if (array_offset==-1) {
  1063. zend_error_noreturn(E_ERROR, "Cannot break/continue %d level%s", original_nest_levels, (original_nest_levels == 1) ? "" : "s");
  1064. }
  1065. jmp_to = &op_array->brk_cont_array[array_offset];
  1066. if (nest_levels>1) {
  1067. zend_op *brk_opline = &op_array->opcodes[jmp_to->brk];
  1068. switch (brk_opline->opcode) {
  1069. case ZEND_SWITCH_FREE:
  1070. if (brk_opline->op1.u.EA.type != EXT_TYPE_FREE_ON_RETURN) {
  1071. zend_switch_free(&T(brk_opline->op1.u.var), brk_opline->extended_value TSRMLS_CC);
  1072. }
  1073. break;
  1074. case ZEND_FREE:
  1075. if (brk_opline->op1.u.EA.type != EXT_TYPE_FREE_ON_RETURN) {
  1076. zendi_zval_dtor(T(brk_opline->op1.u.var).tmp_var);
  1077. }
  1078. break;
  1079. }
  1080. }
  1081. array_offset = jmp_to->parent;
  1082. } while (--nest_levels > 0);
  1083. return jmp_to;
  1084. }
  1085. #if ZEND_INTENSIVE_DEBUGGING
  1086. #define CHECK_SYMBOL_TABLES() \
  1087. zend_hash_apply(&EG(symbol_table), (apply_func_t) zend_check_symbol TSRMLS_CC); \
  1088. if (&EG(symbol_table)!=EG(active_symbol_table)) { \
  1089. zend_hash_apply(EG(active_symbol_table), (apply_func_t) zend_check_symbol TSRMLS_CC); \
  1090. }
  1091. static int zend_check_symbol(zval **pz TSRMLS_DC)
  1092. {
  1093. if (Z_TYPE_PP(pz) > 9) {
  1094. fprintf(stderr, "Warning! %x has invalid type!\n", *pz);
  1095. } else if (Z_TYPE_PP(pz) == IS_ARRAY) {
  1096. zend_hash_apply(Z_ARRVAL_PP(pz), (apply_func_t) zend_check_symbol TSRMLS_CC);
  1097. } else if (Z_TYPE_PP(pz) == IS_OBJECT) {
  1098. /* OBJ-TBI - doesn't support new object model! */
  1099. zend_hash_apply(Z_OBJPROP_PP(pz), (apply_func_t) zend_check_symbol TSRMLS_CC);
  1100. }
  1101. return 0;
  1102. }
  1103. #else
  1104. #define CHECK_SYMBOL_TABLES()
  1105. #endif
  1106. ZEND_API opcode_handler_t *zend_opcode_handlers;
  1107. ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC)
  1108. {
  1109. zval **return_value_ptr = &(*(temp_variable *)((char *) execute_data_ptr->Ts + execute_data_ptr->opline->result.u.var)).var.ptr;
  1110. ((zend_internal_function *) execute_data_ptr->function_state.function)->handler(execute_data_ptr->opline->extended_value, *return_value_ptr, execute_data_ptr->function_state.function->common.return_reference?return_value_ptr:NULL, execute_data_ptr->object, return_value_used TSRMLS_CC);
  1111. }
  1112. #define ZEND_VM_NEXT_OPCODE() \
  1113. CHECK_SYMBOL_TABLES() \
  1114. EX(opline)++; \
  1115. ZEND_VM_CONTINUE()
  1116. #define ZEND_VM_SET_OPCODE(new_op) \
  1117. CHECK_SYMBOL_TABLES() \
  1118. EX(opline) = new_op
  1119. #define ZEND_VM_JMP(new_op) \
  1120. CHECK_SYMBOL_TABLES() \
  1121. if (EXPECTED(!EG(exception))) { \
  1122. EX(opline) = new_op; \
  1123. } \
  1124. ZEND_VM_CONTINUE()
  1125. #define ZEND_VM_INC_OPCODE() \
  1126. EX(opline)++
  1127. #include "zend_vm_execute.h"
  1128. ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler)
  1129. {
  1130. if (opcode != ZEND_USER_OPCODE) {
  1131. zend_user_opcodes[opcode] = ZEND_USER_OPCODE;
  1132. zend_user_opcode_handlers[opcode] = handler;
  1133. return SUCCESS;
  1134. }
  1135. return FAILURE;
  1136. }
  1137. ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode)
  1138. {
  1139. return zend_user_opcode_handlers[opcode];
  1140. }
  1141. ZEND_API zval *zend_get_zval_ptr(znode *node, const temp_variable *Ts, zend_free_op *should_free, int type TSRMLS_DC) {
  1142. return get_zval_ptr(node, Ts, should_free, type);
  1143. }
  1144. ZEND_API zval **zend_get_zval_ptr_ptr(const znode *node, const temp_variable *Ts, zend_free_op *should_free, int type TSRMLS_DC) {
  1145. return get_zval_ptr_ptr(node, Ts, should_free, type);
  1146. }
  1147. /*
  1148. * Local variables:
  1149. * tab-width: 4
  1150. * c-basic-offset: 4
  1151. * indent-tabs-mode: t
  1152. * End:
  1153. */