From 51c2cf0f56f4649fa5119c9c3a7366c18bad516e Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 11 Jan 2025 14:29:01 +0000 Subject: [PATCH 1/6] ext/soap: Add some SoapServer tests --- ...ndle_non_existing_WSDL_from_get_query.phpt | 78 ++++++++++++++++ ..._WSDL_from_get_query_disable_readfile.phpt | 84 ++++++++++++++++++ ...WSDL_from_get_query_redefine_readfile.phpt | 88 +++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt create mode 100644 ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt create mode 100644 ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt new file mode 100644 index 0000000000000..5a71529555288 --- /dev/null +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt @@ -0,0 +1,78 @@ +--TEST-- +SoapServer handle with WSDL that has disappeared +--EXTENSIONS-- +soap +--GET-- +WSDL +--FILE-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WSDL; + +file_put_contents($wsdlFile, $wsdl); + +$options = []; +$server = new SoapServer($wsdlFile, $options); + +unlink($wsdlFile); + +$server->handle(); + +?> +--CLEAN-- + +--EXPECT-- diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt new file mode 100644 index 0000000000000..5672cb66afa83 --- /dev/null +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt @@ -0,0 +1,84 @@ +--TEST-- +SoapServer handle with WSDL that has disappeared and disabled readfile function +--EXTENSIONS-- +soap +--GET-- +WSDL +--INI-- +disable_functions=readfile +--FILE-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WSDL; + +file_put_contents($wsdlFile, $wsdl); + +$options = []; +$server = new SoapServer($wsdlFile, $options); + +unlink($wsdlFile); + +try { + $server->handle(); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +?> +--CLEAN-- + +--EXPECT-- +Error: Invalid callback readfile, function "readfile" not found or invalid function name diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt new file mode 100644 index 0000000000000..398726e732347 --- /dev/null +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt @@ -0,0 +1,88 @@ +--TEST-- +SoapServer handle with WSDL that has disappeared and disabled and redefined readfile function +--EXTENSIONS-- +soap +--GET-- +WSDL +--INI-- +disable_functions=readfile +--FILE-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WSDL; + +function readfile(string $str) { + throw new Exception('BOO'); +} + +file_put_contents($wsdlFile, $wsdl); + +$options = []; +$server = new SoapServer($wsdlFile, $options); + +unlink($wsdlFile); + +try { + $server->handle(); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +?> +--CLEAN-- + +--EXPECT-- +Exception: BOO From 78e50f5ee39d06e05e5ca00c9426294987f383d3 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Fri, 10 Jan 2025 13:43:08 +0000 Subject: [PATCH 2/6] ext/soap: Don't call readfile() userland function We can perform the operation directly, moreover there is no risk of a user disabling the readfile function and defining their own messing up what we are doing. --- ext/soap/soap.c | 13 ++++--------- ...isting_WSDL_from_get_query_disable_readfile.phpt | 1 - ...sting_WSDL_from_get_query_redefine_readfile.phpt | 1 - 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 48a7fc8885e44..c473686f7feb7 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1307,19 +1307,14 @@ PHP_METHOD(SoapServer, handle) sapi_add_header(hdr, sizeof("Location: ")+strlen(service->sdl->source)-1, 1); efree(hdr); */ - zval readfile, readfile_ret, param; sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1); - ZVAL_STRING(¶m, service->sdl->source); - ZVAL_STRING(&readfile, "readfile"); - if (call_user_function(EG(function_table), NULL, &readfile, &readfile_ret, 1, ¶m ) == FAILURE) { - soap_server_fault("Server", "Couldn't find WSDL", NULL, NULL, NULL); + php_stream *stream = php_stream_open_wrapper_ex(service->sdl->source, "rb", REPORT_ERRORS, NULL, /* context */ NULL); + if (stream) { + php_stream_passthru(stream); + php_stream_close(stream); } - zval_ptr_dtor(¶m); - zval_ptr_dtor_str(&readfile); - zval_ptr_dtor(&readfile_ret); - SOAP_SERVER_END_CODE(); return; } else { diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt index 5672cb66afa83..1a7cf130209a9 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt @@ -81,4 +81,3 @@ $wsdlFile = __DIR__ . '/test_handle_non_existent_wsdl.wsdl'; @unlink($wsdlFile); ?> --EXPECT-- -Error: Invalid callback readfile, function "readfile" not found or invalid function name diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt index 398726e732347..9f2df710a4700 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt @@ -85,4 +85,3 @@ $wsdlFile = __DIR__ . '/test_handle_non_existent_wsdl.wsdl'; @unlink($wsdlFile); ?> --EXPECT-- -Exception: BOO From 6eb11552bdf21509fc147dc4b738388d1a614be8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 11 Jan 2025 13:58:52 +0000 Subject: [PATCH 3/6] ext/soap: Actually throw a SOAP Fault if the WSDL has disappeared --- ext/soap/soap.c | 2 ++ .../SoapServer/handle_non_existing_WSDL_from_get_query.phpt | 2 ++ ...andle_non_existing_WSDL_from_get_query_disable_readfile.phpt | 2 ++ ...ndle_non_existing_WSDL_from_get_query_redefine_readfile.phpt | 2 ++ 4 files changed, 8 insertions(+) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index c473686f7feb7..d7231d4a5d206 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1313,6 +1313,8 @@ PHP_METHOD(SoapServer, handle) if (stream) { php_stream_passthru(stream); php_stream_close(stream); + } else { + soap_server_fault("Server", "Couldn't find WSDL", NULL, NULL, NULL); } SOAP_SERVER_END_CODE(); diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt index 5a71529555288..efe80aa0706d8 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt @@ -76,3 +76,5 @@ $wsdlFile = __DIR__ . '/test_handle_non_existent_wsdl.wsdl'; @unlink($wsdlFile); ?> --EXPECT-- + +SOAP-ENV:ServerCouldn't find WSDL diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt index 1a7cf130209a9..d883a18b442ee 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt @@ -81,3 +81,5 @@ $wsdlFile = __DIR__ . '/test_handle_non_existent_wsdl.wsdl'; @unlink($wsdlFile); ?> --EXPECT-- + +SOAP-ENV:ServerCouldn't find WSDL diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt index 9f2df710a4700..c147b6c8d8276 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt @@ -85,3 +85,5 @@ $wsdlFile = __DIR__ . '/test_handle_non_existent_wsdl.wsdl'; @unlink($wsdlFile); ?> --EXPECT-- + +SOAP-ENV:ServerCouldn't find WSDL From e101ce03dd088bce3fe2145de5e0022cb71433e8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 13 Jan 2025 11:48:48 +0000 Subject: [PATCH 4/6] review --- ext/soap/soap.c | 3 +- ...ndle_non_existing_WSDL_from_get_query.phpt | 4 +- ..._WSDL_from_get_query_disable_readfile.phpt | 10 +-- ...WSDL_from_get_query_redefine_readfile.phpt | 89 ------------------- 4 files changed, 7 insertions(+), 99 deletions(-) delete mode 100644 ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt diff --git a/ext/soap/soap.c b/ext/soap/soap.c index d7231d4a5d206..ef00324d8afef 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1309,7 +1309,8 @@ PHP_METHOD(SoapServer, handle) */ sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1); - php_stream *stream = php_stream_open_wrapper_ex(service->sdl->source, "rb", REPORT_ERRORS, NULL, /* context */ NULL); + php_stream_context *context = php_stream_context_from_zval(NULL, false); + php_stream *stream = php_stream_open_wrapper_ex(service->sdl->source, "rb", REPORT_ERRORS, NULL, context); if (stream) { php_stream_passthru(stream); php_stream_close(stream); diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt index efe80aa0706d8..1ddefa99da51f 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt @@ -6,7 +6,7 @@ soap WSDL --FILE-- @@ -72,7 +72,7 @@ $server->handle(); ?> --CLEAN-- --EXPECT-- diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt index d883a18b442ee..10066897b9ecc 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt @@ -8,7 +8,7 @@ WSDL disable_functions=readfile --FILE-- @@ -68,16 +68,12 @@ $options = []; $server = new SoapServer($wsdlFile, $options); unlink($wsdlFile); +$server->handle(); -try { - $server->handle(); -} catch (Throwable $e) { - echo $e::class, ': ', $e->getMessage(), PHP_EOL; -} ?> --CLEAN-- --EXPECT-- diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt deleted file mode 100644 index c147b6c8d8276..0000000000000 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_redefine_readfile.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -SoapServer handle with WSDL that has disappeared and disabled and redefined readfile function ---EXTENSIONS-- -soap ---GET-- -WSDL ---INI-- -disable_functions=readfile ---FILE-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -WSDL; - -function readfile(string $str) { - throw new Exception('BOO'); -} - -file_put_contents($wsdlFile, $wsdl); - -$options = []; -$server = new SoapServer($wsdlFile, $options); - -unlink($wsdlFile); - -try { - $server->handle(); -} catch (Throwable $e) { - echo $e::class, ': ', $e->getMessage(), PHP_EOL; -} -?> ---CLEAN-- - ---EXPECT-- - -SOAP-ENV:ServerCouldn't find WSDL From e6305b4862a17767d1ccdd72412766e881402662 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 14 Jan 2025 12:03:30 +0000 Subject: [PATCH 5/6] Skip tests on windows for now --- .../SoapServer/handle_non_existing_WSDL_from_get_query.phpt | 6 ++++++ ...e_non_existing_WSDL_from_get_query_disable_readfile.phpt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt index 1ddefa99da51f..02580d6454770 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt @@ -2,6 +2,12 @@ SoapServer handle with WSDL that has disappeared --EXTENSIONS-- soap +--SKIPIF-- + --GET-- WSDL --FILE-- diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt index 10066897b9ecc..d9a5574e61d23 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt @@ -2,6 +2,12 @@ SoapServer handle with WSDL that has disappeared and disabled readfile function --EXTENSIONS-- soap +--SKIPIF-- + --GET-- WSDL --INI-- From d1e3520042caaf28828a99c58d0130408e31b96a Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 15 Jan 2025 14:36:53 +0000 Subject: [PATCH 6/6] [skip ci] Update skipif message --- .../SoapServer/handle_non_existing_WSDL_from_get_query.phpt | 2 +- ...andle_non_existing_WSDL_from_get_query_disable_readfile.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt index 02580d6454770..ca9f9f06ae93c 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query.phpt @@ -5,7 +5,7 @@ soap --SKIPIF-- --GET-- diff --git a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt index d9a5574e61d23..183a00acab238 100644 --- a/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt +++ b/ext/soap/tests/SoapServer/handle_non_existing_WSDL_from_get_query_disable_readfile.phpt @@ -5,7 +5,7 @@ soap --SKIPIF-- --GET--