Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Skips while and fclose to ensure rest of code runs.
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
commit ba0ef76f8d3a5954a42e16ec8b27e34a53ecd0b7
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