Skip to content

Commit 30996a9

Browse files
committed
ext/soap: Convert bailouts to normal exception throwing in SoapServer::__constructor()
Use ValueErrors as the conditions checked are programming errors Also narrow down bailout mechanism use in it as only the call to get_sdl() requires us to use the bailout mechanism.
1 parent a0fbb94 commit 30996a9

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

ext/soap/soap.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,6 @@ PHP_METHOD(SoapServer, __construct)
920920
RETURN_THROWS();
921921
}
922922

923-
SOAP_SERVER_BEGIN_CODE();
924-
925923
service = emalloc(sizeof(soapService));
926924
memset(service, 0, sizeof(soapService));
927925
service->send_errors = 1;
@@ -934,18 +932,19 @@ PHP_METHOD(SoapServer, __construct)
934932

935933
if ((tmp = zend_hash_str_find(ht, "soap_version", sizeof("soap_version")-1)) != NULL) {
936934
if (Z_TYPE_P(tmp) == IS_LONG &&
937-
(Z_LVAL_P(tmp) == SOAP_1_1 || Z_LVAL_P(tmp) == SOAP_1_2)) {
935+
(Z_LVAL_P(tmp) == SOAP_1_1 || Z_LVAL_P(tmp) == SOAP_1_2)) {
938936
version = Z_LVAL_P(tmp);
939937
} else {
940-
php_error_docref(NULL, E_ERROR, "'soap_version' option must be SOAP_1_1 or SOAP_1_2");
938+
zend_argument_value_error(2, "\"soap_version\" option must be SOAP_1_1 or SOAP_1_2");
939+
goto error;
941940
}
942941
}
943942

944-
if ((tmp = zend_hash_str_find(ht, "uri", sizeof("uri")-1)) != NULL &&
945-
Z_TYPE_P(tmp) == IS_STRING) {
943+
if ((tmp = zend_hash_str_find(ht, "uri", sizeof("uri")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
946944
service->uri = estrndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
947945
} else if (!wsdl) {
948-
php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
946+
zend_argument_value_error(2, "must provide \"uri\" option as it is required in nonWSDL mode");
947+
goto error;
949948
}
950949

951950
if ((tmp = zend_hash_str_find(ht, "actor", sizeof("actor")-1)) != NULL &&
@@ -959,7 +958,8 @@ PHP_METHOD(SoapServer, __construct)
959958

960959
encoding = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
961960
if (encoding == NULL) {
962-
php_error_docref(NULL, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_P(tmp));
961+
zend_argument_value_error(2, "provided \"encoding\" option \"%s\" is invalid", Z_STRVAL_P(tmp));
962+
goto error;
963963
} else {
964964
service->encoding = encoding;
965965
}
@@ -997,16 +997,27 @@ PHP_METHOD(SoapServer, __construct)
997997
}
998998

999999
} else if (!wsdl) {
1000-
php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
1000+
zend_argument_value_error(2, "must provide \"uri\" option as it is required in nonWSDL mode");
1001+
goto error;
10011002
}
10021003

10031004
service->version = version;
10041005
service->type = SOAP_FUNCTIONS;
10051006
service->soap_functions.functions_all = FALSE;
10061007
service->soap_functions.ft = zend_new_array(0);
10071008

1009+
if (typemap_ht) {
1010+
service->typemap = soap_create_typemap(service->sdl, typemap_ht);
1011+
if (UNEXPECTED(service->typemap == NULL)) {
1012+
goto error;
1013+
}
1014+
}
1015+
10081016
if (wsdl) {
1017+
SOAP_SERVER_BEGIN_CODE();
10091018
service->sdl = get_sdl(ZEND_THIS, ZSTR_VAL(wsdl), cache_wsdl);
1019+
SOAP_SERVER_END_CODE();
1020+
10101021
if (service->uri == NULL) {
10111022
if (service->sdl->target_ns) {
10121023
service->uri = estrdup(service->sdl->target_ns);
@@ -1017,14 +1028,13 @@ PHP_METHOD(SoapServer, __construct)
10171028
}
10181029
}
10191030

1020-
if (typemap_ht) {
1021-
service->typemap = soap_create_typemap(service->sdl, typemap_ht);
1022-
}
1023-
10241031
soap_server_object *server_obj = soap_server_object_fetch(Z_OBJ_P(ZEND_THIS));
10251032
server_obj->service = service;
1033+
return;
10261034

1027-
SOAP_SERVER_END_CODE();
1035+
error:
1036+
efree(service);
1037+
RETURN_THROWS();
10281038
}
10291039
/* }}} */
10301040

ext/soap/tests/SoapServer/invalid-encoding-option.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ try {
2525

2626
?>
2727
--EXPECT--
28-
<?xml version="1.0" encoding="UTF-8"?>
29-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SoapServer::__construct(): Invalid 'encoding' option - 'non-sense'</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
28+
ValueError: SoapServer::__construct(): Argument #2 ($options) provided "encoding" option "non-sense" is invalid
29+
ValueError: SoapServer::__construct(): Argument #2 ($options) provided "encoding" option "non-sense" is invalid

ext/soap/tests/SoapServer/invalid-soap_version-option.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ try {
2525

2626
?>
2727
--EXPECT--
28-
<?xml version="1.0" encoding="UTF-8"?>
29-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SoapServer::__construct(): 'soap_version' option must be SOAP_1_1 or SOAP_1_2</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
28+
ValueError: SoapServer::__construct(): Argument #2 ($options) "soap_version" option must be SOAP_1_1 or SOAP_1_2
29+
ValueError: SoapServer::__construct(): Argument #2 ($options) "soap_version" option must be SOAP_1_1 or SOAP_1_2

ext/soap/tests/SoapServer/missing-options-non-wsdl-mode.phpt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,11 @@ try {
3232
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
3333
}
3434

35-
echo "\$options array only sets \"uri\" option\n";
36-
$options = ['uri' => 'https://example.com'];
37-
try {
38-
$client = new SoapServer(null, $options);
39-
} catch (Throwable $e) {
40-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
41-
}
42-
try {
43-
$client = new ExtendedSoapServer(null, $options);
44-
} catch (Throwable $e) {
45-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
46-
}
47-
4835
?>
4936
--EXPECT--
5037
$options not provided
51-
<?xml version="1.0" encoding="UTF-8"?>
52-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SoapServer::__construct(): 'uri' option is required in nonWSDL mode</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
38+
ValueError: SoapServer::__construct(): Argument #2 ($options) must provide "uri" option as it is required in nonWSDL mode
39+
ValueError: SoapServer::__construct(): Argument #2 ($options) must provide "uri" option as it is required in nonWSDL mode
40+
Empty $options array
41+
ValueError: SoapServer::__construct(): Argument #2 ($options) must provide "uri" option as it is required in nonWSDL mode
42+
ValueError: SoapServer::__construct(): Argument #2 ($options) must provide "uri" option as it is required in nonWSDL mode

0 commit comments

Comments
 (0)