File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
java-checks/src/main/java/org/sonar/java/checks/security Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1616 */
1717package org .sonar .java .checks .security ;
1818
19+ import java .util .ArrayList ;
1920import java .util .HashSet ;
21+ import java .util .List ;
2022import java .util .Objects ;
2123import java .util .Set ;
2224import java .util .stream .Stream ;
@@ -72,6 +74,38 @@ public class CipherBlockChainingCheck extends AbstractMethodDetection {
7274 .withAnyParameters ()
7375 .build ();
7476
77+ private @ Nullable Tree outermostClass = null ;
78+
79+ @ Override
80+ public List <Tree .Kind > nodesToVisit () {
81+ var baseNodesToVisit = super .nodesToVisit ();
82+ var nodesToVisit = new ArrayList <Tree .Kind >(baseNodesToVisit .size () + 1 );
83+ nodesToVisit .addAll (baseNodesToVisit );
84+ nodesToVisit .add (Tree .Kind .CLASS );
85+
86+ return nodesToVisit ;
87+ }
88+
89+ @ Override
90+ public void visitNode (Tree tree ) {
91+ if (outermostClass == null && tree .is (Tree .Kind .CLASS )) {
92+ // We only need run SecureByteArrayFactoryFinder once on the outermost class to find all secure IV byte array factory methods.
93+ // If we apply the finder again to nested classes then we explore the same sub-trees multiple times.
94+ outermostClass = tree ;
95+ tree .accept (secureByteArrayFactoryFinder );
96+ }
97+
98+ super .visitNode (tree );
99+ }
100+
101+ @ Override
102+ public void leaveNode (Tree tree ) {
103+ if (tree == outermostClass ) {
104+ secureByteArrayFactoryFinder .clear ();
105+ }
106+ super .leaveNode (tree );
107+ }
108+
75109 @ Override
76110 protected MethodMatchers getMethodInvocationMatchers () {
77111 return MethodMatchers .create ().ofTypes ("javax.crypto.spec.IvParameterSpec" ).constructor ()
You can’t perform that action at this time.
0 commit comments