33import it.unipr.analysis.Number;
44import it.unipr.analysis.StackElement;
55import it.unipr.analysis.contract.Signature;
6- import it.unipr.analysis.taint.TaintElement;
76import it.unive.lisa.program.cfg.statement.Statement;
87import java.util.Collections;
98import java.util.HashSet;
@@ -29,13 +28,12 @@ public class MyCache {
2928
3029 private final LRUMap<String, Set<Object>> _warningsCache;
3130
32- private final LRUMap <Statement, TaintElement > _vulnerableLogStatement;
31+ private final Set <Statement> _vulnerableLogStatement;
3332
3433 private final Set<Statement> _taintedCallDataLoad;
3534
3635 private final LRUMap<Statement, Set<Object>> _linkFromLogToCallDataLoad;
3736
38- private final LRUMap<Integer, Set<Object>> _vulnerabilityPerFunction;
3937 private final LRUMap<Signature, Set<Signature>> _mapEventsFunctions;
4038
4139 /**
@@ -71,15 +69,14 @@ private MyCache() {
7169 this._timeLostToGetStorage = new LRUMap<String, Long>(500);
7270 this._reachableFrom = new LRUMap<String, Boolean>(5000);
7371
74- this._warningsCache = new LRUMap<String, Set<Object>>(15000 );
72+ this._warningsCache = new LRUMap<String, Set<Object>>(20000 );
7573
76- this._vulnerableLogStatement = new LRUMap <>(5000 );
74+ this._vulnerableLogStatement = Collections.synchronizedSet( new HashSet <>() );
7775
78- this._taintedCallDataLoad = new HashSet<>();
76+ this._taintedCallDataLoad = Collections.synchronizedSet( new HashSet<>() );
7977
8078 this._linkFromLogToCallDataLoad = new LRUMap<>(5000);
8179
82- this._vulnerabilityPerFunction = new LRUMap<>(10000);
8380 this._mapEventsFunctions = new LRUMap<>(10000);
8481 }
8582
@@ -162,11 +159,8 @@ public Set<Signature> getMapEventsFunctions(Signature event) {
162159 * @param warning the vulnerability description or warning object to record
163160 */
164161 public void addVulnerabilityPerFunction(Integer key, Object warning) {
165- synchronized (_vulnerabilityPerFunction) {
166- _vulnerabilityPerFunction
167- .computeIfAbsent(key, k -> Collections.synchronizedSet(new HashSet<>()))
168- .add(warning);
169- }
162+ String cacheKey = "vulnerabilityPerFunction:" + key.toString();
163+ putWarning(cacheKey, warning);
170164 }
171165
172166 /**
@@ -183,12 +177,14 @@ public void addVulnerabilityPerFunction(Integer key, Object warning) {
183177 * empty JSONArray if none are present
184178 */
185179 public JSONArray getVulnerabilityPerFunction(Integer key) {
186- synchronized (_vulnerabilityPerFunction) {
187- if (_vulnerabilityPerFunction.get(key) == null)
180+ String cacheKey = "vulnerabilityPerFunction:" + key.toString();
181+ synchronized (_warningsCache) {
182+ Set<Object> warnings = _warningsCache.get(cacheKey);
183+ if (warnings == null)
188184 return new JSONArray();
189185
190186 JSONArray results = new JSONArray();
191- for (Object warning : _vulnerabilityPerFunction.get(key) ) {
187+ for (Object warning : warnings ) {
192188 results.put(warning);
193189 }
194190 return results;
@@ -641,9 +637,7 @@ public int getPossibleLocalDependencyWarnings(Integer key) {
641637 * @param key the LOG statement to mark as vulnerable
642638 */
643639 public void addVulnerableLogStatementForLocalDependencyChecker(Statement key) {
644- synchronized (_vulnerableLogStatement) {
645- _vulnerableLogStatement.put(key, TaintElement.TAINT);
646- }
640+ _vulnerableLogStatement.add(key);
647641 }
648642
649643 /**
@@ -653,9 +647,7 @@ public void addVulnerableLogStatementForLocalDependencyChecker(Statement key) {
653647 * @return a set of LOG statements to be checked for local dependency
654648 */
655649 public Set<Statement> getSetOfVulnerableLogStatementForLocalDependencyChecker() {
656- synchronized (_vulnerableLogStatement) {
657- return _vulnerableLogStatement.keySet();
658- }
650+ return new HashSet<>(_vulnerableLogStatement);
659651 }
660652
661653 /**
@@ -665,9 +657,7 @@ public Set<Statement> getSetOfVulnerableLogStatementForLocalDependencyChecker()
665657 * @param stmt the CALLDATALOAD statement to mark as tainted
666658 */
667659 public void addTaintedCallDataLoad(Statement stmt) {
668- synchronized (_taintedCallDataLoad) {
669- _taintedCallDataLoad.add(stmt);
670- }
660+ _taintedCallDataLoad.add(stmt);
671661 }
672662
673663 /**
@@ -679,9 +669,7 @@ public void addTaintedCallDataLoad(Statement stmt) {
679669 * @return true if the statement is tainted, false otherwise
680670 */
681671 public boolean isTaintedCallDataLoad(Statement stmt) {
682- synchronized (_taintedCallDataLoad) {
683- return _taintedCallDataLoad.contains(stmt);
684- }
672+ return _taintedCallDataLoad.contains(stmt);
685673 }
686674
687675 /**
0 commit comments