Skip to content

Commit ab50417

Browse files
committed
Catch potential NULL return value from preg_replace_callback
For reference: issue #356
1 parent 4c04bab commit ab50417

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/collector/backend/SourceFileException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
class SourceFileException extends \Exception {
55
public const BadEncoding = 1;
6-
76
public const InvalidDataBytes = 2;
7+
public const RegexError = 3;
88
}

src/collector/project/SourceFile.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getSource(): string {
4343

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

46-
if ($source == '') {
46+
if ($source === '') {
4747
$this->src = '';
4848

4949
return '';
@@ -71,6 +71,13 @@ function (array $matches) {
7171
$source
7272
);
7373

74+
if ($this->src === null) {
75+
throw new SourceFileException(
76+
sprintf('Error %d while executing regular expression callback', \preg_last_error()),
77+
SourceFileException::RegexError
78+
);
79+
}
80+
7481
return $this->src;
7582
}
7683

0 commit comments

Comments
 (0)