Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/6626217/bug_21227.java
32284 views
1import java.lang.reflect.*;2import java.security.*;34abstract public class bug_21227 {56// Jam anything you want in here, it will be cast to a You_Have_Been_P0wned7public static Object _p0wnee;89public static void main(String argv[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException {10System.out.println("Warmup");1112// Make a Class 'many_loader' under the default loader13bug_21227 bug = new many_loader();1415// Some classes under a new Loader, LOADER2, including another version of 'many_loader'16ClassLoader LOADER2 = new Loader2();17Class clazz2 = LOADER2.loadClass("from_loader2");18IFace iface = (IFace)clazz2.newInstance();1920// Set the victim, a String of length 621String s = "victim";22_p0wnee = s;2324// Go cast '_p0wnee' to type You_Have_Been_P0wned25many_loader[] x2 = bug.make(iface);2627many_loader b = x2[0];2829// Make it clear that the runtime type many_loader (what we get from the30// array X2) varies from the static type of many_loader.31Class cl1 = b.getClass();32ClassLoader ld1 = cl1.getClassLoader();33Class cl2 = many_loader.class;34ClassLoader ld2 = cl2.getClassLoader();35System.out.println("bug.make() "+ld1+":"+cl1);36System.out.println("many_loader "+ld2+":"+cl2);3738// Read the victims guts out39You_Have_Been_P0wned q = b._p0wnee;40System.out.println("q._a = 0x"+Integer.toHexString(q._a));41System.out.println("q._b = 0x"+Integer.toHexString(q._b));42System.out.println("q._c = 0x"+Integer.toHexString(q._c));43System.out.println("q._d = 0x"+Integer.toHexString(q._d));4445System.out.println("I will now crash the VM:");46// On 32-bit HotSpot Java6 this sets the victim String length shorter, then crashes the VM47//q._c = 3;48q._a = -1;4950System.out.println(s);5152}5354// I need to compile (hence call in a loop) a function which returns a value55// loaded from classloader other than the system one. The point of this56// call is to give me an abstract 'hook' into a function loaded with a57// foreign loader.58public abstract many_loader[] make( IFace iface ); // abstract factory59}60616263