Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Soot Concurrent Modification Bug Fix (#19)
Browse files Browse the repository at this point in the history
* Added semaphore to prevent concurrent modification when  loading soot clases

* Formatted code
  • Loading branch information
DavidBakerEffendi authored Nov 1, 2021
1 parent c550a90 commit c72c37b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scalaVersion := "2.13.6"
val cpgVersion = "1.3.392"
val sootVersion = "4.2.1"
val slf4jVersion = "1.7.32"
val scalatestVersion = "3.1.1"
val scalatestVersion = "3.2.9"

Test / fork := true
resolvers ++= Seq(
Expand Down
12 changes: 9 additions & 3 deletions src/main/scala/io/joern/jimple2cpg/passes/AstCreationPass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import org.slf4j.LoggerFactory
import soot.{Scene, SootClass}

import java.io.{File => JFile}
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.{ConcurrentHashMap, Semaphore}
import scala.tools.nsc

case class Global(
usedTypes: ConcurrentHashMap[String, Boolean] = new ConcurrentHashMap[String, Boolean]()
usedTypes: ConcurrentHashMap[String, Boolean] = new ConcurrentHashMap[String, Boolean](),
sootLock: Semaphore = new Semaphore(1)
)

class AstCreationPass(codePath: String, filenames: List[String], cpg: Cpg, keyPool: IntervalKeyPool)
Expand All @@ -33,7 +34,12 @@ class AstCreationPass(codePath: String, filenames: List[String], cpg: Cpg, keyPo
val qualifiedClassName = getQualifiedClassPath(filename)
var sootClass: Option[SootClass] = None
try {
sootClass = Option(Scene.v().loadClassAndSupport(qualifiedClassName))
try {
global.sootLock.acquire()
sootClass = Option(Scene.v().loadClassAndSupport(qualifiedClassName))
} finally {
global.sootLock.release()
}
sootClass match {
case Some(clazz) => new AstCreator(filename, global).createAst(clazz)
case None => null
Expand Down

0 comments on commit c72c37b

Please sign in to comment.