Skip to content

php 8 compatibility in Zend_Xml_Security class #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
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
19 changes: 13 additions & 6 deletions library/Zend/Xml/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public static function scan($xml, DOMDocument $dom = null)
}

if (!self::isPhpFpm()) {
$loadEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
// this function no longer has an effect in PHP 8.0, but it's required in earlier versions
$loadEntities = libxml_disable_entity_loader(true);
}
$useInternalXmlErrors = libxml_use_internal_errors(true);
}

Expand All @@ -97,7 +100,9 @@ public static function scan($xml, DOMDocument $dom = null)
if (!$result) {
// Entity load to previous setting
if (!self::isPhpFpm()) {
libxml_disable_entity_loader($loadEntities);
if (isset($loadEntities)) {
libxml_disable_entity_loader($loadEntities);
}
libxml_use_internal_errors($useInternalXmlErrors);
}
return false;
Expand All @@ -117,7 +122,9 @@ public static function scan($xml, DOMDocument $dom = null)

// Entity load to previous setting
if (!self::isPhpFpm()) {
libxml_disable_entity_loader($loadEntities);
if (isset($loadEntities)) {
libxml_disable_entity_loader($loadEntities);
}
libxml_use_internal_errors($useInternalXmlErrors);
}

Expand Down Expand Up @@ -167,10 +174,10 @@ public static function scanFile($file, DOMDocument $dom = null)
public static function isPhpFpm()
{
$isVulnerableVersion = (
version_compare(PHP_VERSION, '5.5.22', 'lt')
version_compare(PHP_VERSION, '5.5.22', '<')
|| (
version_compare(PHP_VERSION, '5.6', 'gte')
&& version_compare(PHP_VERSION, '5.6.6', 'lt')
version_compare(PHP_VERSION, '5.6', '>=')
&& version_compare(PHP_VERSION, '5.6.6', '<')
)
);

Expand Down