Skip to content

Commit

Permalink
Merge pull request #1269 from Bertk/fix-security
Browse files Browse the repository at this point in the history
fix quality flaws
  • Loading branch information
guwirth authored Oct 28, 2017
2 parents c38a27b + d8f25fd commit ed22f82
Show file tree
Hide file tree
Showing 16 changed files with 427 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ public void visitNode(AstNode node) {
}

private static boolean hasBooleanLiteralOperand(AstNode node) {
return node.select()
.children(CxxGrammarImpl.LITERAL)
.children(CxxGrammarImpl.BOOL)
.descendants(CxxKeyword.TRUE, CxxKeyword.FALSE)
.isNotEmpty();
return node.hasDirectChildren(CxxGrammarImpl.LITERAL,CxxGrammarImpl.BOOL)
&& node.hasDescendant(CxxKeyword.TRUE, CxxKeyword.FALSE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonar.cxx.checks;

import java.util.List;

import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
Expand Down Expand Up @@ -51,18 +53,21 @@ public class TooManyParametersCheck extends SquidCheck<Grammar> {

@Override
public void init() {
subscribeTo(CxxGrammarImpl.parameterDeclarationClause, CxxGrammarImpl.lambdaDeclarator, CxxGrammarImpl.cliParameterArray);
subscribeTo(CxxGrammarImpl.parameterDeclarationClause,
CxxGrammarImpl.lambdaDeclarator,
CxxGrammarImpl.cliParameterArray);
}

@Override
public void visitNode(AstNode node) {
int nbParameters = node.select()
.children(CxxGrammarImpl.parameterDeclarationList)
.children(CxxGrammarImpl.parameterDeclaration)
.size();
if (nbParameters > max) {
String message = "parameter list has {0} parameters, which is greater than the {1} authorized.";
getContext().createLineViolation(this, message, node, nbParameters, max);
int nbParameters = 0;
AstNode parameterList = node.getFirstChild(CxxGrammarImpl.parameterDeclarationList);
if (parameterList != null) {
nbParameters = parameterList.getChildren(CxxGrammarImpl.parameterDeclaration).size();
if (nbParameters > max) {
String message = "parameter list has {0} parameters, which is greater than the {1} authorized.";
getContext().createLineViolation(this, message, node, nbParameters, max);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,16 @@
@SqaleConstantRemediation("5min")
public class UseCorrectIncludeCheck extends SquidCheck<Grammar> implements CxxCharsetAwareVisitor {

public static final String regularExpression = "#include\\s+(?>\"|\\<)[\\\\/\\.]+";
public static final String message = "Use correct #include directives";
private static final String REGULAR_EXPRESSION = "#include\\s+(?>\"|\\<)[\\\\/\\.]+";
private Pattern pattern = null;
private Charset charset = Charset.forName("UTF-8");

@Override
public void init() {
if (null != regularExpression && !regularExpression.isEmpty()) {
try {
pattern = Pattern.compile(regularExpression, Pattern.DOTALL);
} catch (RuntimeException e) {
throw new IllegalStateException("Unable to compile regular expression: " + regularExpression, e);
}
try {
pattern = Pattern.compile(REGULAR_EXPRESSION, Pattern.DOTALL);
} catch (RuntimeException e) {
throw new IllegalStateException("Unable to compile regular expression: " + REGULAR_EXPRESSION, e);
}
}

Expand Down
27 changes: 24 additions & 3 deletions cxx-lint/src/main/java/org/sonar/cxx/cxxlint/CheckerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@
* @author jocs
*/
public class CheckerData {
public String id = "";
public String templateId = "";
public boolean enabled = true;
private String id = "";
private String templateId = "";
private boolean enabled = true;
public HashMap<String, String> parameterData = new HashMap<String, String>();

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}

public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}

public boolean isEnabled() {
return enabled;
}
public void setEnable(boolean active) {
this.enabled = active;
}
}

Loading

0 comments on commit ed22f82

Please sign in to comment.