Skip to content

Commit 3fb41c2

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79191: Error in SoapClient ctor disables DOMDocument::save()
2 parents 58b1790 + fe1bfb7 commit 3fb41c2

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ PHP NEWS
2727
-Intl:
2828
. Fixed bug #79212 (NumberFormatter::format() may detect wrong type). (cmb)
2929

30+
- Libxml:
31+
. Fixed bug #79191 (Error in SoapClient ctor disables DOMDocument::save()).
32+
(Nikita, cmb)
33+
3034
- MBString:
3135
. Fixed bug #79149 (SEGV in mb_convert_encoding with non-string encodings).
3236
(cmb)

ext/libxml/libxml.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ static int php_libxml_streams_IO_read(void *context, char *buffer, int len)
382382

383383
static int php_libxml_streams_IO_write(void *context, const char *buffer, int len)
384384
{
385-
if (CG(unclean_shutdown)) {
386-
return -1;
387-
}
388385
return php_stream_write((php_stream*)context, buffer, len);
389386
}
390387

ext/libxml/tests/bug79191.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #79191 (Error in SoapClient ctor disables DOMDocument::save())
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('soap')) die('skip soap extension not available');
6+
if (!extension_loaded('dom')) die('dom extension not available');
7+
?>
8+
--FILE--
9+
<?php
10+
try {
11+
new \SoapClient('does-not-exist.wsdl');
12+
} catch (Throwable $t) {
13+
}
14+
15+
$dom = new DOMDocument;
16+
$dom->loadxml('<?xml version="1.0" ?><root />');
17+
var_dump($dom->save(__DIR__ . '/bug79191.xml'));
18+
?>
19+
--CLEAN--
20+
<?php
21+
unlink(__DIR__ . '/bug79191.xml');
22+
?>
23+
--EXPECTF--
24+
int(%d)

ext/xmlwriter/php_xmlwriter.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ typedef int (*xmlwriter_read_int_t)(xmlTextWriterPtr writer);
8383
static void xmlwriter_free_resource_ptr(xmlwriter_object *intern)
8484
{
8585
if (intern) {
86-
if (EG(active)) {
87-
if (intern->ptr) {
88-
xmlFreeTextWriter(intern->ptr);
89-
intern->ptr = NULL;
90-
}
91-
if (intern->output) {
92-
xmlBufferFree(intern->output);
93-
intern->output = NULL;
94-
}
86+
if (intern->ptr) {
87+
xmlFreeTextWriter(intern->ptr);
88+
intern->ptr = NULL;
89+
}
90+
if (intern->output) {
91+
xmlBufferFree(intern->output);
92+
intern->output = NULL;
9593
}
9694
efree(intern);
9795
}
@@ -112,17 +110,25 @@ static void xmlwriter_free_resource_ptr(xmlwriter_object *intern)
112110

113111
static zend_object_handlers xmlwriter_object_handlers;
114112

115-
/* {{{ xmlwriter_object_free_storage */
116-
static void xmlwriter_object_free_storage(zend_object *object)
113+
/* {{{{ xmlwriter_object_dtor */
114+
static void xmlwriter_object_dtor(zend_object *object)
117115
{
118116
ze_xmlwriter_object *intern = php_xmlwriter_fetch_object(object);
119-
if (!intern) {
120-
return;
121-
}
117+
118+
/* freeing the resource here may leak, but otherwise we may use it after it has been freed */
122119
if (intern->xmlwriter_ptr) {
123120
xmlwriter_free_resource_ptr(intern->xmlwriter_ptr);
124121
}
125122
intern->xmlwriter_ptr = NULL;
123+
zend_objects_destroy_object(object);
124+
}
125+
/* }}} */
126+
127+
/* {{{ xmlwriter_object_free_storage */
128+
static void xmlwriter_object_free_storage(zend_object *object)
129+
{
130+
ze_xmlwriter_object *intern = php_xmlwriter_fetch_object(object);
131+
126132
zend_object_std_dtor(&intern->std);
127133
}
128134
/* }}} */
@@ -1818,6 +1824,7 @@ static PHP_MINIT_FUNCTION(xmlwriter)
18181824

18191825
memcpy(&xmlwriter_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
18201826
xmlwriter_object_handlers.offset = XtOffsetOf(ze_xmlwriter_object, std);
1827+
xmlwriter_object_handlers.dtor_obj = xmlwriter_object_dtor;
18211828
xmlwriter_object_handlers.free_obj = xmlwriter_object_free_storage;
18221829
xmlwriter_object_handlers.clone_obj = NULL;
18231830
INIT_CLASS_ENTRY(ce, "XMLWriter", xmlwriter_class_functions);

ext/xmlwriter/tests/bug71536.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #71536 (Access Violation crashes php-cgi.exe)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('xmlwriter')) die('skip xmlwriter extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
class Test {
10+
public static function init()
11+
{
12+
$xml = new \XMLWriter();
13+
$xml->openUri('php://memory');
14+
$xml->setIndent(false);
15+
$xml->startDocument('1.0', 'UTF-8');
16+
$xml->startElement('response');
17+
die('now'); // crashed with die()
18+
}
19+
}
20+
21+
Test::init();
22+
?>
23+
--EXPECT--
24+
now

ext/xmlwriter/tests/bug79029.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ $x = array( new XMLWriter() );
1111
$x[0]->openUri("bug79029_1.txt");
1212
$x[0]->startComment();
1313

14-
$x = new XMLWriter();
15-
$x->openUri("bug79029_2.txt");
14+
$y = new XMLWriter();
15+
$y->openUri("bug79029_2.txt");
1616
fclose(@end(get_resources()));
1717

1818
file_put_contents("bug79029_3.txt", "a");
19-
$x = new XMLReader();
20-
$x->open("bug79029_3.txt");
19+
$z = new XMLReader();
20+
$z->open("bug79029_3.txt");
2121
fclose(@end(get_resources()));
2222
?>
2323
okey

0 commit comments

Comments
 (0)