Skip to content

Commit

Permalink
Protect self-attach from execution as source file.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 22, 2024
1 parent b559499 commit 94f0e35
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ public class ByteBuddyAgent {
*/
private static final String OS_NAME = "os.name";

/**
* Represents the {@code file} URL protocol.
*/
private static final String FILE_PROTOCOL = "file";

/**
* The attachment type evaluator to be used for determining if an attachment requires an external process.
*/
Expand Down Expand Up @@ -705,7 +700,7 @@ private static File trySelfResolve() {
return null;
}
URL location = codeSource.getLocation();
if (!location.getProtocol().equals(FILE_PROTOCOL)) {
if (!location.getProtocol().equals("file")) {
return null;
}
try {
Expand Down Expand Up @@ -1451,7 +1446,9 @@ private static File trySelfResolve(Class<?> installer) throws IOException {
return null;
}
URL location = codeSource.getLocation();
if (!location.getProtocol().equals(FILE_PROTOCOL)) {
if (!location.getProtocol().equals("file")
|| location.getPath() == null
|| !location.getPath().endsWith(".class")) {
return null;
}
File agentJar;
Expand Down

0 comments on commit 94f0e35

Please sign in to comment.