Skip to content

Commit a58c3a7

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix reading zlib ini settings in ext-soap Fix memory leak if calling SoapServer::setClass() twice Fix memory leak if calling SoapServer::setObject() twice Fix missing error restore code in ext-soap (#14379) Fix GH-14368: Test failure in ext/session/tests/gh13856.phpt (#14378)
2 parents 5e242fe + 2b1097a commit a58c3a7

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

ext/session/tests/gh13856.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ session
66
session.save_handler=files
77
open_basedir=.
88
error_reporting=E_ALL
9+
session.save_path=
910
--FILE--
1011
<?php
1112
session_set_save_handler(new \SessionHandler(), true);

ext/soap/soap.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static xmlNodePtr serialize_parameter(sdlParamPtr param,zval *param_val,int inde
6565
static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName, int style, xmlNodePtr parent);
6666

6767
static void delete_service(void *service);
68+
static void delete_hashtable(void *hashtable);
69+
static void delete_argv(struct _soap_class *class);
6870

6971
static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
7072

@@ -1012,11 +1014,9 @@ PHP_METHOD(SoapServer, setPersistence)
10121014
zend_argument_value_error(
10131015
1, "must be either SOAP_PERSISTENCE_SESSION or SOAP_PERSISTENCE_REQUEST when the SOAP server is used in class mode"
10141016
);
1015-
RETURN_THROWS();
10161017
}
10171018
} else {
10181019
zend_throw_error(NULL, "SoapServer::setPersistence(): Persistence cannot be set when the SOAP server is used in function mode");
1019-
RETURN_THROWS();
10201020
}
10211021

10221022
SOAP_SERVER_END_CODE();
@@ -1043,6 +1043,8 @@ PHP_METHOD(SoapServer, setClass)
10431043
service->type = SOAP_CLASS;
10441044
service->soap_class.ce = ce;
10451045

1046+
delete_argv(&service->soap_class);
1047+
10461048
service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
10471049
service->soap_class.argc = num_args;
10481050
if (service->soap_class.argc > 0) {
@@ -1074,6 +1076,7 @@ PHP_METHOD(SoapServer, setObject)
10741076

10751077
service->type = SOAP_OBJECT;
10761078

1079+
zval_ptr_dtor(&service->soap_object);
10771080
ZVAL_OBJ_COPY(&service->soap_object, Z_OBJ_P(obj));
10781081

10791082
SOAP_SERVER_END_CODE();
@@ -1155,13 +1158,15 @@ PHP_METHOD(SoapServer, addFunction)
11551158

11561159
if (Z_TYPE_P(tmp_function) != IS_STRING) {
11571160
zend_argument_type_error(1, "must contain only strings");
1161+
SOAP_SERVER_END_CODE();
11581162
RETURN_THROWS();
11591163
}
11601164

11611165
key = zend_string_tolower(Z_STR_P(tmp_function));
11621166

11631167
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
11641168
zend_type_error("SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
1169+
SOAP_SERVER_END_CODE();
11651170
RETURN_THROWS();
11661171
}
11671172

@@ -1179,6 +1184,7 @@ PHP_METHOD(SoapServer, addFunction)
11791184

11801185
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
11811186
zend_argument_type_error(1, "must be a valid function name, function \"%s\" not found", Z_STRVAL_P(function_name));
1187+
SOAP_SERVER_END_CODE();
11821188
RETURN_THROWS();
11831189
}
11841190
if (service->soap_functions.ft == NULL) {
@@ -1199,11 +1205,9 @@ PHP_METHOD(SoapServer, addFunction)
11991205
service->soap_functions.functions_all = TRUE;
12001206
} else {
12011207
zend_argument_value_error(1, "must be SOAP_FUNCTIONS_ALL when an integer is passed");
1202-
RETURN_THROWS();
12031208
}
12041209
} else {
12051210
zend_argument_type_error(1, "must be of type array|string|int, %s given", zend_zval_value_name(function_name));
1206-
RETURN_THROWS();
12071211
}
12081212

12091213
SOAP_SERVER_END_CODE();
@@ -1263,6 +1267,7 @@ PHP_METHOD(SoapServer, handle)
12631267

12641268
if (arg && ZEND_SIZE_T_INT_OVFL(arg_len)) {
12651269
soap_server_fault("Server", "Input string is too long", NULL, NULL, NULL);
1270+
SOAP_SERVER_END_CODE();
12661271
return;
12671272
}
12681273

@@ -1344,10 +1349,12 @@ PHP_METHOD(SoapServer, handle)
13441349
php_stream_filter_append(&SG(request_info).request_body->readfilters, zf);
13451350
} else {
13461351
php_error_docref(NULL, E_WARNING,"Can't uncompress compressed request");
1352+
SOAP_SERVER_END_CODE();
13471353
return;
13481354
}
13491355
} else {
13501356
php_error_docref(NULL, E_WARNING,"Request is compressed with unknown compression '%s'",Z_STRVAL_P(encoding));
1357+
SOAP_SERVER_END_CODE();
13511358
return;
13521359
}
13531360
}
@@ -1359,6 +1366,7 @@ PHP_METHOD(SoapServer, handle)
13591366
}
13601367
} else {
13611368
zval_ptr_dtor(&retval);
1369+
SOAP_SERVER_END_CODE();
13621370
return;
13631371
}
13641372
} else {
@@ -1618,7 +1626,7 @@ PHP_METHOD(SoapServer, handle)
16181626
sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
16191627
}
16201628

1621-
if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
1629+
if (INI_INT("zlib.output_compression")) {
16221630
sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
16231631
} else {
16241632
snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
@@ -1720,6 +1728,7 @@ PHP_METHOD(SoapServer, addSoapHeader)
17201728

17211729
if (!service || !service->soap_headers_ptr) {
17221730
zend_throw_error(NULL, "SoapServer::addSoapHeader() may be called only during SOAP request processing");
1731+
SOAP_SERVER_END_CODE();
17231732
RETURN_THROWS();
17241733
}
17251734

@@ -1766,7 +1775,7 @@ static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeade
17661775
if (use_http_error_status) {
17671776
sapi_add_header("HTTP/1.1 500 Internal Server Error", sizeof("HTTP/1.1 500 Internal Server Error")-1, 1);
17681777
}
1769-
if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
1778+
if (INI_INT("zlib.output_compression")) {
17701779
sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
17711780
} else {
17721781
snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
@@ -4439,6 +4448,16 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */
44394448
}
44404449
/* }}} */
44414450

4451+
static void delete_argv(struct _soap_class *class)
4452+
{
4453+
if (class->argc) {
4454+
for (int i = 0; i < class->argc; i++) {
4455+
zval_ptr_dtor(&class->argv[i]);
4456+
}
4457+
efree(class->argv);
4458+
}
4459+
}
4460+
44424461
static void delete_service(void *data) /* {{{ */
44434462
{
44444463
soapServicePtr service = (soapServicePtr)data;
@@ -4453,13 +4472,7 @@ static void delete_service(void *data) /* {{{ */
44534472
efree(service->typemap);
44544473
}
44554474

4456-
if (service->soap_class.argc) {
4457-
int i;
4458-
for (i = 0; i < service->soap_class.argc;i++) {
4459-
zval_ptr_dtor(&service->soap_class.argv[i]);
4460-
}
4461-
efree(service->soap_class.argv);
4462-
}
4475+
delete_argv(&service->soap_class);
44634476

44644477
if (service->actor) {
44654478
efree(service->actor);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
SOAP Server: SoapServer::setClass() twice
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
class Foo {
8+
function test() {
9+
return "Hello World";
10+
}
11+
}
12+
13+
$server = new SoapServer(null,array('uri'=>"http://testuri.org"));
14+
$server->setClass(Foo::class, new stdClass, []);
15+
$server->setClass(Foo::class, new stdClass, []);
16+
17+
echo "Done\n";
18+
?>
19+
--EXPECT--
20+
Done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
SOAP Server: SoapServer::setObject twice
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
$foo = new stdClass();
8+
$server = new SoapServer(null,array('uri'=>"http://testuri.org"));
9+
$server->setObject($foo);
10+
$server->setObject($foo);
11+
echo "Done\n";
12+
?>
13+
--EXPECT--
14+
Done

0 commit comments

Comments
 (0)