如何为 find sec bug 插件编写自定义检测器?如果有人编写一个样本检测器来检测单词的使用,那将会很有帮助。提前致谢
问问题
431 次
1 回答
2
下面是检测 system.out.printl 的示例代码,但它显示了许多误报错误
package com.h3xstream.findsecbugs;
import org.apache.bcel.Constants;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.Priorities;
import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.FieldDescriptor;
public class CallToSystemOutPrintlnDetector2 extends OpcodeStackDetector {
private BugReporter bugReporter;
public CallToSystemOutPrintlnDetector2(BugReporter bugReporter) {
super();
this.bugReporter = bugReporter;
}
public void sawOpcode(int seen) {
if (seen == Constants.GETSTATIC) {
try {
FieldDescriptor operand = getFieldDescriptorOperand();
ClassDescriptor classDescriptor = operand.getClassDescriptor();
if ("java/lang/System".equals(classDescriptor.getClassName())
&& ("err".equals(operand.getName()) || "out"
.equals(operand.getName()))) {
bugReporter
.reportBug(new BugInstance(this,
"MY_CALL_TO_SYSTEM_OUT_BUG",
Priorities.NORMAL_PRIORITY)
//
.addClass(this).addMethod(this)
.addSourceLine(this));
}
} catch (Exception e) {
// ignore
}
}
}
}
于 2016-06-24T09:30:14.897 回答