Do not allow to access compiler internals in .kts scripts

Set parent class loader to null explicitly instead of the system class
loader
This commit is contained in:
Alexander Udalov
2017-07-10 20:39:35 +03:00
parent d1603c4329
commit 36001ff931
6 changed files with 55 additions and 62 deletions
@@ -115,15 +115,16 @@ done
scriptFileName: String,
scriptTemplate: KClass<out Any>,
environment: Map<String, Any?>? = null,
suppressOutput: Boolean = false): Class<*>? =
compileScriptImpl("src/test/resources/scripts/" + scriptFileName, KotlinScriptDefinitionFromAnnotatedTemplate(scriptTemplate, null, null, environment), suppressOutput)
suppressOutput: Boolean = false
): Class<*>? =
compileScriptImpl("src/test/resources/scripts/" + scriptFileName,
KotlinScriptDefinitionFromAnnotatedTemplate(scriptTemplate, null, null, environment), suppressOutput)
private fun compileScriptImpl(
scriptPath: String,
scriptDefinition: KotlinScriptDefinition,
suppressOutput: Boolean): Class<*>?
{
val paths = PathUtil.getKotlinPathsForDistDirectory()
suppressOutput: Boolean
): Class<*>? {
val messageCollector =
if (suppressOutput) MessageCollector.NONE
else PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false)
@@ -158,7 +159,7 @@ done
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
try {
return KotlinToJVMBytecodeCompiler.compileScript(environment, paths)
return KotlinToJVMBytecodeCompiler.compileScript(environment)
}
catch (e: CompilationException) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),