php-src/ext/ffi/tests/bug79571.phpt
Christoph M. Becker d5300873c5 Fix #79571: FFI: var_dumping unions may segfault
We must not attempt to access arbitrary union members when retrieving
debug info, because that may not be valid.  Therefore we do no longer
dereference pointer types inside of unions, but report their address as
string in `%p` format instead.
2020-05-11 16:24:46 +02:00

29 lines
482 B
PHP

--TEST--
Bug #79571 (FFI: var_dumping unions may segfault)
--SKIPIF--
<?php
if (!extension_loaded('ffi')) die('skip ffi extension not available');
?>
--FILE--
<?php
$ffi = FFI::cdef(<<<EOF
typedef union {
int num;
char *str;
} my_union;
EOF);
$union = $ffi->new('my_union');
$union->num = 42;
var_dump($union);
var_dump($union->num);
?>
--EXPECTF--
object(FFI\CData:union <anonymous>)#%d (2) {
["num"]=>
int(42)
["str"]=>
string(4) "0x2a"
}
int(42)