Skip to content

Commit a33122a

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

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ class ChildProcessRunner {
4949

5050
val directory = WorkingDirService.provide().toFile()
5151

52-
val processBuilder = ProcessBuilder(cmds)
52+
val commandsWithOptions = buildList {
53+
addAll(cmds)
54+
if (UtSettings.disableSandbox) {
55+
add(DISABLE_SANDBOX_OPTION)
56+
}
57+
}
58+
59+
val processBuilder = ProcessBuilder(commandsWithOptions)
5360
.redirectError(errorLogFile)
5461
.directory(directory)
5562

0 commit comments

Comments
 (0)