From 2e9b3c22d8692d7c02826d60f119836c9e7339e6 Mon Sep 17 00:00:00 2001 From: pento Date: Mon, 24 Oct 2016 04:44:07 +0000 Subject: [PATCH] General: Check to see that the PHP-XML module is enabled before using XML functions. There are a handful of places where we don't check that the XML functions exist before we use them. Ubuntu's PHP 7 packages don't include PHP-XML by default, increasing the chance of this causing issues. Props kraftbj, markoheijnen. Fixes #37122. git-svn-id: https://develop.svn.wordpress.org/trunk@38883 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/link-parse-opml.php | 5 +++++ src/wp-includes/IXR/class-IXR-message.php | 5 +++++ src/wp-includes/atomlib.php | 5 +++++ src/wp-includes/feed.php | 6 ++++++ src/wp-includes/rss.php | 12 +++++------- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/link-parse-opml.php b/src/wp-admin/link-parse-opml.php index 1d051b5237..42bf52cefc 100644 --- a/src/wp-admin/link-parse-opml.php +++ b/src/wp-admin/link-parse-opml.php @@ -72,6 +72,11 @@ function endElement($parser, $tagName) { } // Create an XML parser +if ( ! function_exists( 'xml_parser_create' ) ) { + trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); + wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); +} + $xml_parser = xml_parser_create(); // Set the functions to handle opening and closing tags diff --git a/src/wp-includes/IXR/class-IXR-message.php b/src/wp-includes/IXR/class-IXR-message.php index d222fc83b6..613e972c65 100644 --- a/src/wp-includes/IXR/class-IXR-message.php +++ b/src/wp-includes/IXR/class-IXR-message.php @@ -44,6 +44,11 @@ class IXR_Message function parse() { + if ( ! function_exists( 'xml_parser_create' ) ) { + trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML" ) ); + return false; + } + // first remove the XML declaration // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); diff --git a/src/wp-includes/atomlib.php b/src/wp-includes/atomlib.php index 368015adb1..f2cba56361 100644 --- a/src/wp-includes/atomlib.php +++ b/src/wp-includes/atomlib.php @@ -121,6 +121,11 @@ class AtomParser { array_unshift($this->ns_contexts, array()); + if ( ! function_exists( 'xml_parser_create_ns' ) ) { + trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); + return false; + } + $parser = xml_parser_create_ns(); xml_set_object($parser, $this); xml_set_element_handler($parser, "start_element", "end_element"); diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index d4e6b1911b..e6686c040e 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -538,6 +538,12 @@ function prep_atom_text_construct($data) { return array('text', $data); } + if ( ! function_exists( 'xml_parser_create' ) ) { + trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); + + return array( 'html', "" ); + } + $parser = xml_parser_create(); xml_parse($parser, '
' . $data . '
', true); $code = xml_get_error_code($parser); diff --git a/src/wp-includes/rss.php b/src/wp-includes/rss.php index 4c3fb15160..99c8fe8649 100644 --- a/src/wp-includes/rss.php +++ b/src/wp-includes/rss.php @@ -60,15 +60,13 @@ class MagpieRSS { */ function __construct( $source ) { - # if PHP xml isn't compiled in, die + # Check if PHP xml isn't compiled # - if ( !function_exists('xml_parser_create') ) - trigger_error( "Failed to load PHP's XML Extension. https://secure.php.net/manual/en/ref.xml.php" ); + if ( ! function_exists('xml_parser_create') ) { + return trigger_error( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ); + } - $parser = @xml_parser_create(); - - if ( !is_resource($parser) ) - trigger_error( "Failed to create an instance of PHP's XML parser. https://secure.php.net/manual/en/ref.xml.php"); + $parser = xml_parser_create(); $this->parser = $parser;