Skip to content

Commit 2b1097a

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: 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 7c947b5 + 89c4db9 commit 2b1097a

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ PHP NEWS
2828

2929
- Soap:
3030
. Fixed bug #47925 (PHPClient can't decompress response). (nielsdos)
31+
. Fix missing error restore code. (nielsdos)
32+
. Fix memory leak if calling SoapServer::setObject() twice. (nielsdos)
33+
. Fix memory leak if calling SoapServer::setClass() twice. (nielsdos)
34+
. Fix reading zlib ini settings in ext-soap. (nielsdos)
3135

3236
- Sodium:
3337
. Fix memory leaks in ext/sodium on failure of some functions. (nielsdos)

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: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName,
6666
static void delete_service(void *service);
6767
static void delete_url(void *handle);
6868
static void delete_hashtable(void *hashtable);
69+
static void delete_argv(struct _soap_class *class);
6970

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

@@ -899,11 +900,9 @@ PHP_METHOD(SoapServer, setPersistence)
899900
zend_argument_value_error(
900901
1, "must be either SOAP_PERSISTENCE_SESSION or SOAP_PERSISTENCE_REQUEST when the SOAP server is used in class mode"
901902
);
902-
RETURN_THROWS();
903903
}
904904
} else {
905905
zend_throw_error(NULL, "SoapServer::setPersistence(): Persistence cannot be set when the SOAP server is used in function mode");
906-
RETURN_THROWS();
907906
}
908907

909908
SOAP_SERVER_END_CODE();
@@ -930,6 +929,8 @@ PHP_METHOD(SoapServer, setClass)
930929
service->type = SOAP_CLASS;
931930
service->soap_class.ce = ce;
932931

932+
delete_argv(&service->soap_class);
933+
933934
service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
934935
service->soap_class.argc = num_args;
935936
if (service->soap_class.argc > 0) {
@@ -961,6 +962,7 @@ PHP_METHOD(SoapServer, setObject)
961962

962963
service->type = SOAP_OBJECT;
963964

965+
zval_ptr_dtor(&service->soap_object);
964966
ZVAL_OBJ_COPY(&service->soap_object, Z_OBJ_P(obj));
965967

966968
SOAP_SERVER_END_CODE();
@@ -1042,13 +1044,15 @@ PHP_METHOD(SoapServer, addFunction)
10421044

10431045
if (Z_TYPE_P(tmp_function) != IS_STRING) {
10441046
zend_argument_type_error(1, "must contain only strings");
1047+
SOAP_SERVER_END_CODE();
10451048
RETURN_THROWS();
10461049
}
10471050

10481051
key = zend_string_tolower(Z_STR_P(tmp_function));
10491052

10501053
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
10511054
zend_type_error("SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
1055+
SOAP_SERVER_END_CODE();
10521056
RETURN_THROWS();
10531057
}
10541058

@@ -1066,6 +1070,7 @@ PHP_METHOD(SoapServer, addFunction)
10661070

10671071
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
10681072
zend_argument_type_error(1, "must be a valid function name, function \"%s\" not found", Z_STRVAL_P(function_name));
1073+
SOAP_SERVER_END_CODE();
10691074
RETURN_THROWS();
10701075
}
10711076
if (service->soap_functions.ft == NULL) {
@@ -1086,11 +1091,9 @@ PHP_METHOD(SoapServer, addFunction)
10861091
service->soap_functions.functions_all = TRUE;
10871092
} else {
10881093
zend_argument_value_error(1, "must be SOAP_FUNCTIONS_ALL when an integer is passed");
1089-
RETURN_THROWS();
10901094
}
10911095
} else {
10921096
zend_argument_type_error(1, "must be of type array|string|int, %s given", zend_zval_value_name(function_name));
1093-
RETURN_THROWS();
10941097
}
10951098

10961099
SOAP_SERVER_END_CODE();
@@ -1150,6 +1153,7 @@ PHP_METHOD(SoapServer, handle)
11501153

11511154
if (arg && ZEND_SIZE_T_INT_OVFL(arg_len)) {
11521155
soap_server_fault("Server", "Input string is too long", NULL, NULL, NULL);
1156+
SOAP_SERVER_END_CODE();
11531157
return;
11541158
}
11551159

@@ -1231,10 +1235,12 @@ PHP_METHOD(SoapServer, handle)
12311235
php_stream_filter_append(&SG(request_info).request_body->readfilters, zf);
12321236
} else {
12331237
php_error_docref(NULL, E_WARNING,"Can't uncompress compressed request");
1238+
SOAP_SERVER_END_CODE();
12341239
return;
12351240
}
12361241
} else {
12371242
php_error_docref(NULL, E_WARNING,"Request is compressed with unknown compression '%s'",Z_STRVAL_P(encoding));
1243+
SOAP_SERVER_END_CODE();
12381244
return;
12391245
}
12401246
}
@@ -1246,6 +1252,7 @@ PHP_METHOD(SoapServer, handle)
12461252
}
12471253
} else {
12481254
zval_ptr_dtor(&retval);
1255+
SOAP_SERVER_END_CODE();
12491256
return;
12501257
}
12511258
} else {
@@ -1520,7 +1527,7 @@ PHP_METHOD(SoapServer, handle)
15201527
sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
15211528
}
15221529

1523-
if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
1530+
if (INI_INT("zlib.output_compression")) {
15241531
sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
15251532
} else {
15261533
snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
@@ -1622,6 +1629,7 @@ PHP_METHOD(SoapServer, addSoapHeader)
16221629

16231630
if (!service || !service->soap_headers_ptr) {
16241631
zend_throw_error(NULL, "SoapServer::addSoapHeader() may be called only during SOAP request processing");
1632+
SOAP_SERVER_END_CODE();
16251633
RETURN_THROWS();
16261634
}
16271635

@@ -1668,7 +1676,7 @@ static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeade
16681676
if (use_http_error_status) {
16691677
sapi_add_header("HTTP/1.1 500 Internal Server Error", sizeof("HTTP/1.1 500 Internal Server Error")-1, 1);
16701678
}
1671-
if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
1679+
if (INI_INT("zlib.output_compression")) {
16721680
sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
16731681
} else {
16741682
snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
@@ -4342,6 +4350,16 @@ static void delete_url(void *handle) /* {{{ */
43424350
}
43434351
/* }}} */
43444352

4353+
static void delete_argv(struct _soap_class *class)
4354+
{
4355+
if (class->argc) {
4356+
for (int i = 0; i < class->argc; i++) {
4357+
zval_ptr_dtor(&class->argv[i]);
4358+
}
4359+
efree(class->argv);
4360+
}
4361+
}
4362+
43454363
static void delete_service(void *data) /* {{{ */
43464364
{
43474365
soapServicePtr service = (soapServicePtr)data;
@@ -4356,13 +4374,7 @@ static void delete_service(void *data) /* {{{ */
43564374
efree(service->typemap);
43574375
}
43584376

4359-
if (service->soap_class.argc) {
4360-
int i;
4361-
for (i = 0; i < service->soap_class.argc;i++) {
4362-
zval_ptr_dtor(&service->soap_class.argv[i]);
4363-
}
4364-
efree(service->soap_class.argv);
4365-
}
4377+
delete_argv(&service->soap_class);
43664378

43674379
if (service->actor) {
43684380
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)