From fc08992e4c38087e1f0c7fbecec4a3d3c577b5bc Mon Sep 17 00:00:00 2001 From: alexanderholman Date: Thu, 4 Jan 2018 23:01:29 +0000 Subject: [PATCH 1/6] fix #74719 update Z_PARAM_RESOURCE to allow NULL --- ext/standard/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index 9c69874c79160..c527e7f8bb34b 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -883,7 +883,7 @@ PHP_NAMED_FUNCTION(php_if_fopen) Z_PARAM_STRING(mode, mode_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(use_include_path) - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); From 2cd3e894dc55b79cbdfbe4b0d8755d55647b9e0e Mon Sep 17 00:00:00 2001 From: alexanderholman Date: Thu, 4 Jan 2018 23:37:53 +0000 Subject: [PATCH 2/6] add tests for fix 74719 --- ext/standard/tests/file/bug74719.phpt | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 ext/standard/tests/file/bug74719.phpt diff --git a/ext/standard/tests/file/bug74719.phpt b/ext/standard/tests/file/bug74719.phpt new file mode 100644 index 0000000000000..73d5aa9084a85 --- /dev/null +++ b/ext/standard/tests/file/bug74719.phpt @@ -0,0 +1,54 @@ +--TEST-- +Bug #74719 Allow NULL as context +--CREDITS-- +Alexander Holman +--FILE-- + +===DONE=== +--EXPECT-- +open and write okay +open and read okay +===DONE=== From 2707bbb892816b645c554f271c7b083734bcb5d0 Mon Sep 17 00:00:00 2001 From: alexanderholman Date: Thu, 4 Jan 2018 23:51:12 +0000 Subject: [PATCH 3/6] adjust Z_PARAM_RESOURCE to check NULL --- Zend/zend_API.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 21b6802ec6afc..968068590fdb9 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1034,7 +1034,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(zend_bool throw_ Z_PARAM_RESOURCE_EX2(dest, check_null, separate, separate) #define Z_PARAM_RESOURCE(dest) \ - Z_PARAM_RESOURCE_EX(dest, 0, 0) + Z_PARAM_RESOURCE_EX(dest, 1, 0) /* old "s" */ #define Z_PARAM_STRING_EX2(dest, dest_len, check_null, deref, separate) \ From 020ada048a0ceb2ceee8984955f56d1640ba8b7c Mon Sep 17 00:00:00 2001 From: alexanderholman Date: Thu, 4 Jan 2018 23:51:55 +0000 Subject: [PATCH 4/6] remove incorrect modification (breaking build) --- ext/standard/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index c527e7f8bb34b..9c69874c79160 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -883,7 +883,7 @@ PHP_NAMED_FUNCTION(php_if_fopen) Z_PARAM_STRING(mode, mode_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(use_include_path) - Z_PARAM_RESOURCE(zcontext, 1, 0) + Z_PARAM_RESOURCE(zcontext) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); From a6856a91c58e699fc79c98707dd5bf7839c7f4f6 Mon Sep 17 00:00:00 2001 From: alexanderholman Date: Thu, 4 Jan 2018 23:58:14 +0000 Subject: [PATCH 5/6] revert function args --- Zend/zend_API.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 968068590fdb9..21b6802ec6afc 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1034,7 +1034,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(zend_bool throw_ Z_PARAM_RESOURCE_EX2(dest, check_null, separate, separate) #define Z_PARAM_RESOURCE(dest) \ - Z_PARAM_RESOURCE_EX(dest, 1, 0) + Z_PARAM_RESOURCE_EX(dest, 0, 0) /* old "s" */ #define Z_PARAM_STRING_EX2(dest, dest_len, check_null, deref, separate) \ From b7dd6b0321f4aec6d35ea3118b63390ada7fe378 Mon Sep 17 00:00:00 2001 From: alexanderholman Date: Thu, 4 Jan 2018 23:59:24 +0000 Subject: [PATCH 6/6] use Z_PARAM_RESOURCE_EX to allow check NULL --- ext/standard/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index 9c69874c79160..b8c30e44d1680 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -883,7 +883,7 @@ PHP_NAMED_FUNCTION(php_if_fopen) Z_PARAM_STRING(mode, mode_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(use_include_path) - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0);