Permalink
Browse files

- Start adding parsed variable checks.

  • Loading branch information...
1 parent 880e7d8 commit ac7ed464b5f85b1aff8224f061baa9b954abff7f @andigutmans andigutmans committed Dec 16, 2001
Showing with 28 additions and 3 deletions.
  1. +22 −0 Zend/zend_compile.c
  2. +2 −0 Zend/zend_compile.h
  3. +4 −3 Zend/zend_language_parser.y
View
@@ -528,6 +528,28 @@ void zend_do_if_end(TSRMLS_D)
DEC_BPC(CG(active_op_array));
}
+#if 0
+/* variable parsing type (compile-time) */
+#define ZEND_PARSED_MEMBER (1<<0)
+#define ZEND_PARSED_METHOD_CALL (1<<1)
+#define ZEND_PARSED_STATIC_MEMBER (1<<2)
+#define ZEND_PARSED_FUNCTION_CALL (1<<3)
+#define ZEND_PARSED_VARIABLE (1<<4)
+
+#endif
+
+void zend_check_writable_variable(znode *variable)
+{
+ zend_uint type = variable->u.EA.type;
+
+ if (type & ZEND_PARSED_METHOD_CALL) {
+ zend_error(E_ERROR, "Can't use method return value in write context");
+ }
+ if ((type & ZEND_PARSED_FUNCTION_CALL) &&
+ !(type & (ZEND_PARSED_METHOD_CALL|ZEND_PARSED_MEMBER))) {
+ zend_error(E_ERROR, "Can't use function return value in write context");
+ }
+}
zend_bool zend_variable_buffer_empty(TSRMLS_D)
{
View
@@ -259,6 +259,8 @@ void zend_do_post_incdec(znode *result, znode *op1, int op TSRMLS_DC);
void zend_do_begin_variable_parse(TSRMLS_D);
void zend_do_end_variable_parse(int type, int arg_offset TSRMLS_DC);
+void zend_check_writable_variable(znode *variable);
+
void zend_do_free(znode *op1 TSRMLS_DC);
void zend_do_init_string(znode *result TSRMLS_DC);
@@ -613,12 +613,13 @@ r_cvar:
w_cvar:
- cvar { zend_do_end_variable_parse(BP_VAR_W, 0 TSRMLS_CC); $$ = $1; }
+ cvar { zend_do_end_variable_parse(BP_VAR_W, 0 TSRMLS_CC); $$ = $1; }
+ { zend_check_writable_variable(&$$); }
;
-
rw_cvar:
- cvar { zend_do_end_variable_parse(BP_VAR_RW, 0 TSRMLS_CC); $$ = $1; }
+ cvar { zend_do_end_variable_parse(BP_VAR_RW, 0 TSRMLS_CC); $$ = $1; }
+ { zend_check_writable_variable(&$$); }
;
r_cvar_without_static_member:

0 comments on commit ac7ed46

Please sign in to comment.