mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-14215: Cannot use FFI::load on CRLF header file with apache2handler
Some modules may reset _fmode, which causes mangling of line endings. Always be explicit like we do in other places where the native open call is used. Closes GH-14218.
This commit is contained in:
parent
719fa46150
commit
ebd1a36670
7 changed files with 64 additions and 2 deletions
4
NEWS
4
NEWS
|
@ -23,6 +23,10 @@ PHP NEWS
|
|||
. Fix crash in ParentNode::append() when dealing with a fragment
|
||||
containing text nodes. (nielsdos)
|
||||
|
||||
- FFI:
|
||||
. Fixed bug GH-14215 (Cannot use FFI::load on CRLF header file with
|
||||
apache2handler). (nielsdos)
|
||||
|
||||
- FPM:
|
||||
. Fix bug GH-14175 (Show decimal number instead of scientific notation in
|
||||
systemd status). (Benjamin Cremer)
|
||||
|
|
|
@ -3255,7 +3255,11 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
|
|||
|
||||
code_size = buf.st_size;
|
||||
code = emalloc(code_size + 1);
|
||||
fd = open(filename, O_RDONLY, 0);
|
||||
int open_flags = O_RDONLY;
|
||||
#ifdef PHP_WIN32
|
||||
open_flags |= _O_BINARY;
|
||||
#endif
|
||||
fd = open(filename, open_flags, 0);
|
||||
if (fd < 0 || read(fd, code, code_size) != code_size) {
|
||||
if (preload) {
|
||||
zend_error(E_WARNING, "FFI: Failed pre-loading '%s', cannot read_file", filename);
|
||||
|
|
3
ext/ffi/tests/gh14215.h
Normal file
3
ext/ffi/tests/gh14215.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#define FFI_LIB "Kernel32.dll"
|
||||
typedef unsigned long DWORD;
|
||||
DWORD GetLastError(void);
|
23
ext/ffi/tests/gh14215.phpt
Normal file
23
ext/ffi/tests/gh14215.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
GH-14215 (Cannot use FFI::load on CRLF header file with apache2handler)
|
||||
--EXTENSIONS--
|
||||
ffi
|
||||
zend_test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if(PHP_OS_FAMILY !== "Windows") {
|
||||
die('skip only for Windows');
|
||||
}
|
||||
?>
|
||||
--INI--
|
||||
ffi.enable=1
|
||||
--FILE--
|
||||
<?php
|
||||
zend_test_set_fmode(false);
|
||||
$header_path = __DIR__.'\\gh14215.h';
|
||||
$ffi = FFI::load($header_path);
|
||||
var_dump($ffi->GetLastError());
|
||||
zend_test_set_fmode(true);
|
||||
?>
|
||||
--EXPECT--
|
||||
int(0)
|
|
@ -584,6 +584,18 @@ static ZEND_FUNCTION(zend_test_is_pcre_bundled)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
static ZEND_FUNCTION(zend_test_set_fmode)
|
||||
{
|
||||
bool binary;
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_BOOL(binary)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
_fmode = binary ? _O_BINARY : _O_TEXT;
|
||||
}
|
||||
#endif
|
||||
|
||||
static zend_object *zend_test_class_new(zend_class_entry *class_type)
|
||||
{
|
||||
zend_object *obj = zend_objects_new(class_type);
|
||||
|
|
|
@ -182,6 +182,10 @@ function zend_test_override_libxml_global_state(): void {}
|
|||
#endif
|
||||
|
||||
function zend_test_is_pcre_bundled(): bool {}
|
||||
|
||||
#if defined(PHP_WIN32)
|
||||
function zend_test_set_fmode(bool $binary): void {}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace ZendTestNS {
|
||||
|
|
14
ext/zend_test/test_arginfo.h
generated
14
ext/zend_test/test_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
|||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 420711ec6f040d38bde450a169bf1186f8531191 */
|
||||
* Stub hash: b0964f7eabf91dc0fbffdee87257ee4e58dab303 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
@ -112,6 +112,12 @@ ZEND_END_ARG_INFO()
|
|||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_is_pcre_bundled, 0, 0, _IS_BOOL, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#if defined(PHP_WIN32)
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_set_fmode, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, binary, _IS_BOOL, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
#endif
|
||||
|
||||
#define arginfo_ZendTestNS2_namespaced_func arginfo_zend_test_is_pcre_bundled
|
||||
|
||||
#define arginfo_ZendTestNS2_namespaced_deprecated_func arginfo_zend_test_void_return
|
||||
|
@ -216,6 +222,9 @@ static ZEND_FUNCTION(zend_test_crash);
|
|||
static ZEND_FUNCTION(zend_test_override_libxml_global_state);
|
||||
#endif
|
||||
static ZEND_FUNCTION(zend_test_is_pcre_bundled);
|
||||
#if defined(PHP_WIN32)
|
||||
static ZEND_FUNCTION(zend_test_set_fmode);
|
||||
#endif
|
||||
static ZEND_FUNCTION(ZendTestNS2_namespaced_func);
|
||||
static ZEND_FUNCTION(ZendTestNS2_namespaced_deprecated_func);
|
||||
static ZEND_FUNCTION(ZendTestNS2_ZendSubNS_namespaced_func);
|
||||
|
@ -275,6 +284,9 @@ static const zend_function_entry ext_functions[] = {
|
|||
ZEND_FE(zend_test_override_libxml_global_state, arginfo_zend_test_override_libxml_global_state)
|
||||
#endif
|
||||
ZEND_FE(zend_test_is_pcre_bundled, arginfo_zend_test_is_pcre_bundled)
|
||||
#if defined(PHP_WIN32)
|
||||
ZEND_FE(zend_test_set_fmode, arginfo_zend_test_set_fmode)
|
||||
#endif
|
||||
ZEND_NS_FALIAS("ZendTestNS2", namespaced_func, ZendTestNS2_namespaced_func, arginfo_ZendTestNS2_namespaced_func)
|
||||
ZEND_NS_DEP_FALIAS("ZendTestNS2", namespaced_deprecated_func, ZendTestNS2_namespaced_deprecated_func, arginfo_ZendTestNS2_namespaced_deprecated_func)
|
||||
ZEND_NS_FALIAS("ZendTestNS2", namespaced_aliased_func, zend_test_void_return, arginfo_ZendTestNS2_namespaced_aliased_func)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue