com php-src: Fix #78761: Zend memory heap corruption with preload and casting: NEWS ext/ffi/ffi.c ext/ffi/tests/bug78761.phpt
ext/ffi/tests/bug78761_preload.h ext/ffi/tests/ bug78761_preload.php

From: Date: Wed, 30 Oct 2019 18:49:39 +0000
Subject: com php-src: Fix #78761: Zend memory heap corruption with preload and casting: NEWS ext/ffi/ffi.c ext/ffi/tests/bug78761.phpt
ext/ffi/tests/bug78761_preload.h ext/ffi/tests/ bug78761_preload.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109143@lists.php.net to get a copy of this message
Commit: 0055f1e3dc7ec27778d6d3bd22404319b3ceeeca Author: Christoph M. Becker <cmbecker69@gmx.de> Wed, 30 Oct 2019 18:05:10 +0100 Parents: 1e2d3d58a8b392385d926bdca11ba0a0bc2547b4 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0055f1e3dc7ec27778d6d3bd22404319b3ceeeca Log: Fix #78761: Zend memory heap corruption with preload and casting We have to reset FFI_G(persistent) back to zero when preloading has finished. Bugs: https://bugs.php.net/78761 Changed paths: M NEWS M ext/ffi/ffi.c A ext/ffi/tests/bug78761.phpt A ext/ffi/tests/bug78761_preload.h A ext/ffi/tests/bug78761_preload.php Diff: diff --git a/NEWS b/NEWS index 17dd4756c12..b63d82438c8 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ PHP NEWS . Fixed bug #78716 (Function name mangling is wrong for some parameter types). (cmb) . Fixed bug #78762 (Failing FFI::cast() may leak memory). (cmb) + . Fixed bug #78761 (Zend memory heap corruption with preload and casting). + (cmb) . Implement FR #78270 (Support __vectorcall convention with FFI). (cmb) - FPM: diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 08117cba836..369e6531ace 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -3340,6 +3340,7 @@ static zend_ffi *zend_ffi_load(const char *filename, zend_bool preload) /* {{{ * efree(code); FFI_G(symbols) = NULL; FFI_G(tags) = NULL; + FFI_G(persistent) = 0; return ffi; diff --git a/ext/ffi/tests/bug78761.phpt b/ext/ffi/tests/bug78761.phpt new file mode 100644 index 00000000000..1db977a841c --- /dev/null +++ b/ext/ffi/tests/bug78761.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #78761 (Zend memory heap corruption with preload and casting) +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--INI-- +opcache.enable_cli=1 +opcache.preload={PWD}/bug78761_preload.php +--FILE-- +<?php +try { + FFI::cast('char[10]', FFI::new('char[1]')); +} catch (FFI\Exception $ex) { + echo $ex->getMessage(), PHP_EOL; +} +?> +--EXPECT-- +attempt to cast to larger type diff --git a/ext/ffi/tests/bug78761_preload.h b/ext/ffi/tests/bug78761_preload.h new file mode 100644 index 00000000000...e69de29bb2d diff --git a/ext/ffi/tests/bug78761_preload.php b/ext/ffi/tests/bug78761_preload.php new file mode 100644 index 00000000000..207b7c3ec84 --- /dev/null +++ b/ext/ffi/tests/bug78761_preload.php @@ -0,0 +1,3 @@ +<?php + +FFI::load(__DIR__ . '/bug78761_preload.h');

« previous php.cvs (#109143) next »