Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, $this->mktimeFamilyFunctions) || count($node->args) < 7) {
         return;
     }
     $this->addContextMessage(sprintf('Removed argument $is_dst used for function "%s"', $node->name->__toString()), $node);
 }
 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, $this->removedFunctionNames)) {
         return;
     }
     /** @var Node\Expr\FuncCall $node */
     $this->addContextMessage(sprintf('Removed function "%s" called', $node->name->toString()), $node);
 }
 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     $isCurrentNodeFunctionLike = $node instanceof Node\FunctionLike;
     if ($isCurrentNodeFunctionLike || $this->argumentModificationStack->isEmpty() || !$this->argumentModificationStack->top() || !$this->functionAnalyzer->isFunctionCallByStaticName($node, array_flip(array('func_get_arg', 'func_get_args')))) {
         $isCurrentNodeFunctionLike && $this->argumentModificationStack->push(false);
         return;
     }
     /** @var Node\Expr\FuncCall $node */
     $functionName = $node->name->toString();
     $this->addContextMessage(sprintf('Function argument(s) returned by "%s" might have been modified', $functionName), $node);
 }
 public function enterNode(Node $node)
 {
     if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, self::$setcookieFamilyFunctions)) {
         return;
     }
     /** @var Node\Expr\FuncCall $node */
     $cookieNameArgumentValue = isset($node->args[0]) ? $node->args[0]->value : null;
     $isEmptyString = $cookieNameArgumentValue && $cookieNameArgumentValue instanceof Node\Scalar\String_ && $cookieNameArgumentValue->value === '';
     $isEmptyConstant = $cookieNameArgumentValue && $cookieNameArgumentValue instanceof Node\Expr\ConstFetch && in_array(strtolower($cookieNameArgumentValue->name->toString()), array('null', 'false'), true);
     if ($isEmptyConstant || $isEmptyString) {
         $this->addContextMessage(sprintf('Function "%s" called with an empty cookie name', $node->name->toString()), $node);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, 'preg_replace')) {
         return;
     }
     /** @var Node\Expr\FuncCall $node */
     $regExpPatternArgument = $node->args[0];
     if (!$regExpPatternArgument->value instanceof Node\Scalar\String_) {
         return;
     }
     $regExp = $this->regExpParser->parse($regExpPatternArgument->value->value);
     if ($regExp->hasModifier(static::PREG_REPLACE_EVAL_MODIFIER)) {
         $this->addContextMessage(sprintf('Removed regular expression modifier "%s" used', static::PREG_REPLACE_EVAL_MODIFIER), $node);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, array('password_hash' => true)) || !isset($node->args[static::PASSWORD_HASH_OPTIONS_ARGUMENT_INDEX]) || !$node->args[static::PASSWORD_HASH_OPTIONS_ARGUMENT_INDEX]->value instanceof Node\Expr\Array_) {
         return;
     }
     /** @var Node\Expr\Array_ $passwordHashOptions */
     $passwordHashOptions = $node->args[static::PASSWORD_HASH_OPTIONS_ARGUMENT_INDEX]->value;
     /** @var $node Node\Expr\FuncCall */
     foreach ($passwordHashOptions->items as $option) {
         if ($option->key instanceof Node\Scalar\String_ && $option->key->value === 'salt') {
             $this->addContextMessage('Deprecated option "salt" passed to password_hash function', $node);
             break;
         }
     }
 }
Exemple #7
0
 /**
  * @param Node      $node
  * @param array     $functions
  * @param null|bool $skippedByRefType Reference type (by value/by reference) to skip
  *
  * @return bool
  */
 protected function hasFunctionCallWithForeachArgument(Node $node, array $functions, $skippedByRefType = null)
 {
     if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, $functions)) {
         return false;
     }
     /** @var Node\Expr\FuncCall $node */
     foreach ($node->args as $argument) {
         /** @var Node\Stmt\Foreach_ $foreach */
         foreach ($this->foreachStack as $foreach) {
             if ($skippedByRefType !== null && $foreach->byRef === $skippedByRefType) {
                 continue;
             }
             if ($argument->value instanceof Node\Expr\Variable && $argument->value->name === $this->getForeachVariableName($foreach)) {
                 return true;
             }
         }
     }
     return false;
 }
 public function enterNode(Node $node)
 {
     $checkedName = '';
     $usagePatternName = null;
     if ($node instanceof Node\Stmt\ClassLike) {
         $checkedName = $node->name;
         $usagePatternName = 'as a class, interface or trait name';
     } elseif ($this->functionAnalyzer->isFunctionCallByStaticName($node, 'class_alias')) {
         /** @var Node\Expr\FuncCall $node */
         $secondArgument = isset($node->args[1]) ? $node->args[1] : null;
         if (!$secondArgument || !$secondArgument->value instanceof Node\Scalar\String_) {
             return;
         }
         $checkedName = $secondArgument->value->value;
         $usagePatternName = 'as a class alias';
     } elseif ($node instanceof Node\Stmt\UseUse) {
         $checkedName = $node->alias;
         $usagePatternName = 'as a use statement alias';
     }
     $checkedName = strtolower($checkedName);
     if ($checkedName && isset($this->reservedNamesToMessagesMap[$checkedName])) {
         $this->addContextMessage(sprintf($this->reservedNamesToMessagesMap[$checkedName], $checkedName, $usagePatternName), $node);
     }
 }
 public function enterNode(Node $node)
 {
     if ($this->functionAnalyzer->isFunctionCallByStaticName($node, array('session_set_save_handler' => true))) {
         $this->addContextMessage('Check that callbacks that are passed to "session_set_save_handler" ' . 'and return false or -1 (if any) operate correctly', $node);
     }
 }
 /**
  * @dataProvider isFunctionCallByStaticNameChecksFunctionNameCorrectlyProvider
  */
 public function testIsFunctionCallByStaticNameChecksFunctionNameCorrectly($node, $checkedFunctionNames, $result)
 {
     $this->assertSame($this->functionAnalyzer->isFunctionCallByStaticName($node, $checkedFunctionNames), $result);
 }