Skip to content

Commit

Permalink
Skips while and fclose to ensure rest of code runs.
Browse files Browse the repository at this point in the history
If a plugin/theme changes AtomParser::FILE to an invalid or unavailable
resource, fopen will return `false`.

- PHP 8: `fread` throws a fatal error as its 1st param requires
  a resource type.
- <PHP 8: `fread` and `fclose` throw a warning, but code continues
  to run.

This commit:

- wraps the entire `while` block and `fclose` to prevent the PHP 8
  fatal error.
- allows the remaining code to run to ensure the parser is freed
  and error handler restored.
  • Loading branch information
hellofromtonya committed Nov 22, 2020
1 parent 3e538e3 commit ba0ef76
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/wp-includes/atomlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,22 @@ function parse() {
$ret = true;

$fp = fopen($this->FILE, "r");
if (false === $fp) {
return false;
}

while ($data = fread($fp, 4096)) {
if($this->debug) $this->content .= $data;

if(!xml_parse($parser, $data, feof($fp))) {
/* translators: 1: Error message, 2: Line number. */
trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
$ret = false;
break;
}
if (false === $fp) {

while ($data = fread($fp, 4096)) {
if($this->debug) $this->content .= $data;

if(!xml_parse($parser, $data, feof($fp))) {
/* translators: 1: Error message, 2: Line number. */
trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
$ret = false;
break;
}
}
fclose($fp);
}
fclose($fp);

xml_parser_free($parser);
unset($parser);
Expand Down

0 comments on commit ba0ef76

Please sign in to comment.