Skip to content

Commit

Permalink
Add property to disallow self-attachment to avoid linking a file into…
Browse files Browse the repository at this point in the history
… the system class loader that is supposed to be deleted.
  • Loading branch information
raphw committed Dec 30, 2019
1 parent 05d400b commit 7962d0b
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
*/
public class ByteBuddyAgent {

/**
* Indicates that the agent should not resolve it's own code location for a self-attachment.
*/
public static final String LATENT_RESOLVE = "net.bytebuddy.agent.latent";

/**
* The manifest property specifying the agent class.
*/
Expand Down Expand Up @@ -686,6 +691,9 @@ private static void installExternal(AttachmentProvider.Accessor.ExternalAttachme
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Exception should not be rethrown but trigger a fallback")
private static File trySelfResolve() {
try {
if (Boolean.getBoolean(LATENT_RESOLVE)) {
return CANNOT_SELF_RESOLVE;
}
ProtectionDomain protectionDomain = Attacher.class.getProtectionDomain();
if (protectionDomain == null) {
return CANNOT_SELF_RESOLVE;
Expand Down Expand Up @@ -1397,6 +1405,9 @@ enum ForByteBuddyAgent implements AgentProvider {
*/
private static File trySelfResolve() throws IOException {
ProtectionDomain protectionDomain = Installer.class.getProtectionDomain();
if (Boolean.getBoolean(LATENT_RESOLVE)) {
return CANNOT_SELF_RESOLVE;
}
if (protectionDomain == null) {
return CANNOT_SELF_RESOLVE;
}
Expand Down

0 comments on commit 7962d0b

Please sign in to comment.