From 76d66203f4a83d8796fe07dd4fc5f3d2199baf7f Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Fri, 31 Oct 2003 01:17:47 +0000 Subject: [PATCH] add some error control to analyzeSourceCode() for really rare cases - invalid PHP --- pear/PEAR/Common.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php index 478ca11c16..920cbd0167 100644 --- a/pear/PEAR/Common.php +++ b/pear/PEAR/Common.php @@ -26,6 +26,10 @@ require_once 'PEAR/Config.php'; // {{{ constants and globals +/** + * PEAR_Common error when an invalid PHP file is passed to PEAR_Common::analyzeSourceCode() + */ +define('PEAR_COMMON_ERROR_INVALIDPHP', 1); define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+'); define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/'); @@ -1319,6 +1323,11 @@ class PEAR_Common extends PEAR case '(': $paren_level++; continue 2; case ')': $paren_level--; continue 2; case T_CLASS: + if (($current_class_level != -1) || ($current_function_level != -1)) { + PEAR::raiseError("Parser error: Invalid PHP file $file", + PEAR_COMMON_ERROR_INVALIDPHP); + return false; + } case T_FUNCTION: case T_NEW: case T_EXTENDS: @@ -1358,6 +1367,11 @@ class PEAR_Common extends PEAR } continue 2; case T_DOUBLE_COLON: + if ($tokens[$i - 1][0] != T_STRING) { + PEAR::raiseError("Parser error: Invalid PHP file $file", + PEAR_COMMON_ERROR_INVALIDPHP); + return false; + } $class = $tokens[$i - 1][1]; if (strtolower($class) != 'parent') { $used_classes[$class] = true; -- 2.50.1