Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7124c53
Adjust bc_num to number without trailing zeros
jorgsowa Jul 6, 2023
0653132
Improve tests for bcpow with zero
jorgsowa Jul 7, 2023
ec994a3
Fixed tests for 32bits systems
jorgsowa Jul 8, 2023
f55eab1
Fixed test case for maximum exponent for int to lower than max
jorgsowa Jul 8, 2023
d63ba2f
Fix bcmath tests for number zero
jorgsowa Jul 8, 2023
d812639
Remove unused ZEND_STACK_GROWS_DOWNWARDS constant (#11762)
petk Jul 22, 2023
8fbbfd6
zend call stack fix freebsd code path. (#11766)
devnexen Jul 23, 2023
5d6d66b
zend vm savee registers support for riscv 64. (#11773)
devnexen Jul 24, 2023
c6202fc
Fixed incorrect QM_ASSIGN elimination
dstogov Jul 24, 2023
f8f3280
Use xmlSetNsProp when possible to prevent parsing the name
nielsdos Jul 22, 2023
1bd964c
Remove useless readonly checks
nielsdos Jul 22, 2023
a808b32
Simplify configuration getters (#11778)
nielsdos Jul 24, 2023
39d7258
Refactor BCMath bundledlib and extension (#10774)
Girgias Jul 24, 2023
acf1bf7
[skip ci] Add myself to CODEOWNER for BCMath extension
Girgias Jul 24, 2023
ac1fc0e
Fix DOMEntity field getter bugs
nielsdos Jul 23, 2023
6da01ce
Fix incorrect attribute existence check in DOMElement::setAttributeNo…
nielsdos Jul 23, 2023
058cfa5
Fix DOMCharacterData::replaceWith() with itself
nielsdos Jul 22, 2023
05b4555
Fix empty argument cases for DOMParentNode methods
nielsdos Jul 22, 2023
095be3e
[skip ci] Don't render zend_vm_handlers.h in PRs
iluuu1994 Jul 25, 2023
96b77f6
Fix open_basedir leak
iluuu1994 Jul 24, 2023
716f6b4
Call cast_object handler from get_properties_for
iluuu1994 Jun 30, 2023
2372bf2
CS
derickr Jul 19, 2023
7ecb398
Make the new DatePeriod::createFromISO8601String method emit DateTime…
derickr Jul 19, 2023
00163a3
Adjust bc_num to number without trailing zeros
jorgsowa Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix DOMEntity field getter bugs
- publicId could crash PHP if none was provided
- notationName never worked

The fields of this classs were untested. This new test file changes that.

Closes GH-11779.
  • Loading branch information
nielsdos authored and jorgsowa committed Jul 26, 2023
commit ac1fc0e042dede732368e39fab7603f4fdf63e09
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.3.0beta2

- DOM:
. Fix DOMEntity field getter bugs. (nielsdos)

- FFI:
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)

Expand Down
20 changes: 11 additions & 9 deletions ext/dom/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
/*
* class DOMEntity extends DOMNode
*
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-527DCFF2
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-527DCFF2
* Since:
*/

/* {{{ publicId string
readonly=yes
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-D7303025
URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7303025
Since:
*/
int dom_entity_public_id_read(dom_object *obj, zval *retval)
Expand All @@ -45,7 +45,7 @@ int dom_entity_public_id_read(dom_object *obj, zval *retval)
return FAILURE;
}

if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY || !nodep->ExternalID) {
ZVAL_NULL(retval);
} else {
ZVAL_STRING(retval, (char *) (nodep->ExternalID));
Expand All @@ -58,7 +58,7 @@ int dom_entity_public_id_read(dom_object *obj, zval *retval)

/* {{{ systemId string
readonly=yes
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-D7C29F3E
URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7C29F3E
Since:
*/
int dom_entity_system_id_read(dom_object *obj, zval *retval)
Expand All @@ -83,13 +83,12 @@ int dom_entity_system_id_read(dom_object *obj, zval *retval)

/* {{{ notationName string
readonly=yes
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-6ABAEB38
URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6ABAEB38
Since:
*/
int dom_entity_notation_name_read(dom_object *obj, zval *retval)
{
xmlEntity *nodep = (xmlEntity *) dom_object_get_node(obj);
char *content;

if (nodep == NULL) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
Expand All @@ -99,9 +98,12 @@ int dom_entity_notation_name_read(dom_object *obj, zval *retval)
if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
ZVAL_NULL(retval);
} else {
content = (char *) xmlNodeGetContent((xmlNodePtr) nodep);
ZVAL_STRING(retval, content);
xmlFree(content);
/* According to spec, NULL is only allowed for unparsed entities, if it's not set we should use the empty string. */
if (!nodep->content) {
ZVAL_EMPTY_STRING(retval);
} else {
ZVAL_STRING(retval, (const char *) nodep->content);
}
}

return SUCCESS;
Expand Down
100 changes: 100 additions & 0 deletions ext/dom/tests/DOMEntity_fields.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
--TEST--
DOMEntity fields
--EXTENSIONS--
dom
--FILE--
<?php
$xmlString = <<<XML
<?xml version="1.0"?>
<!DOCTYPE test [
<!ENTITY sampleInternalEntity "This is a sample entity value.">
<!ENTITY sampleExternalSystemWithNotationName SYSTEM "external.stuff" NDATA stuff>
<!ENTITY sampleExternalSystemWithoutNotationName SYSTEM "external.stuff" NDATA >
<!ENTITY sampleExternalPublicWithNotationName1 PUBLIC "public id" "external.stuff" NDATA stuff>
<!ENTITY sampleExternalPublicWithNotationName2 PUBLIC "" "external.stuff" NDATA stuff>
<!ENTITY sampleExternalPublicWithoutNotationName1 PUBLIC "public id" "external.stuff" NDATA >
<!ENTITY sampleExternalPublicWithoutNotationName2 PUBLIC "" "external.stuff" NDATA >
]>
<root/>
XML;

$dom = new DOMDocument();
$dom->loadXML($xmlString);

// Sort them, the iteration order isn't defined
$entities = iterator_to_array($dom->doctype->entities);
ksort($entities);

foreach ($entities as $entity) {
echo "Entity name: {$entity->nodeName}\n";
echo "publicId: ";
var_dump($entity->publicId);
echo "systemId: ";
var_dump($entity->systemId);
echo "notationName: ";
var_dump($entity->notationName);
echo "actualEncoding: ";
var_dump($entity->actualEncoding);
echo "encoding: ";
var_dump($entity->encoding);
echo "version: ";
var_dump($entity->version);
echo "\n";
}
?>
--EXPECT--
Entity name: sampleExternalPublicWithNotationName1
publicId: string(9) "public id"
systemId: string(14) "external.stuff"
notationName: string(5) "stuff"
actualEncoding: NULL
encoding: NULL
version: NULL

Entity name: sampleExternalPublicWithNotationName2
publicId: string(0) ""
systemId: string(14) "external.stuff"
notationName: string(5) "stuff"
actualEncoding: NULL
encoding: NULL
version: NULL

Entity name: sampleExternalPublicWithoutNotationName1
publicId: string(9) "public id"
systemId: string(14) "external.stuff"
notationName: string(0) ""
actualEncoding: NULL
encoding: NULL
version: NULL

Entity name: sampleExternalPublicWithoutNotationName2
publicId: string(0) ""
systemId: string(14) "external.stuff"
notationName: string(0) ""
actualEncoding: NULL
encoding: NULL
version: NULL

Entity name: sampleExternalSystemWithNotationName
publicId: NULL
systemId: string(14) "external.stuff"
notationName: string(5) "stuff"
actualEncoding: NULL
encoding: NULL
version: NULL

Entity name: sampleExternalSystemWithoutNotationName
publicId: NULL
systemId: string(14) "external.stuff"
notationName: string(0) ""
actualEncoding: NULL
encoding: NULL
version: NULL

Entity name: sampleInternalEntity
publicId: NULL
systemId: NULL
notationName: NULL
actualEncoding: NULL
encoding: NULL
version: NULL