import ctypes import mmap import os import tempfile def killctypes(): fd, name = tempfile.mkstemp() os.write(fd, '\x00' * mmap.PAGESIZE) m = mmap.mmap(fd, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE) m.resize(mmap.PAGESIZE * 2) killer_t = ctypes.c_char * (mmap.PAGESIZE + 1) killer = killer_t.from_buffer(m, 0) killer.value = 'x' * (mmap.PAGESIZE + 1) print killer.value m.resize(mmap.PAGESIZE * 3) print repr(m[0]) print killer.value if __name__ == '__main__': killctypes()