Skip to content

Commit

Permalink
Catch potential NULL return value from preg_replace_callback
Browse files Browse the repository at this point in the history
For reference: issue #356
  • Loading branch information
theseer committed Mar 19, 2019
1 parent 4c04bab commit ab50417
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/collector/backend/SourceFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

class SourceFileException extends \Exception {
public const BadEncoding = 1;

public const InvalidDataBytes = 2;
public const RegexError = 3;
}
9 changes: 8 additions & 1 deletion src/collector/project/SourceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getSource(): string {

$source = \file_get_contents($this->getPathname());

if ($source == '') {
if ($source === '') {
$this->src = '';

return '';
Expand Down Expand Up @@ -71,6 +71,13 @@ function (array $matches) {
$source
);

if ($this->src === null) {
throw new SourceFileException(
sprintf('Error %d while executing regular expression callback', \preg_last_error()),
SourceFileException::RegexError
);
}

return $this->src;
}

Expand Down

2 comments on commit ab50417

@jan-koch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I implement this fix?
I updated the files locally but it seems that phpdox is showing the same issue. Please see #397.

Thanks!

@theseer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed some more changes, try running phpDox from master. Again, the issue in general is not fixed with these changes, just the error handling is enhanced making it more likely for me to find the root cause.

Please sign in to comment.