Skip to content

Commit e246dea

Browse files
committed
Fix #78025: segfault when accessing properties of DOMDocumentType
Instead of following the NULL pointer, we return an empty string.
1 parent 35353dc commit e246dea

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #76980 (Interface gets skipped if autoloader throws an exception).
77
(Nikita)
88

9+
- DOM:
10+
. Fixed bug #78025 (segfault when accessing properties of DOMDocumentType).
11+
(cmb)
12+
913
30 May 2019, PHP 7.2.19
1014

1115
- FPM:

ext/dom/documenttype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int dom_documenttype_name_read(dom_object *obj, zval *retval)
5252
return FAILURE;
5353
}
5454

55-
ZVAL_STRING(retval, (char *) (dtdptr->name));
55+
ZVAL_STRING(retval, dtdptr->name ? (char *) (dtdptr->name) : "");
5656

5757
return SUCCESS;
5858
}

ext/dom/tests/bug78025.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #78025 (segfault when accessing properties of DOMDocumentType)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('dom')) die('skip dom extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$htm = "<!DOCTYPE><html></html>";
10+
$dom = new DOMDocument;
11+
$dom->loadHTML($htm);
12+
var_dump($dom->doctype->name);
13+
?>
14+
===DONE===
15+
--EXPECTF--
16+
Warning: DOMDocument::loadHTML(): htmlParseDocTypeDecl : no DOCTYPE name ! in Entity, line: 1 in %s on line %d
17+
string(0) ""
18+
===DONE===

0 commit comments

Comments
 (0)