poniedziałek, kwietnia 06, 2009

Jak wywalić JVM

import sun.misc.Unsafe;

public final class EvilCode {

public final static Unsafe getUnsafe () {
try {
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
return (Unsafe)field.get(null);
}
catch (Exception ex) {
throw new RuntimeException("can't get Unsafe instance", ex);
}
}

public final static void main(String[] args) {
Unsafe u = getUnsafe();
Random r = new Random();
for (int i=0; i < 1000000; i++) {
u.setMemory(r.nextLong(), 1L, (byte)0x0);
}
}
}

#
# An unexpected error has been detected by Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb7df628a, pid=7635, tid=3084217232
#
# Java VM: Java HotSpot(TM) Client VM (11.0-b16 mixed mode, sharing linux-x86)
# Problematic frame:
# C [libc.so.6+0x7528a] memset+0x1a
#

0 komentarze: