Skip to content

Commit 8e10939

Browse files
committed
Try to ignore jarsigner system.exit calls
1 parent 97b7dca commit 8e10939

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/processing/mode/android/AndroidBuild.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import sun.security.tools.JarSigner;
3737

3838
import java.io.*;
39+
import java.security.Permission;
3940

4041

4142
class AndroidBuild extends JavaBuild {
@@ -304,7 +305,12 @@ private File signPackage(File projectFolder, String keyStorePassword) throws Exc
304305
};
305306

306307
// TODO remove hardcoded tools.jar path from build.xml
307-
JarSigner.main(args);
308+
309+
SystemExitControl.forbidSystemExitCall();
310+
try {
311+
JarSigner.main(args);
312+
} catch (SystemExitControl.ExitTrappedException ignored) { }
313+
SystemExitControl.enableSystemExitCall();
308314

309315
if(verifySignedPackage(unsignedPackage)) {
310316
File signedPackage = new File(projectFolder, "bin/" + sketch.getName() + "-release-signed.apk");
@@ -907,3 +913,26 @@ public void cleanup() {
907913
tmpFolder.deleteOnExit();
908914
}
909915
}
916+
917+
// http://www.avanderw.co.za/preventing-calls-to-system-exit-in-java/
918+
class SystemExitControl {
919+
920+
public static class ExitTrappedException extends SecurityException {
921+
}
922+
923+
public static void forbidSystemExitCall() {
924+
final SecurityManager securityManager = new SecurityManager() {
925+
@Override
926+
public void checkPermission(Permission permission) {
927+
if (permission.getName().contains("exitVM")) {
928+
throw new ExitTrappedException();
929+
}
930+
}
931+
};
932+
System.setSecurityManager(securityManager);
933+
}
934+
935+
public static void enableSystemExitCall() {
936+
System.setSecurityManager(null);
937+
}
938+
}

0 commit comments

Comments
 (0)