Skip to content
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

AgentModule should set ProtectionDomain when defining classes #1425

Merged
merged 5 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void should_only_load_classes_in_scope() throws Exception {

assertNotSame(this.getClass().getClassLoader(),
t.getClass().getClassLoader());
assertSame(AgentModule.class.getProtectionDomain(),
t.getClass().getProtectionDomain());
assertSame(t.getClass().getClassLoader(),
t.getInnerClassInstance().getClass().getClassLoader());
assertNotSame(this.getClass().getClassLoader(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected Class<?> loadClass(final String name,
} catch (final IOException e) {
throw new RuntimeException(e);
}
return defineClass(name, bytes, 0, bytes.length);
return defineClass(name, bytes, 0, bytes.length,
AgentModule.class.getProtectionDomain());
}
};
}
Expand Down
16 changes: 16 additions & 0 deletions org.jacoco.ant.test/src/org/jacoco/ant/CoverageTaskTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,20 @@
</jacoco:coverage>
</target>

<target name="testSecurityManager">
<jacoco:coverage destfile="${exec.file}">
<java classname="org.jacoco.ant.TestTarget" fork="true" failonerror="true">
<classpath path="${org.jacoco.ant.coverageTaskTest.classes.dir}"/>
<jvmarg value="-Djacoco.agent=${_jacoco.agentFile}"/>
<jvmarg value="-Djacoco.exec=${exec.file}"/>
<jvmarg value="-Djava.security.manager"/>
<!-- Note that the use of two equal signs (==) below is not a typo -->
<jvmarg value="-Djava.security.policy==${basedir}/data/policy.txt"/>
</java>
</jacoco:coverage>

<au:assertFileExists file="${exec.file}"/>
<au:assertLogContains text="Target executed"/>
</target>

</project>
9 changes: 9 additions & 0 deletions org.jacoco.ant.test/src/org/jacoco/ant/data/policy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
grant codeBase "file:${jacoco.agent}" {
permission java.io.FilePermission "${jacoco.exec}/..", "read";
permission java.io.FilePermission "${jacoco.exec}", "write";
permission java.lang.RuntimePermission "shutdownHooks";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "getProtectionDomain";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.lang.RuntimePermission "defineClass";
};
7 changes: 7 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ <h1>Change History</h1>

<h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>

<h3>Fixed bugs</h3>
<ul>
<li>Agent should not require configuration of permissions for
<code>SecurityManager</code> outside of its <code>codeBase</code>
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1425">#1425</a>).</li>
</ul>

<h2>Release 0.8.9 (2023/03/31)</h2>

<h3>New Features</h3>
Expand Down