Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added trusted libraries scope
  • Loading branch information
Damtev committed Jul 7, 2022
commit 98c2dda7d0e008a5103bc603f85fca13d2933fd4
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.utbot.framework

import mu.KotlinLogging
import org.utbot.common.PathUtil.toPath
import java.io.IOException

private val logger = KotlinLogging.logger {}

private val defaultUserTrustedLibrariesPath: String = "${utbotHomePath}/trustedLibraries.txt"
private const val userTrustedLibrariesKey: String = "utbot.settings.trusted.libraries.path"

object TrustedLibraries {
/**
* JDK and some "trustworthy" open-source libraries.
*/
private val defaultTrustedLibraries: List<String> = listOf(
"java",
"sun",
"javax",
"com.sun",
"org.omg",
"org.xml",
"org.w3c.dom",
"com.google.common",
Comment thread
Damtev marked this conversation as resolved.
Outdated
"org.antlr.v4",
"org.antlr.runtime",
"com.alibaba.fastjson",
Comment thread
Damtev marked this conversation as resolved.
Outdated
"com.alibaba.fescar.core",
"org.apache.pdfbox",
"io.seata.core",
"spoon"
)

private val userTrustedLibraries: List<String>
get() {
val userTrustedLibrariesPath = System.getProperty(userTrustedLibrariesKey) ?: defaultUserTrustedLibrariesPath
val userTrustedLibrariesFile = userTrustedLibrariesPath.toPath().toFile()

if (!userTrustedLibrariesFile.exists()) {
return emptyList()
}

return try {
userTrustedLibrariesFile.readLines()
} catch (e: IOException) {
logger.info { e.message }

emptyList()
}
}

/**
* Represents prefixes of packages for trusted libraries -
* as the union of [defaultTrustedLibraries] and [userTrustedLibraries].
*/
val trustedLibraries: Set<String> by lazy { (defaultTrustedLibraries + userTrustedLibraries).toSet() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import kotlin.reflect.KProperty

private val logger = KotlinLogging.logger {}

/**
* Path to the utbot home folder.
*/
internal val utbotHomePath = "${System.getProperty("user.home")}/.utbot"

/**
* Default path for properties file
*/
internal val defaultSettingsPath = "${System.getProperty("user.home")}/.utbot/settings.properties"
internal const val defaultKeyForSettingsPath = "utbot.settings.path"
private val defaultSettingsPath = "$utbotHomePath/settings.properties"
private const val defaultKeyForSettingsPath = "utbot.settings.path"

internal class SettingDelegate<T>(val initializer: () -> T) {
private var value = initializer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import org.utbot.engine.symbolic.asHardConstraint
import org.utbot.engine.symbolic.asSoftConstraint
import org.utbot.engine.symbolic.asAssumption
import org.utbot.engine.symbolic.asUpdate
import org.utbot.engine.util.trusted.isFromTrustedLibrary
import org.utbot.engine.util.mockListeners.MockListener
import org.utbot.engine.util.mockListeners.MockListenerController
import org.utbot.engine.util.statics.concrete.associateEnumSootFieldsWithConcreteValues
Expand Down Expand Up @@ -2249,10 +2250,10 @@ class UtBotSymbolicEngine(
* Marks the [createdField] as speculatively not null if the [field] is considering as
* not producing [NullPointerException].
*
* @see [SootField.speculativelyCannotProduceNullPointerException], [markAsSpeculativelyNotNull]
* @see [SootField.speculativelyCannotProduceNullPointerException], [markAsSpeculativelyNotNull], [isFromTrustedLibrary].
*/
private fun checkAndMarkLibraryFieldSpeculativelyNotNull(field: SootField, createdField: SymbolicValue) {
if (maximizeCoverageUsingReflection || !field.declaringClass.isLibraryClass) {
if (maximizeCoverageUsingReflection || !field.declaringClass.isFromTrustedLibrary()) {
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.utbot.engine.util.trusted

import org.utbot.framework.TrustedLibraries
import soot.SootClass

/**
* Cache for already discovered trusted/untrusted packages.
*/
private val isPackageTrusted: MutableMap<String, Boolean> = mutableMapOf()

/**
* Determines whether [this] class is from trusted libraries as defined in [TrustedLibraries].
*/
fun SootClass.isFromTrustedLibrary(): Boolean {
isPackageTrusted[packageName]?.let {
return it
}

val isTrusted = TrustedLibraries.trustedLibraries.any { packageName.startsWith(it, ignoreCase = false) }

return isTrusted.also { isPackageTrusted[packageName] = it }
}