-
Notifications
You must be signed in to change notification settings - Fork 46
Fixes for analysis of reflection and Unsafe #721 #797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
utbot-framework/src/main/java/org/utbot/engine/overrides/security/UtSecurityManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.utbot.engine.overrides.security; | ||
|
||
import java.security.Permission; | ||
|
||
/** | ||
* Overridden implementation for [java.lang.SecurityManager] class | ||
*/ | ||
public class UtSecurityManager { | ||
public void checkPermission(Permission perm) { | ||
// Do nothing to allow everything | ||
} | ||
|
||
public void checkPackageAccess(String pkg) { | ||
// Do nothing to allow everything | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
utbot-framework/src/main/kotlin/org/utbot/engine/SecurityManagerWrapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.utbot.engine | ||
|
||
import org.utbot.engine.overrides.security.UtSecurityManager | ||
import org.utbot.framework.plugin.api.UtAssembleModel | ||
import org.utbot.framework.plugin.api.UtModel | ||
import org.utbot.framework.plugin.api.UtStatementModel | ||
import org.utbot.framework.plugin.api.classId | ||
import org.utbot.framework.util.nextModelName | ||
import soot.Scene | ||
import soot.SootClass | ||
import soot.SootMethod | ||
|
||
class SecurityManagerWrapper : BaseOverriddenWrapper(utSecurityManagerClass.name) { | ||
private val baseModelName: String = "securityManager" | ||
|
||
override fun Traverser.overrideInvoke( | ||
wrapper: ObjectValue, | ||
method: SootMethod, | ||
parameters: List<SymbolicValue> | ||
): List<InvokeResult>? { | ||
// We currently do not overload any [SecurityManager] method symbolically | ||
return null | ||
} | ||
|
||
override fun value(resolver: Resolver, wrapper: ObjectValue): UtModel = resolver.run { | ||
val classId = wrapper.type.classId | ||
val addr = holder.concreteAddr(wrapper.addr) | ||
val modelName = nextModelName(baseModelName) | ||
|
||
val instantiationChain = mutableListOf<UtStatementModel>() | ||
val modificationChain = mutableListOf<UtStatementModel>() | ||
return UtAssembleModel(addr, classId, modelName, instantiationChain, modificationChain) | ||
} | ||
|
||
companion object { | ||
val utSecurityManagerClass: SootClass | ||
get() = Scene.v().getSootClass(UtSecurityManager::class.qualifiedName) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
utbot-framework/src/main/kotlin/org/utbot/framework/util/ReflectionUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.utbot.framework.util | ||
|
||
import org.utbot.framework.plugin.api.FieldId | ||
import soot.RefType | ||
|
||
/** | ||
* Several fields are inaccessible in runtime even via reflection | ||
*/ | ||
val FieldId.isInaccessibleViaReflection: Boolean | ||
get() { | ||
val declaringClassName = declaringClass.name | ||
return declaringClassName in inaccessibleViaReflectionClasses || | ||
(name to declaringClassName) in inaccessibleViaReflectionFields | ||
} | ||
|
||
val RefType.isInaccessibleViaReflection: Boolean | ||
get() { | ||
return className in inaccessibleViaReflectionClasses | ||
} | ||
|
||
private val inaccessibleViaReflectionClasses = setOf( | ||
"jdk.internal.reflect.ReflectionFactory", | ||
"jdk.internal.reflect.Reflection", | ||
"jdk.internal.loader.ClassLoaderValue", | ||
"sun.reflect.Reflection", | ||
) | ||
|
||
private val inaccessibleViaReflectionFields = setOf( | ||
"security" to "java.lang.System", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
utbot-framework/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.utbot.examples.unsafe | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.utbot.examples.DoNotCalculate | ||
import org.utbot.examples.UtValueTestCaseChecker | ||
import org.utbot.examples.eq | ||
import org.utbot.examples.withoutSandbox | ||
import org.utbot.framework.codegen.CodeGeneration | ||
import org.utbot.framework.plugin.api.CodegenLanguage | ||
import org.utbot.framework.plugin.api.MockStrategyApi | ||
|
||
internal class UnsafeOperationsTest : UtValueTestCaseChecker(testClass = UnsafeOperations::class) { | ||
@Test | ||
fun checkGetAddressSizeOrZero() { | ||
withoutSandbox { | ||
check( | ||
UnsafeOperations::getAddressSizeOrZero, | ||
eq(1), | ||
{ r -> r!! > 0 }, | ||
// Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0) | ||
// TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807 | ||
coverage = DoNotCalculate | ||
dtim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun checkGetAddressSizeOrZeroWithMocks() { | ||
withoutSandbox { | ||
check( | ||
UnsafeOperations::getAddressSizeOrZero, | ||
eq(1), | ||
{ r -> r!! > 0 }, | ||
// Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0) | ||
// TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807 | ||
coverage = DoNotCalculate, | ||
dtim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mockStrategy = MockStrategyApi.OTHER_CLASSES | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.