新增准则:修改if判断方式

wuhaoyang
RenFengJiang 8 months ago
parent 987b77fea9
commit a2eafc5661
  1. 18
      sonar-keyware-plugins-java/src/main/java/com/keyware/sonar/java/rules/checkers/UploadFileVerifyChecker.java

@ -22,6 +22,8 @@ import java.util.List;
@Rule(key = "UploadFileVerify")
public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor {
private final String value = "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型";
@Override
public List<Tree.Kind> nodesToVisit() {
/**
@ -42,38 +44,38 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor {
//获取文件名称类型判断是否配置文件权限
var interiorInvoIf = new InteriorInvoIf();
((MethodTree) tree).block().accept(interiorInvoIf);
if (interiorInvoIf.fileType != "") {
if (!interiorInvoIf.fileType.equals("")) {
//判断是否对文件后缀进行限制
NodeIf nodeIf = new NodeIf(interiorInvoIf.fileType);
((MethodTree) tree).block().accept(nodeIf);
if (nodeIf.boo) {
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型");
context.reportIssue(this, node.simpleName(), value);
}
} else {
if (interiorInvoIf.fileName != "") {
if (!interiorInvoIf.fileName.equals("")) {
// 判断是否对文件后缀进行限制
NodeIf nodeIf = new NodeIf(interiorInvoIf.fileName);
((MethodTree) tree).block().accept(nodeIf);
if (nodeIf.boo) {
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型");
context.reportIssue(this, node.simpleName(), value);
}
} else {
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型");
context.reportIssue(this, node.simpleName(), value);
}
}
if (interiorInvoIf.sizeName != "") {
if (!interiorInvoIf.sizeName.equals("")) {
//判断是否对文件大小进行限制
NodeIf nodeIf = new NodeIf(interiorInvoIf.sizeName);
//nodeIf.check(((MethodTree) tree).block());
((MethodTree) tree).block().accept(nodeIf);
if (nodeIf.boo) {
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型");
context.reportIssue(this, node.simpleName(), value);
}
}
//判断是否进行权限设置
if (interiorInvoIf.privType) {
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型");
context.reportIssue(this, node.simpleName(), value);
}
}

Loading…
Cancel
Save