diff options
author | Wayne Meissner <wmeissner@gmail.com> | 2010-02-01 09:14:39 +1000 |
---|---|---|
committer | Wayne Meissner <wmeissner@gmail.com> | 2010-02-01 09:14:39 +1000 |
commit | 27620f9ae0496710f242bad5b565c4fe7b8853f1 (patch) | |
tree | 8f233112db75c3fb5ef82d6cca28ee0d047d41ff | |
parent | 3bcf67a0bd40a63855b844b476aa3733a38ca470 (diff) | |
download | ffi-27620f9ae0496710f242bad5b565c4fe7b8853f1.tar.gz |
Add checks to disallow extending FFI::Library into a non-module
-rw-r--r-- | ext/ffi_c/Function.c | 8 | ||||
-rw-r--r-- | lib/ffi/library.rb | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/ext/ffi_c/Function.c b/ext/ffi_c/Function.c index 08d563f..97abe94 100644 --- a/ext/ffi_c/Function.c +++ b/ext/ffi_c/Function.c @@ -249,7 +249,13 @@ function_attach(VALUE self, VALUE module, VALUE name) Data_Get_Struct(self, Function, fn); if (fn->info->parameterCount == -1) { - rb_raise(rb_eRuntimeError, "Cannot attach variadic functions"); + rb_raise(rb_eRuntimeError, "cannot attach variadic functions"); + return Qnil; + } + + if (!rb_obj_is_kind_of(module, rb_cModule)) { + rb_raise(rb_eRuntimeError, "trying to attach function to non-module"); + return Qnil; } if (fn->methodHandle == NULL) { diff --git a/lib/ffi/library.rb b/lib/ffi/library.rb index d8524b1..1ba8475 100644 --- a/lib/ffi/library.rb +++ b/lib/ffi/library.rb @@ -34,6 +34,10 @@ module FFI CURRENT_PROCESS = FFI::CURRENT_PROCESS LIBC = FFI::Platform::LIBC + def self.extended(mod) + raise RuntimeError.new("must only be extended by module") unless mod.kind_of?(Module) + end + def ffi_lib(*names) ffi_libs = names.map do |name| |