]> granicus.if.org Git - php/commitdiff
add some error control to analyzeSourceCode() for really rare cases - invalid PHP
authorGreg Beaver <cellog@php.net>
Fri, 31 Oct 2003 01:17:47 +0000 (01:17 +0000)
committerGreg Beaver <cellog@php.net>
Fri, 31 Oct 2003 01:17:47 +0000 (01:17 +0000)
pear/PEAR/Common.php

index 478ca11c164c6061354a30420e9e1c20a5bd8eee..920cbd0167620c0ef9cafffb849c9247cfd267d2 100644 (file)
@@ -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;