diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-04-27 13:08:22 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-04-27 13:08:22 +0300 |
commit | 2a1b0b112129c947e24c0fd9243df88816adac42 (patch) | |
tree | d3809278c8a4738334f89f585b7a2bc6561df2a9 /Zend/zend_compile.c | |
parent | 94245bc14c5ed1a1afa2c5a1bc081e95bcd3628b (diff) | |
download | php-git-2a1b0b112129c947e24c0fd9243df88816adac42.tar.gz |
Use "safe" anonymous class names. Don't show the mangled names through var_dump().
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r-- | Zend/zend_compile.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index eb7f830cbc..c4170673cb 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4898,11 +4898,24 @@ void zend_compile_implements(znode *class_node, zend_ast *ast) /* {{{ */ } /* }}} */ -static zend_string *zend_generate_anon_class_name(void) /* {{{ */ +static zend_string *zend_generate_anon_class_name(unsigned char *lex_pos) /* {{{ */ { - // TODO The opline pointer may be reused, this is not safe! - uint32_t next = get_next_op_number(CG(active_op_array)); - return zend_strpprintf(0, "class@%p", &CG(active_op_array)->opcodes[next-1]); + zend_string *result; + char char_pos_buf[32]; + size_t filename_len, char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos); + + const char *filename; + if (CG(active_op_array)->filename) { + filename = CG(active_op_array)->filename->val; + filename_len = CG(active_op_array)->filename->len; + } else { + filename = "-"; + filename_len = sizeof("-") - 1; + } + /* NULL, name length, filename length, last accepting char position length */ + result = zend_string_alloc(sizeof("class@anonymous") + filename_len + char_pos_len, 0); + sprintf(result->val, "class@anonymous%c%s%s", '\0', filename, char_pos_buf); + return zend_new_interned_string(result); } /* }}} */ @@ -4922,7 +4935,7 @@ zend_class_entry *zend_compile_class_decl(zend_ast *ast) /* {{{ */ znode original_implementing_class = FC(implementing_class); if (decl->flags & ZEND_ACC_ANON_CLASS) { - decl->name = name = zend_generate_anon_class_name(); + decl->name = name = zend_generate_anon_class_name(decl->lex_pos); /* Serialization is not supported for anonymous classes */ ce->serialize = zend_class_serialize_deny; |