-
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
Conversation
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
3d26899
to
fe736fc
Compare
Damtev
requested changes
Aug 29, 2022
utbot-framework/src/main/kotlin/org/utbot/engine/SecurityManagerWrapper.kt
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt
Show resolved
Hide resolved
utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt
Outdated
Show resolved
Hide resolved
CaelmBleidd
approved these changes
Aug 29, 2022
Markoutte
approved these changes
Aug 29, 2022
sergeypospelov
approved these changes
Aug 29, 2022
cc16746
to
08ef426
Compare
Damtev
approved these changes
Aug 29, 2022
* Refactored the list of fields that can't be accessed via reflection to use the single rules for all cases (engine, concrete executor, codegen) * Updated this list for Java 11 classes * Added a check to avoid marking reflection-inaccessible static fields as meaningful (they can't be reflexively created by the codegen anyway) * Added `jdk.internal` to the list of system packages to avoid mocking, disabled mocking for classes that can't be accessed via reflection * Added a wrapper for `SecurityManager` and override for two related methods in [Class] * Added UtSettings option to disable sandbox * Temporarily disabled `StringExamplesTest.testByteToString` as flaky
08ef426
to
99fad06
Compare
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Add support for symbolic/concrete analysis of reflection and
Unsafe
calls under JDK 11 and improve their analysis under JDK 8.jdk.internal.*
classes on JDK 11.FieldId.isInaccessibleViaReflection
property to consistently use it in all relevant checks (engine, codegen, concrete executor, mocking), updated the class/field list to JDK 11.SecurityManager
that simulates the "enable all" policy to avoid long analysis of the real privilege checking code. We can lose branches, but the hypothesis is that we will keep "interesting" branches. Two corresponding methods have been added to the [Class] override to save a bit more of work.As the concrete executor now implements a sandbox to disable unsafe and dangerous operations,
UtSettings.disableSandbox
option has been introduced. It allows to disable sandboxing without using non-trivial security manager configuration file. A utility functionwithoutSandbox
can now be used to disable sandbox in a specific unit test.Fixes #721
Fixes #785
Note: the
StringExamplesTest.testByteToString
unit test has been temporarily disabled as flaky. The change of its behavior seems to be related to this PR (new wrappers may change the set of generated constraints), but the test itself is buggy and very fragile due to limitations of the currentString
wrapper implementation (related issue: #131). The test will be re-enabled as a part of new string support (without Z3-backedUtNativeString
), as its problems are rooted in the Z3 string theory and are not related toSecurityManager
and other stuff affected by this PR.Type of Change
This PR adds a new way to disable sandbox, alters the list of classes and fields that can be mocked, can make some static fields not meaningful, and replaces the real analysis of privilege checking with a wrapper/overrides.
How Has This Been Tested?
Automated Testing
New tests have been added:
org.utbot.examples.exceptions.JvmCrashExamplesTest#testCrashPrivileged
: checks thatUnsafe
call can be analyzed when the MUT contains an explicit call todoPrivileged
method.org.utbot.examples.unsafe.UnsafeOperationsTest#checkGetAddressSizeOrZero
: checks a "safe"Unsafe
call.org.utbot.examples.unsafe.UnsafeOperationsTest#checkGetAddressSizeOrZeroWithMocks
: checks a "safe"Unsafe
call with mocking enabled.Manual Scenario
It should be now possible to generate unit tests for the code that involves unsafe calls, e.g.:
It should be possible to generate tests for the "crash" example from the description of #721, but it is necessary to disable summary generation by setting
UtSettings.enableMachineLearningModule = false
. Reason: the only execution that can be generated results in JVM failure, but by default this execution is removed by the summarizer (related issue: #800).Note: make sure that sandbox is either turned off or configured with all necessary privileges during testing, or the method under test wraps privileged calls to
doPrivileged
, otherwise only "disabled by sandbox" tests will be generated.Checklist:
This is the author self-check list