Intentionally cause a segfault under Ruby 1.8.7
What's the easiest way to cause a segf开发者_如何学运维ault intentionally in MRI Ruby 1.8.7?
You might check out segfault4r (it was last updated in 2007). You have to download and install the gem manually, as it's not available through RubyGems.
You could write a bad C module that de-references a NULL pointer.
Depending on your needs (and environment) you could get it running, find the interpreter's process ID and do:
$ kill -s SIGSEGV $pid
I just tried this on OSX with bash and it worked on an ed(1) (the one true text editor) process.
You could also run Ruby in a debugger and manually set a pointer or two to zero. One of the pointers inside a variable would do nicely. Of course, you'd probably need to have an interpreter built with debug symbols and you'd need to know a thing or two about the interpreter's internals.
If you're doing this against a specific patchlevel, look at Ruby's bug tracker for bugs that were reported after that patchlevel was created that cause a segmentation fault. As you're looking at 1.8.7, you'll probably want to look at those categorized as Ruby 1.8 .
For example, for the version of Ruby (1.9) I have on my Windows machine, Thread.kill(nil)
is sufficient to cause a segfault, and I think it applies to Ruby 1.8 as well.
精彩评论