Пример #1
0
 /**
  * @return bool|wfWAFLexerToken
  * @throws wfWAFParserSyntaxError
  */
 public function nextToken()
 {
     if (!$this->scanner->eos()) {
         /** @var wfWAFLexerTokenMatcher $tokenMatcher */
         foreach ($this->tokenMatchers as $tokenMatcher) {
             $this->scanner->skip('/^\\s+/s');
             if ($this->scanner->eos()) {
                 return false;
             }
             if (($this->flags & self::FLAG_TOKENIZE_MYSQL_PORTABLE_COMMENTS) === 0 && ($tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_START || $tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_END)) {
                 continue;
             }
             if (!$this->hasPortableCommentStart && $tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_END) {
                 continue;
             }
             if ($tokenMatcher->useMaximalMunch() && ($match = $this->scanner->check($tokenMatcher->getMatch())) !== null) {
                 $biggestToken = $this->createToken($tokenMatcher->getTokenID(), $match);
                 /** @var wfWAFLexerTokenMatcher $tokenMatcher2 */
                 foreach ($this->tokenMatchers as $tokenMatcher2) {
                     if ($tokenMatcher === $tokenMatcher2) {
                         continue;
                     }
                     if (($match2 = $this->scanner->check($tokenMatcher2->getMatch())) !== null) {
                         $biggestToken2 = $this->createToken($tokenMatcher2->getTokenID(), $match2);
                         if (wfWAFUtils::strlen($biggestToken2->getValue()) > wfWAFUtils::strlen($biggestToken->getValue())) {
                             $biggestToken = $biggestToken2;
                         }
                     }
                 }
                 $this->scanner->advancePointer(wfWAFUtils::strlen($biggestToken->getValue()));
                 return $biggestToken;
             } else {
                 if (($match = $this->scanner->scan($tokenMatcher->getMatch())) !== null) {
                     $token = $this->createToken($tokenMatcher->getTokenID(), $match);
                     if ($tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_START) {
                         $this->hasPortableCommentStart = true;
                     } else {
                         if ($tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_END) {
                             $this->hasPortableCommentStart = false;
                         }
                     }
                     return $token;
                 }
             }
         }
         $char = $this->scanner->scanChar();
         $e = new wfWAFParserSyntaxError(sprintf('Invalid character "%s" (\\x%02x) found on line %d, column %d', $char, ord($char), $this->scanner->getLine(), $this->scanner->getColumn()));
         $e->setParseLine($this->scanner->getLine());
         $e->setParseColumn($this->scanner->getColumn());
         throw $e;
     }
     return false;
 }
Пример #2
0
 /**
  * @param wfWAFLexerToken $token
  * @param string $message
  * @throws wfWAFParserSyntaxError
  */
 protected function triggerSyntaxError($token, $message = 'Wordfence WAF Syntax Error: Unexpected %s %s found on line %d, column %d')
 {
     $e = new wfWAFParserSyntaxError(sprintf($message, $token->getType(), $token->getValue(), $token->getLine(), $token->getColumn()));
     $e->setToken($token);
     $e->setParseLine($token->getLine());
     $e->setParseColumn($token->getColumn());
     throw $e;
 }