Skip to content

Commit f20fafa

Browse files
committed
Add UtSettings option to disable sandbox
1 parent 517c9f6 commit f20fafa

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ object UtSettings {
406406
*/
407407
var ignoreStaticsFromTrustedLibraries by getBooleanProperty(true)
408408

409+
/**
410+
* Disable sandbox in the concrete executor. All unsafe/dangerous calls will be permitted.
411+
*/
412+
var disableSandbox by getBooleanProperty(false)
413+
409414
override fun toString(): String =
410415
settingsValues
411416
.mapKeys { it.key.name }

utbot-framework/src/test/kotlin/org/utbot/examples/UtValueTestCaseChecker.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,3 +2890,16 @@ inline fun <reified T> withUsingReflectionForMaximizingCoverage(maximizeCoverage
28902890
UtSettings.maximizeCoverageUsingReflection = prev
28912891
}
28922892
}
2893+
2894+
/**
2895+
* Run [block] with disabled sandbox in the concrete executor
2896+
*/
2897+
inline fun <reified T> withoutSandbox(block: () -> T): T {
2898+
val prev = UtSettings.disableSandbox
2899+
UtSettings.disableSandbox = true
2900+
try {
2901+
return block()
2902+
} finally {
2903+
UtSettings.disableSandbox = prev
2904+
}
2905+
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ private fun log(any: Any?) {
4848

4949
private val kryoHelper: KryoHelper = KryoHelper(System.`in`, System.`out`)
5050

51+
/**
52+
* Command-line option do disable the sandbox
53+
*/
54+
const val DISABLE_SANDBOX_OPTION = "--disable-sandbox"
55+
5156
/**
5257
* It should be compiled into separate jar file (child_process.jar) and be run with an agent (agent.jar) option.
5358
*/
54-
fun main() {
55-
permissions {
56-
// Enable all permissions for instrumentation.
57-
// SecurityKt.sandbox() is used to restrict these permissions.
58-
+ AllPermission()
59+
fun main(args: Array<String>) {
60+
if (!args.contains(DISABLE_SANDBOX_OPTION)) {
61+
permissions {
62+
// Enable all permissions for instrumentation.
63+
// SecurityKt.sandbox() is used to restrict these permissions.
64+
+AllPermission()
65+
}
5966
}
6067

6168
// We don't want user code to litter the standard output, so we redirect it.

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcessRunner.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ class ChildProcessRunner {
3030

3131
val pathToJava = JdkInfoService.provide().path
3232

33+
val disableSandboxCmd = if (UtSettings.disableSandbox)
34+
listOf(DISABLE_SANDBOX_OPTION)
35+
else
36+
emptyList()
37+
3338
listOf(pathToJava.resolve("bin${File.separatorChar}java").toString()) +
3439
debugCmd +
3540
javaVersionSpecificArguments +
36-
listOf("-javaagent:$jarFile", "-ea", "-jar", "$jarFile")
41+
listOf("-javaagent:$jarFile", "-ea", "-jar", "$jarFile") +
42+
disableSandboxCmd
3743
}
3844

3945
var errorLogFile: File = NULL_FILE

0 commit comments

Comments
 (0)