duckinator/sicuro — pull request #5 by bcluca (2012-06-03 23:41:43+00:00)
Title: Fixed removal of unsafe Kernel methods

Hi,

The removal of Kernel methods as implemented in `#_unsafe_eval` has no effect, as undefining them with `#undef_method` is not enough.

This means that we can run code like this:

Sicuro.eval "Kernel.open('foo', 'w') { |f| f.write 'bar' }"

This is especially dangerous because the latest version of FakeFS fails to fake `Kernel.open` and, consequently, the code above creates an actual file on the filesystem (unless $SAFE is used, of course).

Because of the way Kernel is defined, the unsafe methods have to be removed with `#remove_method` from both Kernel and Kernel's eigenclass:

Kernel.send(:remove_method, x.to_sym)
class << Kernel; self end.send(:remove_method, x.to_sym)

This pull request fixes the issue in `#_unsafe_eval` and adds the corresponding test.

Tested with Ruby 1.8.7, 1.9.2 and 1.9.3 on MacOS 10.6.8 and Ubuntu 12.04.

Thanks,
_Luca Bernardo Ciddio_