Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/str_size_and_int64_56_backport' …
Browse files Browse the repository at this point in the history
…into str_size_and_int64

* origin/str_size_and_int64_56_backport: (58 commits)
  fix datatypes
  fix zpp
  fixed prototype
  fix test - doesn't seem to produce warning
  Fix test - on CI somebody could create a process in the meantime
  fix windows build
  Fix #66942: openssl_seal() memory leak
  ws fix
  Fix #66942: openssl_seal() memory leak
  ws fix
  Fix null byte in LDAP bindings
  Fix bug #66171: better handling of symlinks
  Fix null byte in LDAP bindings
  Fix bug #66171: better handling of symlinks
  Fix null byte in LDAP bindings
  Fix bug #66171: better handling of symlinks
  fix crash in MINFO when no mysqlnd plugins are loaded
  Add test
  backported some ext/intl tests from 5.6 into 5.4
  test fixes for ICU 53.1
  ...

Conflicts:
	ext/mysqlnd/mysqlnd_result.c
  • Loading branch information
weltling committed Apr 15, 2014
2 parents 0eb34f2 + 5e750fe commit b504468
Show file tree
Hide file tree
Showing 140 changed files with 5,465 additions and 2,674 deletions.
30 changes: 30 additions & 0 deletions Zend/tests/bug66015.phpt
@@ -0,0 +1,30 @@
--TEST--
Bug #66015 (wrong array indexing in class's static property)
--FILE--
<?php
class Test
{
const FIRST = 1;
const SECOND = 2;
const THIRD = 3;

protected static $array = [
self::FIRST => 'first',
'second',
'third'
];

public function __construct()
{
var_export(self::$array);
}
}

$test = new Test();
?>
--EXPECTF--
array (
1 => 'first',
2 => 'second',
3 => 'third',
)
13 changes: 13 additions & 0 deletions Zend/tests/bug66660.phpt
@@ -0,0 +1,13 @@
--TEST--
Bug #66660 (Composer.phar install/update fails)
--STDIN--
<?php __CLASS__ ?>
--FILE--
<?php
file_put_contents(__DIR__."/bug66660.tmp.php", "<?php __CLASS__ ?>");
echo php_strip_whitespace(__DIR__."/bug66660.tmp.php");
?>
--CLEAN--
<?php unlink(__DIR__."/bug66660.tmp.php"); ?>
--EXPECT--
<?php __CLASS__ ?>
4 changes: 3 additions & 1 deletion Zend/tests/errmsg_040.phpt
Expand Up @@ -7,7 +7,9 @@ class test {
const TEST = array(1,2,3);
}

var_dump(test::TEST);

echo "Done\n";
?>
--EXPECTF--
Fatal error: Arrays are not allowed in class constants in %s on line %d
Fatal error: Arrays are not allowed in constants at run-time in %s on line %d
5 changes: 4 additions & 1 deletion Zend/tests/ns_059.phpt
Expand Up @@ -3,6 +3,9 @@
--FILE--
<?php
const C = array();

var_dump(C);
?>
--EXPECTF--
Fatal error: Arrays are not allowed as constants in %sns_059.php on line 2
Fatal error: Arrays are not allowed in constants at run-time in %sns_059.php on line 4

7 changes: 2 additions & 5 deletions Zend/zend.h
Expand Up @@ -589,14 +589,11 @@ typedef int (*zend_write_func_t)(const char *str, zend_size_t str_length);
#define IS_STRING 6
#define IS_RESOURCE 7
#define IS_CONSTANT 8
#define IS_CONSTANT_ARRAY 9
#define IS_CONSTANT_AST 10
#define IS_CALLABLE 11
#define IS_CONSTANT_AST 9
#define IS_CALLABLE 10

/* Ugly hack to support constants as static array indices */
#define IS_CONSTANT_TYPE_MASK 0x00f
#define IS_CONSTANT_UNQUALIFIED 0x010
#define IS_CONSTANT_INDEX 0x080
#define IS_LEXICAL_VAR 0x020
#define IS_LEXICAL_REF 0x040
#define IS_CONSTANT_IN_NAMESPACE 0x100
Expand Down
7 changes: 3 additions & 4 deletions Zend/zend_API.c
Expand Up @@ -1080,7 +1080,7 @@ static int zval_update_class_constant(zval **pp, int is_static, int offset TSRML
int ret;
zend_class_entry *old_scope = *scope;
*scope = prop_info->ce;
ret = zval_update_constant(pp, (void*)1 TSRMLS_CC);
ret = zval_update_constant(pp, 1 TSRMLS_CC);
*scope = old_scope;
return ret;
}
Expand All @@ -1089,7 +1089,7 @@ static int zval_update_class_constant(zval **pp, int is_static, int offset TSRML
} while (ce);

}
return zval_update_constant(pp, (void*)1 TSRMLS_CC);
return zval_update_constant(pp, 1 TSRMLS_CC);
}
return 0;
}
Expand All @@ -1103,7 +1103,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
int i;

*scope = class_type;
zend_hash_apply_with_argument(&class_type->constants_table, (apply_func_arg_t) zval_update_constant, (void*)1 TSRMLS_CC);
zend_hash_apply_with_argument(&class_type->constants_table, (apply_func_arg_t) zval_update_constant, (void *)1 TSRMLS_CC);

for (i = 0; i < class_type->default_properties_count; i++) {
if (class_type->default_properties_table[i]) {
Expand Down Expand Up @@ -3471,7 +3471,6 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, ze
if (ce->type & ZEND_INTERNAL_CLASS) {
switch(Z_TYPE_P(property)) {
case IS_ARRAY:
case IS_CONSTANT_ARRAY:
case IS_OBJECT:
case IS_RESOURCE:
zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
Expand Down
79 changes: 60 additions & 19 deletions Zend/zend_ast.c
Expand Up @@ -63,6 +63,27 @@ ZEND_API zend_ast* zend_ast_create_ternary(uint kind, zend_ast *op0, zend_ast *o
return ast;
}

ZEND_API zend_ast* zend_ast_create_dynamic(uint kind)
{
zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * 3); /* use 4 children as deafult */
ast->kind = kind;
ast->children = 0;
return ast;
}

ZEND_API void zend_ast_dynamic_add(zend_ast **ast, zend_ast *op)
{
if ((*ast)->children >= 4 && (*ast)->children == ((*ast)->children & -(*ast)->children)) {
*ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children * 2 + 1));
}
(&(*ast)->u.child)[(*ast)->children++] = op;
}

ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast)
{
*ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children - 1));
}

ZEND_API int zend_ast_is_ct_constant(zend_ast *ast)
{
int i;
Expand Down Expand Up @@ -233,7 +254,7 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
*result = *ast->u.val;
zval_copy_ctor(result);
if (IS_CONSTANT_TYPE(Z_TYPE_P(result))) {
zval_update_constant_ex(&result, (void *) 1, scope TSRMLS_CC);
zval_update_constant_ex(&result, 1, scope TSRMLS_CC);
}
break;
case ZEND_BOOL_AND:
Expand Down Expand Up @@ -284,6 +305,35 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
sub_function(result, &op1, &op2 TSRMLS_CC);
zval_dtor(&op2);
break;
case ZEND_INIT_ARRAY:
INIT_PZVAL(result);
array_init(result);
{
int i;
zend_bool has_key;
for (i = 0; i < ast->children; i+=2) {
zval *expr;
MAKE_STD_ZVAL(expr);
if ((has_key = !!(&ast->u.child)[i])) {
zend_ast_evaluate(&op1, (&ast->u.child)[i], scope TSRMLS_CC);
}
zend_ast_evaluate(expr, (&ast->u.child)[i+1], scope TSRMLS_CC);
zend_do_add_static_array_element(result, has_key?&op1:NULL, expr);
}
}
break;
case ZEND_FETCH_DIM_R:
zend_ast_evaluate(&op1, (&ast->u.child)[0], scope TSRMLS_CC);
zend_ast_evaluate(&op2, (&ast->u.child)[1], scope TSRMLS_CC);
{
zval *tmp;
zend_fetch_dimension_by_zval(&tmp, &op1, &op2 TSRMLS_CC);
*result = *tmp;
efree(tmp);
}
zval_dtor(&op1);
zval_dtor(&op2);
break;
default:
zend_error(E_ERROR, "Unsupported constant expression");
}
Expand All @@ -297,26 +347,17 @@ ZEND_API zend_ast *zend_ast_copy(zend_ast *ast)
zend_ast *copy = zend_ast_create_constant(ast->u.val);
zval_copy_ctor(copy->u.val);
return copy;
} else {
switch (ast->children) {
case 1:
return zend_ast_create_unary(
ast->kind,
zend_ast_copy((&ast->u.child)[0]));
case 2:
return zend_ast_create_binary(
ast->kind,
zend_ast_copy((&ast->u.child)[0]),
zend_ast_copy((&ast->u.child)[1]));
case 3:
return zend_ast_create_ternary(
ast->kind,
zend_ast_copy((&ast->u.child)[0]),
zend_ast_copy((&ast->u.child)[1]),
zend_ast_copy((&ast->u.child)[2]));
} else if (ast->children) {
zend_ast *new = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
int i;
new->kind = ast->kind;
new->children = ast->children;
for (i = 0; i < ast->children; i++) {
(&new->u.child)[i] = zend_ast_copy((&ast->u.child)[i]);
}
return new;
}
return NULL;
return zend_ast_create_dynamic(ast->kind);
}

ZEND_API void zend_ast_destroy(zend_ast *ast)
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_ast.h
Expand Up @@ -50,6 +50,9 @@ ZEND_API zend_ast *zend_ast_create_constant(zval *zv);
ZEND_API zend_ast *zend_ast_create_unary(uint kind, zend_ast *op0);
ZEND_API zend_ast *zend_ast_create_binary(uint kind, zend_ast *op0, zend_ast *op1);
ZEND_API zend_ast *zend_ast_create_ternary(uint kind, zend_ast *op0, zend_ast *op1, zend_ast *op2);
ZEND_API zend_ast* zend_ast_create_dynamic(uint kind);
ZEND_API void zend_ast_dynamic_add(zend_ast **ast, zend_ast *op);
ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast);

ZEND_API int zend_ast_is_ct_constant(zend_ast *ast);

Expand Down
57 changes: 11 additions & 46 deletions Zend/zend_compile.c
Expand Up @@ -1933,7 +1933,7 @@ void zend_do_receive_param(zend_uchar op, znode *varname, const znode *initializ
if (op == ZEND_RECV_INIT) {
if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL")) || Z_TYPE(initialization->u.constant) == IS_CONSTANT_AST) {
cur_arg_info->allow_null = 1;
} else if (Z_TYPE(initialization->u.constant) != IS_ARRAY && Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) {
} else if (Z_TYPE(initialization->u.constant) != IS_ARRAY) {
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters with array type hint can only be an array or NULL");
}
}
Expand Down Expand Up @@ -3461,7 +3461,7 @@ static char * zend_get_function_declaration(zend_function *fptr TSRMLS_DC) /* {{
*zv = *precv->op2.zv;
zval_copy_ctor(zv);
INIT_PZVAL(zv);
zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC);
zval_update_constant_ex(&zv, 1, fptr->common.scope TSRMLS_CC);
if (Z_TYPE_P(zv) == IS_BOOL) {
if (Z_IVAL_P(zv)) {
memcpy(offset, "true", 4);
Expand Down Expand Up @@ -5442,10 +5442,6 @@ void zend_do_declare_class_constant(znode *var_name, const znode *value TSRMLS_D
const char *cname = NULL;
zend_uint_t hash;

if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
zend_error_noreturn(E_COMPILE_ERROR, "Arrays are not allowed in class constants");
return;
}
if ((CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
zend_error_noreturn(E_COMPILE_ERROR, "Traits cannot have constants");
return;
Expand Down Expand Up @@ -5887,57 +5883,30 @@ void zend_do_add_array_element(znode *result, const znode *expr, const znode *of
}
/* }}} */

void zend_do_add_static_array_element(znode *result, znode *offset, const znode *expr) /* {{{ */
void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr) /* {{{ */
{
zval *element;

ALLOC_ZVAL(element);
*element = expr->u.constant;
if (offset) {
switch (Z_TYPE(offset->u.constant) & IS_CONSTANT_TYPE_MASK) {
case IS_CONSTANT:
/* Ugly hack to denote that this value has a constant index */
Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
Z_STRVAL(offset->u.constant) = erealloc(Z_STRVAL(offset->u.constant), Z_STRSIZE(offset->u.constant)+3);
Z_STRVAL(offset->u.constant)[Z_STRSIZE(offset->u.constant)+1] = Z_TYPE(offset->u.constant);
Z_STRVAL(offset->u.constant)[Z_STRSIZE(offset->u.constant)+2] = 0;
zend_symtable_update(Z_ARRVAL(result->u.constant), Z_STRVAL(offset->u.constant), Z_STRSIZE(offset->u.constant)+3, &element, sizeof(zval *), NULL);
zval_dtor(&offset->u.constant);
break;
case IS_CONSTANT_AST: {
/* Another ugly hack to store the data about the AST in the array */
char* key;
int len = sizeof(zend_ast *);
Z_TYPE_P(element) |= IS_CONSTANT_INDEX;

key = emalloc(len + 2);
*(zend_ast **)key = Z_AST(offset->u.constant);
key[len] = Z_TYPE(offset->u.constant);
key[len + 1] = 0;
zend_symtable_update(Z_ARRVAL(result->u.constant), key, len + 2, &element, sizeof(zval *), NULL);
efree(key);
break;
}
switch (Z_TYPE_P(offset)) {
case IS_STRING:
zend_symtable_update(Z_ARRVAL(result->u.constant), Z_STRVAL(offset->u.constant), Z_STRSIZE(offset->u.constant)+1, &element, sizeof(zval *), NULL);
zval_dtor(&offset->u.constant);
zend_symtable_update(Z_ARRVAL_P(result), Z_STRVAL_P(offset), Z_STRSIZE_P(offset)+1, &expr, sizeof(zval *), NULL);
zval_dtor(offset);
break;
case IS_NULL:
zend_symtable_update(Z_ARRVAL(result->u.constant), "", 1, &element, sizeof(zval *), NULL);
zend_symtable_update(Z_ARRVAL_P(result), "", 1, &expr, sizeof(zval *), NULL);
break;
case IS_INT:
case IS_BOOL:
zend_hash_index_update(Z_ARRVAL(result->u.constant), Z_IVAL(offset->u.constant), &element, sizeof(zval *), NULL);
zend_hash_index_update(Z_ARRVAL_P(result), Z_IVAL_P(offset), &expr, sizeof(zval *), NULL);
break;
case IS_DOUBLE:
zend_hash_index_update(Z_ARRVAL(result->u.constant), zend_dval_to_ival(Z_DVAL(offset->u.constant)), &element, sizeof(zval *), NULL);
zend_hash_index_update(Z_ARRVAL_P(result), zend_dval_to_ival(Z_DVAL_P(offset)), &expr, sizeof(zval *), NULL);
break;
case IS_CONSTANT_ARRAY:
case IS_ARRAY:
zend_error(E_ERROR, "Illegal offset type");
break;
}
} else {
zend_hash_next_index_insert(Z_ARRVAL(result->u.constant), &element, sizeof(zval *), NULL);
zend_hash_next_index_insert(Z_ARRVAL_P(result), &expr, sizeof(zval *), NULL);
}
}
/* }}} */
Expand Down Expand Up @@ -7318,10 +7287,6 @@ void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
zend_op *opline;
zval **ns_name;

if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
zend_error_noreturn(E_COMPILE_ERROR, "Arrays are not allowed as constants");
}

if (zend_get_ct_const(&name->u.constant, 0 TSRMLS_CC)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant));
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.h
Expand Up @@ -602,7 +602,7 @@ void zend_do_shell_exec(znode *result, const znode *cmd TSRMLS_DC);

void zend_do_init_array(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC);
void zend_do_add_array_element(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC);
void zend_do_add_static_array_element(znode *result, znode *offset, const znode *expr);
void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr);
void zend_do_list_init(TSRMLS_D);
void zend_do_list_end(znode *result, znode *expr TSRMLS_DC);
void zend_do_add_list_element(const znode *element TSRMLS_DC);
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_constants.c
Expand Up @@ -408,7 +408,7 @@ ZEND_API int zend_get_constant_ex(const char *name, zend_size_t name_len, zval *
efree(lcname);
if(found_const) {
*result = c->value;
zval_update_constant_ex(&result, (void*)1, NULL TSRMLS_CC);
zval_update_constant_ex(&result, 1, NULL TSRMLS_CC);
zval_copy_ctor(result);
Z_SET_REFCOUNT_P(result, 1);
Z_UNSET_ISREF_P(result);
Expand All @@ -423,7 +423,7 @@ ZEND_API int zend_get_constant_ex(const char *name, zend_size_t name_len, zval *
retval = 0;
finish:
if (retval) {
zval_update_constant_ex(ret_constant, (void*)1, ce TSRMLS_CC);
zval_update_constant_ex(ret_constant, 1, ce TSRMLS_CC);
*result = **ret_constant;
zval_copy_ctor(result);
INIT_PZVAL(result);
Expand Down
8 changes: 7 additions & 1 deletion Zend/zend_execute.c
Expand Up @@ -1352,9 +1352,15 @@ static void zend_fetch_dimension_address_read(temp_variable *result, zval *conta
}
}

ZEND_API void zend_fetch_dimension_by_zval(zval **result, zval *container, zval *dim TSRMLS_DC) {
temp_variable tmp;
zend_fetch_dimension_address_read(&tmp, container, dim, IS_TMP_VAR, BP_VAR_R TSRMLS_CC);
*result = tmp.var.ptr;
}

static void zend_fetch_property_address(temp_variable *result, zval **container_ptr, zval *prop_ptr, const zend_literal *key, int type TSRMLS_DC)
{
zval *container = *container_ptr;;
zval *container = *container_ptr;

if (Z_TYPE_P(container) != IS_OBJECT) {
if (container == &EG(error_zval)) {
Expand Down

0 comments on commit b504468

Please sign in to comment.