DynSqlSelectStmts.java

Example 6-6 provides the full source code of the DynSqlSelectStmts.java example discussed in this chapter.

Example 6-6. Source code for DynSqlSelectStmts.jav

package net.sourceforge.pmd.rules.web.security; import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.ast.*; import net.sourceforge.pmd.RuleContext; import org.apache.regexp.*; import java.util.*; import java.text.MessageFormat; public class DynSqlSelectStmts extends AbstractRule { private static boolean debug = true; private static final String PATTERN = "select.+from"; private String currMethName; private int currMethXsVis; private Map currMethParams; private String currMethSymptomCode; private List currMethExprsToChase; private List currMethVarsChased; private void init ( ) { currMethName = ""; currMethXsVis = 0; currMethParams = new HashMap( ); currMethSymptomCode = ""; currMethExprsToChase = new ArrayList( ); currMethVarsChased = new LinkedList( ); } public void setDebug (boolean x) { debug = x; } public void printDebug (String str) { if (debug) System.out.print(str + "\n"); } public Object visit(ASTCompilationUnit node, Object data) { getInfo(node); printDebug("Rule: " + this.getName( ) + "\n\n"); return super.visit(node,data); } public Object visit(ASTClassBodyDeclaration node, Object data) { getInfo(node); if (!(node.jjtGetChild(0) instanceof ASTMethodDeclaration)) { return null; } this.init( ); return super.visit(node,data); } public Object visit(ASTMethodDeclaration node, Object ...

Get Network Security Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.