mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
FML now sets a security manager (FINALLY!). It's primary purpose at this point is to catch
rogue calls to System.exit so that they can cause a proper crash report, rather than silently abandoning the game.
This commit is contained in:
1 parent
7219061b05
commit
dff2204558
2 files changed
+48
No files matched your search
@@ -19,6 +19,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.FMLSecurityManager;
|
||||
|
||||
public class FMLTweaker implements ITweaker {
|
||||
private File gameDir;
|
||||
@@ -26,6 +27,17 @@ public class FMLTweaker implements ITweaker {
|
||||
private List<String> standaloneArgs;
|
||||
private static URI jarLocation;
|
||||
|
||||
public FMLTweaker()
|
||||
{
|
||||
try
|
||||
{
|
||||
System.setSecurityManager(new FMLSecurityManager());
|
||||
}
|
||||
catch (SecurityException se)
|
||||
{
|
||||
throw new RuntimeException("FML was unable to install the security manager. The game will not start", se);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package cpw.mods.fml.relauncher;
|
||||
|
||||
import java.security.Permission;
|
||||
|
||||
/**
|
||||
* A custom security manager stopping certain events from happening
|
||||
* unexpectedly.
|
||||
*
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class FMLSecurityManager extends SecurityManager {
|
||||
@Override
|
||||
public void checkPermission(Permission perm)
|
||||
{
|
||||
String permName = perm.getName() != null ? perm.getName() : "missing";
|
||||
if (permName.startsWith("exitVM"))
|
||||
{
|
||||
String callingClass = getClassContext()[4].getName();
|
||||
// FML is allowed to call system exit
|
||||
if (!callingClass.startsWith("cpw.mods.fml."))
|
||||
{
|
||||
throw new ExitTrappedException();
|
||||
}
|
||||
}
|
||||
else if ("setSecurityManager".equals(permName))
|
||||
{
|
||||
throw new SecurityException("Cannot replace the FML security manager");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static class ExitTrappedException extends SecurityException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user