reflection
reflection copied to clipboard
Missing error check after regex
An error check is missing after doing a preg_match() here. The code just ignores any errors, such as exceeding pcre.backtrack_limit
. This is also true for the current master branch.
Found the missing error check when getting this Drupal error.
Something like this should be added after. Stolen from the Symfony YAML parser.
if (preg_match("/\A.*^\s*((abstract|final)\s+)?class\s+{$this->shortClassName}\s+/sm", $contents, $matches)) {
$contents = $matches[0];
}
switch (preg_last_error()) {
case PREG_INTERNAL_ERROR:
$error = 'Internal PCRE error.';
break;
case PREG_BACKTRACK_LIMIT_ERROR:
$error = 'pcre.backtrack_limit reached.';
break;
case PREG_RECURSION_LIMIT_ERROR:
$error = 'pcre.recursion_limit reached.';
break;
case PREG_BAD_UTF8_ERROR:
$error = 'Malformed UTF-8 data.';
break;
case PREG_BAD_UTF8_OFFSET_ERROR:
$error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.';
break;
default:
$error = FALSE;
}
if ($error) throw new \Exception("Wow we did it! $error");