@Nullable private static ExpressionTree retrieveArgumentFromIsNullCall(FunctionCallTree functionCall) { if ("is_null".equalsIgnoreCase(functionCall.callee().toString()) && functionCall.arguments().size() == 1) { return functionCall.arguments().get(0); } else { return null; } }
private static boolean isSuspiciousGlobalConfiguration(String lowerCaseQualifiedName, SeparatedList<ExpressionTree> arguments) { return GLOBAL_CONFIGURATION_FUNCTIONS.contains(lowerCaseQualifiedName) && arguments.size() == 2 && isSuspiciousDirective(getStringValue(arguments.get(0)), arguments.get(1)); }
private boolean matches(FunctionCallTree function) { int argumentCount = function.arguments().size(); boolean pathMatches = pathIndexes.length == 0 || hasFileSystemPath(function.arguments()); return minCount <= argumentCount && argumentCount <= maxCount && pathMatches; }
private void checkParseStrArguments(FunctionCallTree tree) { if (tree.arguments().size() < 2) { context().newIssue(this, tree, "Add a second argument to this call to \"parse_str\"."); } }
private void checkParseStrArguments(FunctionCallTree tree) { if (tree.arguments().size() < 2) { context().newIssue(this, tree, "Add a second argument to this call to \"parse_str\"."); } }
@Override public void visitClassPropertyDeclaration(ClassPropertyDeclarationTree tree) { super.visitClassPropertyDeclaration(tree); int declarationsNumber = tree.declarations().size(); if (declarationsNumber > 1) { String message = String.format(MESSAGE, declarationsNumber); context().newIssue(this, tree, message); } }
@Override public void visitParameterList(ParameterListTree parameterList) { int numberOfParameters = parameterList.parameters().size(); int maxValue = isConstructorParameterList(parameterList) ? constructorMax : max; if (numberOfParameters > maxValue) { context().newIssue(this, parameterList, String.format(MESSAGE, numberOfParameters, maxValue)); } super.visitParameterList(parameterList); }
private static boolean httpOnlySetToFalse(FunctionCallTree tree) { if (tree.arguments().size() > HTTP_ONLY_PARAMETER_INDEX) { ExpressionTree httpOnlyArgument = tree.arguments().get(HTTP_ONLY_PARAMETER_INDEX); return httpOnlyArgument.is(Kind.BOOLEAN_LITERAL) && ((LiteralTree) httpOnlyArgument).value().equals("false"); } return false; } }
private static boolean httpOnlySetToFalse(FunctionCallTree tree) { if (tree.arguments().size() > HTTP_ONLY_PARAMETER_INDEX) { ExpressionTree httpOnlyArgument = tree.arguments().get(HTTP_ONLY_PARAMETER_INDEX); return httpOnlyArgument.is(Kind.BOOLEAN_LITERAL) && ((LiteralTree) httpOnlyArgument).value().equals("false"); } return false; } }
@Nullable public static ExpressionTree getForCondition(ForStatementTree tree) { if (tree.condition().isEmpty()) { return null; } // in a loop, all conditions are evaluated but only the last one is used as the result return tree.condition().get(tree.condition().size() - 1); }
private static boolean isVariableLengthParameterList(ParameterListTree parameterList) { SeparatedList<ParameterTree> parameters = parameterList.parameters(); if (!parameters.isEmpty()) { ParameterTree lastParameter = parameters.get(parameters.size() - 1); return lastParameter.ellipsisToken() != null; } return false; }
private static boolean argumentSetToFalse(FunctionCallTree tree, int argumentIndex) { if (tree.arguments().size() > argumentIndex) { ExpressionTree secureArgument = tree.arguments().get(argumentIndex); return CheckUtils.isFalseValue(secureArgument); } return true; }
private static boolean hasCookieValue(FunctionCallTree tree) { return tree.arguments().size() > VALUE_PARAMETER_INDEX && !CheckUtils.isNullOrEmptyString(tree.arguments().get(VALUE_PARAMETER_INDEX)); }
private static boolean argumentSetToFalse(FunctionCallTree tree, int argumentIndex) { if (tree.arguments().size() > argumentIndex) { ExpressionTree secureArgument = tree.arguments().get(argumentIndex); return CheckUtils.isFalseValue(secureArgument); } return true; }
private void checkPasswordArgument(FunctionCallTree functionCall, int argumentIndex) { SeparatedList<ExpressionTree> arguments = functionCall.arguments(); if (arguments.size() > argumentIndex) { ExpressionTree passwordArgument = arguments.get(argumentIndex); if (hasEmptyValue(passwordArgument)) { context().newIssue(this, passwordArgument, MESSAGE); } } }
private boolean argumentIsNullOrEmptyString(FunctionCallTree tree, int argumentIndex) { if (tree.arguments().size() > argumentIndex) { ExpressionTree valueArgument = getAssignedValue(tree.arguments().get(argumentIndex)); return CheckUtils.isNullOrEmptyString(valueArgument); } return true; }
private boolean argumentIsNullOrEmptyString(FunctionCallTree tree, int argumentIndex) { if (tree.arguments().size() > argumentIndex) { ExpressionTree valueArgument = getAssignedValue(tree.arguments().get(argumentIndex)); return CheckUtils.isNullOrEmptyString(valueArgument); } return true; }
private void checkSqlServer(FunctionCallTree functionCall) { SeparatedList<ExpressionTree> arguments = functionCall.arguments(); int argumentIndex = 1; if (arguments.size() > argumentIndex) { ExpressionTree connectionInfo = arguments.get(argumentIndex); ExpressionTree password = sqlServerPassword(connectionInfo); if (password != null && hasEmptyValue(password)) { context().newIssue(this, password, MESSAGE); } } }
@Override protected void createIssue(FunctionCallTree tree) { if (tree.arguments().size() > PADDING_ARGUMENT_INDEX) { ExpressionTree padding = tree.arguments().get(PADDING_ARGUMENT_INDEX); if (padding.is(Kind.NAMESPACE_NAME) && !((NamespaceNameTree) padding).fullName().equals(SECURE_PADDING)) { context().newIssue(this, padding, MESSAGE); } } else { context().newIssue(this, tree.callee(), MESSAGE); } }
@Override protected void createIssue(FunctionCallTree tree) { if (tree.arguments().size() > PADDING_ARGUMENT_INDEX) { ExpressionTree padding = tree.arguments().get(PADDING_ARGUMENT_INDEX); if (padding.is(Kind.NAMESPACE_NAME) && !((NamespaceNameTree) padding).fullName().equals(SECURE_PADDING)) { context().newIssue(this, padding, MESSAGE); } } else { context().newIssue(this, tree.callee(), MESSAGE); } }