Skip to content

Commit b504468

Browse files
committed
Merge remote-tracking branch 'origin/str_size_and_int64_56_backport' 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
2 parents 0eb34f2 + 5e750fe commit b504468

File tree

140 files changed

+5465
-2674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+5465
-2674
lines changed

Zend/tests/bug66015.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #66015 (wrong array indexing in class's static property)
3+
--FILE--
4+
<?php
5+
class Test
6+
{
7+
const FIRST = 1;
8+
const SECOND = 2;
9+
const THIRD = 3;
10+
11+
protected static $array = [
12+
self::FIRST => 'first',
13+
'second',
14+
'third'
15+
];
16+
17+
public function __construct()
18+
{
19+
var_export(self::$array);
20+
}
21+
}
22+
23+
$test = new Test();
24+
?>
25+
--EXPECTF--
26+
array (
27+
1 => 'first',
28+
2 => 'second',
29+
3 => 'third',
30+
)

Zend/tests/bug66660.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #66660 (Composer.phar install/update fails)
3+
--STDIN--
4+
<?php __CLASS__ ?>
5+
--FILE--
6+
<?php
7+
file_put_contents(__DIR__."/bug66660.tmp.php", "<?php __CLASS__ ?>");
8+
echo php_strip_whitespace(__DIR__."/bug66660.tmp.php");
9+
?>
10+
--CLEAN--
11+
<?php unlink(__DIR__."/bug66660.tmp.php"); ?>
12+
--EXPECT--
13+
<?php __CLASS__ ?>

Zend/tests/errmsg_040.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class test {
77
const TEST = array(1,2,3);
88
}
99

10+
var_dump(test::TEST);
11+
1012
echo "Done\n";
1113
?>
1214
--EXPECTF--
13-
Fatal error: Arrays are not allowed in class constants in %s on line %d
15+
Fatal error: Arrays are not allowed in constants at run-time in %s on line %d

Zend/tests/ns_059.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
--FILE--
44
<?php
55
const C = array();
6+
7+
var_dump(C);
8+
?>
69
--EXPECTF--
7-
Fatal error: Arrays are not allowed as constants in %sns_059.php on line 2
10+
Fatal error: Arrays are not allowed in constants at run-time in %sns_059.php on line 4
811

Zend/zend.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,11 @@ typedef int (*zend_write_func_t)(const char *str, zend_size_t str_length);
589589
#define IS_STRING 6
590590
#define IS_RESOURCE 7
591591
#define IS_CONSTANT 8
592-
#define IS_CONSTANT_ARRAY 9
593-
#define IS_CONSTANT_AST 10
594-
#define IS_CALLABLE 11
592+
#define IS_CONSTANT_AST 9
593+
#define IS_CALLABLE 10
595594

596-
/* Ugly hack to support constants as static array indices */
597595
#define IS_CONSTANT_TYPE_MASK 0x00f
598596
#define IS_CONSTANT_UNQUALIFIED 0x010
599-
#define IS_CONSTANT_INDEX 0x080
600597
#define IS_LEXICAL_VAR 0x020
601598
#define IS_LEXICAL_REF 0x040
602599
#define IS_CONSTANT_IN_NAMESPACE 0x100

Zend/zend_API.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ static int zval_update_class_constant(zval **pp, int is_static, int offset TSRML
10801080
int ret;
10811081
zend_class_entry *old_scope = *scope;
10821082
*scope = prop_info->ce;
1083-
ret = zval_update_constant(pp, (void*)1 TSRMLS_CC);
1083+
ret = zval_update_constant(pp, 1 TSRMLS_CC);
10841084
*scope = old_scope;
10851085
return ret;
10861086
}
@@ -1089,7 +1089,7 @@ static int zval_update_class_constant(zval **pp, int is_static, int offset TSRML
10891089
} while (ce);
10901090

10911091
}
1092-
return zval_update_constant(pp, (void*)1 TSRMLS_CC);
1092+
return zval_update_constant(pp, 1 TSRMLS_CC);
10931093
}
10941094
return 0;
10951095
}
@@ -1103,7 +1103,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
11031103
int i;
11041104

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

11081108
for (i = 0; i < class_type->default_properties_count; i++) {
11091109
if (class_type->default_properties_table[i]) {
@@ -3471,7 +3471,6 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, ze
34713471
if (ce->type & ZEND_INTERNAL_CLASS) {
34723472
switch(Z_TYPE_P(property)) {
34733473
case IS_ARRAY:
3474-
case IS_CONSTANT_ARRAY:
34753474
case IS_OBJECT:
34763475
case IS_RESOURCE:
34773476
zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");

Zend/zend_ast.c

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ ZEND_API zend_ast* zend_ast_create_ternary(uint kind, zend_ast *op0, zend_ast *o
6363
return ast;
6464
}
6565

66+
ZEND_API zend_ast* zend_ast_create_dynamic(uint kind)
67+
{
68+
zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * 3); /* use 4 children as deafult */
69+
ast->kind = kind;
70+
ast->children = 0;
71+
return ast;
72+
}
73+
74+
ZEND_API void zend_ast_dynamic_add(zend_ast **ast, zend_ast *op)
75+
{
76+
if ((*ast)->children >= 4 && (*ast)->children == ((*ast)->children & -(*ast)->children)) {
77+
*ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children * 2 + 1));
78+
}
79+
(&(*ast)->u.child)[(*ast)->children++] = op;
80+
}
81+
82+
ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast)
83+
{
84+
*ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children - 1));
85+
}
86+
6687
ZEND_API int zend_ast_is_ct_constant(zend_ast *ast)
6788
{
6889
int i;
@@ -233,7 +254,7 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
233254
*result = *ast->u.val;
234255
zval_copy_ctor(result);
235256
if (IS_CONSTANT_TYPE(Z_TYPE_P(result))) {
236-
zval_update_constant_ex(&result, (void *) 1, scope TSRMLS_CC);
257+
zval_update_constant_ex(&result, 1, scope TSRMLS_CC);
237258
}
238259
break;
239260
case ZEND_BOOL_AND:
@@ -284,6 +305,35 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
284305
sub_function(result, &op1, &op2 TSRMLS_CC);
285306
zval_dtor(&op2);
286307
break;
308+
case ZEND_INIT_ARRAY:
309+
INIT_PZVAL(result);
310+
array_init(result);
311+
{
312+
int i;
313+
zend_bool has_key;
314+
for (i = 0; i < ast->children; i+=2) {
315+
zval *expr;
316+
MAKE_STD_ZVAL(expr);
317+
if ((has_key = !!(&ast->u.child)[i])) {
318+
zend_ast_evaluate(&op1, (&ast->u.child)[i], scope TSRMLS_CC);
319+
}
320+
zend_ast_evaluate(expr, (&ast->u.child)[i+1], scope TSRMLS_CC);
321+
zend_do_add_static_array_element(result, has_key?&op1:NULL, expr);
322+
}
323+
}
324+
break;
325+
case ZEND_FETCH_DIM_R:
326+
zend_ast_evaluate(&op1, (&ast->u.child)[0], scope TSRMLS_CC);
327+
zend_ast_evaluate(&op2, (&ast->u.child)[1], scope TSRMLS_CC);
328+
{
329+
zval *tmp;
330+
zend_fetch_dimension_by_zval(&tmp, &op1, &op2 TSRMLS_CC);
331+
*result = *tmp;
332+
efree(tmp);
333+
}
334+
zval_dtor(&op1);
335+
zval_dtor(&op2);
336+
break;
287337
default:
288338
zend_error(E_ERROR, "Unsupported constant expression");
289339
}
@@ -297,26 +347,17 @@ ZEND_API zend_ast *zend_ast_copy(zend_ast *ast)
297347
zend_ast *copy = zend_ast_create_constant(ast->u.val);
298348
zval_copy_ctor(copy->u.val);
299349
return copy;
300-
} else {
301-
switch (ast->children) {
302-
case 1:
303-
return zend_ast_create_unary(
304-
ast->kind,
305-
zend_ast_copy((&ast->u.child)[0]));
306-
case 2:
307-
return zend_ast_create_binary(
308-
ast->kind,
309-
zend_ast_copy((&ast->u.child)[0]),
310-
zend_ast_copy((&ast->u.child)[1]));
311-
case 3:
312-
return zend_ast_create_ternary(
313-
ast->kind,
314-
zend_ast_copy((&ast->u.child)[0]),
315-
zend_ast_copy((&ast->u.child)[1]),
316-
zend_ast_copy((&ast->u.child)[2]));
350+
} else if (ast->children) {
351+
zend_ast *new = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
352+
int i;
353+
new->kind = ast->kind;
354+
new->children = ast->children;
355+
for (i = 0; i < ast->children; i++) {
356+
(&new->u.child)[i] = zend_ast_copy((&ast->u.child)[i]);
317357
}
358+
return new;
318359
}
319-
return NULL;
360+
return zend_ast_create_dynamic(ast->kind);
320361
}
321362

322363
ZEND_API void zend_ast_destroy(zend_ast *ast)

Zend/zend_ast.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ ZEND_API zend_ast *zend_ast_create_constant(zval *zv);
5050
ZEND_API zend_ast *zend_ast_create_unary(uint kind, zend_ast *op0);
5151
ZEND_API zend_ast *zend_ast_create_binary(uint kind, zend_ast *op0, zend_ast *op1);
5252
ZEND_API zend_ast *zend_ast_create_ternary(uint kind, zend_ast *op0, zend_ast *op1, zend_ast *op2);
53+
ZEND_API zend_ast* zend_ast_create_dynamic(uint kind);
54+
ZEND_API void zend_ast_dynamic_add(zend_ast **ast, zend_ast *op);
55+
ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast);
5356

5457
ZEND_API int zend_ast_is_ct_constant(zend_ast *ast);
5558

Zend/zend_compile.c

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ void zend_do_receive_param(zend_uchar op, znode *varname, const znode *initializ
19331933
if (op == ZEND_RECV_INIT) {
19341934
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) {
19351935
cur_arg_info->allow_null = 1;
1936-
} else if (Z_TYPE(initialization->u.constant) != IS_ARRAY && Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) {
1936+
} else if (Z_TYPE(initialization->u.constant) != IS_ARRAY) {
19371937
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters with array type hint can only be an array or NULL");
19381938
}
19391939
}
@@ -3461,7 +3461,7 @@ static char * zend_get_function_declaration(zend_function *fptr TSRMLS_DC) /* {{
34613461
*zv = *precv->op2.zv;
34623462
zval_copy_ctor(zv);
34633463
INIT_PZVAL(zv);
3464-
zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC);
3464+
zval_update_constant_ex(&zv, 1, fptr->common.scope TSRMLS_CC);
34653465
if (Z_TYPE_P(zv) == IS_BOOL) {
34663466
if (Z_IVAL_P(zv)) {
34673467
memcpy(offset, "true", 4);
@@ -5442,10 +5442,6 @@ void zend_do_declare_class_constant(znode *var_name, const znode *value TSRMLS_D
54425442
const char *cname = NULL;
54435443
zend_uint_t hash;
54445444

5445-
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
5446-
zend_error_noreturn(E_COMPILE_ERROR, "Arrays are not allowed in class constants");
5447-
return;
5448-
}
54495445
if ((CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
54505446
zend_error_noreturn(E_COMPILE_ERROR, "Traits cannot have constants");
54515447
return;
@@ -5887,57 +5883,30 @@ void zend_do_add_array_element(znode *result, const znode *expr, const znode *of
58875883
}
58885884
/* }}} */
58895885

5890-
void zend_do_add_static_array_element(znode *result, znode *offset, const znode *expr) /* {{{ */
5886+
void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr) /* {{{ */
58915887
{
5892-
zval *element;
5893-
5894-
ALLOC_ZVAL(element);
5895-
*element = expr->u.constant;
58965888
if (offset) {
5897-
switch (Z_TYPE(offset->u.constant) & IS_CONSTANT_TYPE_MASK) {
5898-
case IS_CONSTANT:
5899-
/* Ugly hack to denote that this value has a constant index */
5900-
Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
5901-
Z_STRVAL(offset->u.constant) = erealloc(Z_STRVAL(offset->u.constant), Z_STRSIZE(offset->u.constant)+3);
5902-
Z_STRVAL(offset->u.constant)[Z_STRSIZE(offset->u.constant)+1] = Z_TYPE(offset->u.constant);
5903-
Z_STRVAL(offset->u.constant)[Z_STRSIZE(offset->u.constant)+2] = 0;
5904-
zend_symtable_update(Z_ARRVAL(result->u.constant), Z_STRVAL(offset->u.constant), Z_STRSIZE(offset->u.constant)+3, &element, sizeof(zval *), NULL);
5905-
zval_dtor(&offset->u.constant);
5906-
break;
5907-
case IS_CONSTANT_AST: {
5908-
/* Another ugly hack to store the data about the AST in the array */
5909-
char* key;
5910-
int len = sizeof(zend_ast *);
5911-
Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
5912-
5913-
key = emalloc(len + 2);
5914-
*(zend_ast **)key = Z_AST(offset->u.constant);
5915-
key[len] = Z_TYPE(offset->u.constant);
5916-
key[len + 1] = 0;
5917-
zend_symtable_update(Z_ARRVAL(result->u.constant), key, len + 2, &element, sizeof(zval *), NULL);
5918-
efree(key);
5919-
break;
5920-
}
5889+
switch (Z_TYPE_P(offset)) {
59215890
case IS_STRING:
5922-
zend_symtable_update(Z_ARRVAL(result->u.constant), Z_STRVAL(offset->u.constant), Z_STRSIZE(offset->u.constant)+1, &element, sizeof(zval *), NULL);
5923-
zval_dtor(&offset->u.constant);
5891+
zend_symtable_update(Z_ARRVAL_P(result), Z_STRVAL_P(offset), Z_STRSIZE_P(offset)+1, &expr, sizeof(zval *), NULL);
5892+
zval_dtor(offset);
59245893
break;
59255894
case IS_NULL:
5926-
zend_symtable_update(Z_ARRVAL(result->u.constant), "", 1, &element, sizeof(zval *), NULL);
5895+
zend_symtable_update(Z_ARRVAL_P(result), "", 1, &expr, sizeof(zval *), NULL);
59275896
break;
59285897
case IS_INT:
59295898
case IS_BOOL:
5930-
zend_hash_index_update(Z_ARRVAL(result->u.constant), Z_IVAL(offset->u.constant), &element, sizeof(zval *), NULL);
5899+
zend_hash_index_update(Z_ARRVAL_P(result), Z_IVAL_P(offset), &expr, sizeof(zval *), NULL);
59315900
break;
59325901
case IS_DOUBLE:
5933-
zend_hash_index_update(Z_ARRVAL(result->u.constant), zend_dval_to_ival(Z_DVAL(offset->u.constant)), &element, sizeof(zval *), NULL);
5902+
zend_hash_index_update(Z_ARRVAL_P(result), zend_dval_to_ival(Z_DVAL_P(offset)), &expr, sizeof(zval *), NULL);
59345903
break;
5935-
case IS_CONSTANT_ARRAY:
5904+
case IS_ARRAY:
59365905
zend_error(E_ERROR, "Illegal offset type");
59375906
break;
59385907
}
59395908
} else {
5940-
zend_hash_next_index_insert(Z_ARRVAL(result->u.constant), &element, sizeof(zval *), NULL);
5909+
zend_hash_next_index_insert(Z_ARRVAL_P(result), &expr, sizeof(zval *), NULL);
59415910
}
59425911
}
59435912
/* }}} */
@@ -7318,10 +7287,6 @@ void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
73187287
zend_op *opline;
73197288
zval **ns_name;
73207289

7321-
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
7322-
zend_error_noreturn(E_COMPILE_ERROR, "Arrays are not allowed as constants");
7323-
}
7324-
73257290
if (zend_get_ct_const(&name->u.constant, 0 TSRMLS_CC)) {
73267291
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant));
73277292
}

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ void zend_do_shell_exec(znode *result, const znode *cmd TSRMLS_DC);
602602

603603
void zend_do_init_array(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC);
604604
void zend_do_add_array_element(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC);
605-
void zend_do_add_static_array_element(znode *result, znode *offset, const znode *expr);
605+
void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr);
606606
void zend_do_list_init(TSRMLS_D);
607607
void zend_do_list_end(znode *result, znode *expr TSRMLS_DC);
608608
void zend_do_add_list_element(const znode *element TSRMLS_DC);

Zend/zend_constants.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ ZEND_API int zend_get_constant_ex(const char *name, zend_size_t name_len, zval *
408408
efree(lcname);
409409
if(found_const) {
410410
*result = c->value;
411-
zval_update_constant_ex(&result, (void*)1, NULL TSRMLS_CC);
411+
zval_update_constant_ex(&result, 1, NULL TSRMLS_CC);
412412
zval_copy_ctor(result);
413413
Z_SET_REFCOUNT_P(result, 1);
414414
Z_UNSET_ISREF_P(result);
@@ -423,7 +423,7 @@ ZEND_API int zend_get_constant_ex(const char *name, zend_size_t name_len, zval *
423423
retval = 0;
424424
finish:
425425
if (retval) {
426-
zval_update_constant_ex(ret_constant, (void*)1, ce TSRMLS_CC);
426+
zval_update_constant_ex(ret_constant, 1, ce TSRMLS_CC);
427427
*result = **ret_constant;
428428
zval_copy_ctor(result);
429429
INIT_PZVAL(result);

Zend/zend_execute.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,15 @@ static void zend_fetch_dimension_address_read(temp_variable *result, zval *conta
13521352
}
13531353
}
13541354

1355+
ZEND_API void zend_fetch_dimension_by_zval(zval **result, zval *container, zval *dim TSRMLS_DC) {
1356+
temp_variable tmp;
1357+
zend_fetch_dimension_address_read(&tmp, container, dim, IS_TMP_VAR, BP_VAR_R TSRMLS_CC);
1358+
*result = tmp.var.ptr;
1359+
}
1360+
13551361
static void zend_fetch_property_address(temp_variable *result, zval **container_ptr, zval *prop_ptr, const zend_literal *key, int type TSRMLS_DC)
13561362
{
1357-
zval *container = *container_ptr;;
1363+
zval *container = *container_ptr;
13581364

13591365
if (Z_TYPE_P(container) != IS_OBJECT) {
13601366
if (container == &EG(error_zval)) {

0 commit comments

Comments
 (0)