Skip to content

Commit 328ecb4

Browse files
committed
Merge branch 'PHP-7.1'
2 parents fc92130 + 7cd2494 commit 328ecb4

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

Zend/tests/traits/bug69579.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #69579 (Internal trait double-free)
3+
--SKIPIF--
4+
<?php
5+
if (!PHP_DEBUG) die("skip only run in debug version");
6+
?>
7+
--FILE--
8+
<?php
9+
10+
class Bar{
11+
use _ZendTestTrait;
12+
}
13+
14+
$bar = new Bar();
15+
var_dump($bar->testMethod());
16+
// destruction causes a double-free and explodes
17+
18+
?>
19+
--EXPECT--
20+
bool(true)

Zend/tests/traits/get_declared_traits_001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ final class e { }
1212
var_dump(get_declared_traits());
1313

1414
?>
15-
--EXPECT--
16-
array(1) {
17-
[0]=>
15+
--EXPECTF--
16+
array(%d) {%A
17+
[%d]=>
1818
string(1) "c"
1919
}

Zend/tests/traits/get_declared_traits_002.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace test {
1313
}
1414

1515
?>
16-
--EXPECT--
17-
array(1) {
18-
[0]=>
16+
--EXPECTF--
17+
array(%d) {%A
18+
[%d]=>
1919
string(6) "test\c"
2020
}

Zend/tests/traits/get_declared_traits_003.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ var_dump(get_declared_traits());
1313

1414
?>
1515
--EXPECTF--
16-
%astring(1) "a"
16+
array(%d) {%A
17+
[%d]=>
18+
string(1) "a"
1719
[%d]=>
1820
string(1) "d"
1921
[%d]=>
2022
string(1) "e"
2123
}
22-
array(1) {
23-
[0]=>
24+
array(%d) {%A
25+
[%d]=>
2426
string(1) "c"
2527
}

Zend/zend_builtin_functions.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#if ZEND_DEBUG
3535
static zend_class_entry *zend_test_interface;
3636
static zend_class_entry *zend_test_class;
37+
static zend_class_entry *zend_test_trait;
3738
static zend_object_handlers zend_test_class_handlers;
3839
#endif
3940

@@ -306,6 +307,16 @@ static int zend_test_class_call_method(zend_string *method, zend_object *object,
306307
return 0;
307308
}
308309
/* }}} */
310+
311+
static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
312+
RETURN_TRUE;
313+
}
314+
/* }}} */
315+
316+
static zend_function_entry zend_test_trait_methods[] = {
317+
ZEND_ME(_ZendTestTrait, testMethod, arginfo_zend__void, ZEND_ACC_PUBLIC)
318+
ZEND_FE_END
319+
};
309320
#endif
310321

311322
static const zend_function_entry builtin_functions[] = { /* {{{ */
@@ -403,6 +414,11 @@ ZEND_MINIT_FUNCTION(core) { /* {{{ */
403414
memcpy(&zend_test_class_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
404415
zend_test_class_handlers.get_method = zend_test_class_method_get;
405416
zend_test_class_handlers.call_method = zend_test_class_call_method;
417+
418+
INIT_CLASS_ENTRY(class_entry, "_ZendTestTrait", zend_test_trait_methods);
419+
zend_test_trait = zend_register_internal_class(&class_entry);
420+
zend_test_trait->ce_flags |= ZEND_ACC_TRAIT;
421+
zend_declare_property_null(zend_test_trait, "testProp", sizeof("testProp")-1, ZEND_ACC_PUBLIC);
406422
#endif
407423

408424
return SUCCESS;

Zend/zend_inheritance.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
12271227
function_add_ref(fn);
12281228
new_fn = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
12291229
memcpy(new_fn, fn, sizeof(zend_op_array));
1230+
new_fn->common.fn_flags |= ZEND_ACC_ARENA_ALLOCATED;
12301231
fn = zend_hash_update_ptr(&ce->function_table, key, new_fn);
12311232
zend_add_magic_methods(ce, key, fn);
12321233
}

0 commit comments

Comments
 (0)