Last active
December 20, 2015 00:19
-
-
Save asimihsan/6040598 to your computer and use it in GitHub Desktop.
Get a Python C extension to segfault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cffi import FFI | |
def _make_divide(): | |
libraries = ['c'] | |
extra_compile_args = [] | |
extra_link_args = [] | |
ffi = FFI() | |
ffi.cdef(r""" | |
int divide(int a, int b); | |
""") | |
lib = ffi.verify(""" | |
int divide(int a, int b) { | |
return *(int *)0; | |
}; | |
""", libraries=libraries, | |
extra_compile_args=extra_compile_args, | |
extra_link_args=extra_link_args) | |
return lib.divide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╭─[2013-07-19 17:42:55] asim.ihsan@wll1p00288 ~/temp | |
╰─$ python test.py (env: default) | |
[1] 23328 segmentation fault python test.py | |
╭─[2013-07-19 17:43:23] asim.ihsan@wll1p00288 ~/temp | |
╰─$ ls -ltra | tail -5 (env: default) | |
drwxrwxr-x 3 asim.ihsan asim.ihsan 4096 Jul 19 17:40 __pycache__ | |
-rw-rw-r-- 1 asim.ihsan asim.ihsan 425 Jul 19 17:42 _naughty.py | |
-rw-rw-r-- 1 asim.ihsan asim.ihsan 645 Jul 19 17:42 _naughty.pyc | |
drwxrwxr-x 11 asim.ihsan asim.ihsan 4096 Jul 19 17:42 . | |
drwx------. 76 asim.ihsan asim.ihsan 4096 Jul 19 17:43 .. | |
╭─[2013-07-19 17:43:25] asim.ihsan@wll1p00288 ~/temp | |
# no core file!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _naughty | |
divide = _naughty._make_divide() | |
def main(): | |
print divide(5, 0) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment