[前][次][番号順一覧][スレッド一覧]

ruby-changes:13675

From: tenderlove <ko1@a...>
Date: Sun, 25 Oct 2009 09:11:33 +0900 (JST)
Subject: [ruby-changes:13675] Ruby:r25460 (trunk): * ext/dl/handle.c (rb_dlhandle_sym) refactoring rb_secure(2)

tenderlove	2009-10-25 09:11:15 +0900 (Sun, 25 Oct 2009)

  New Revision: 25460

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25460

  Log:
    * ext/dl/handle.c (rb_dlhandle_sym) refactoring rb_secure(2)
    * test/dl/test_handle.rb (**) testing sym behavior

  Modified files:
    trunk/ext/dl/handle.c
    trunk/test/dl/test_handle.rb

Index: ext/dl/handle.c
===================================================================
--- ext/dl/handle.c	(revision 25459)
+++ ext/dl/handle.c	(revision 25460)
@@ -218,8 +218,6 @@
 {
     struct dl_handle *dlhandle;
 
-    rb_secure(2);
-
     TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
     if( ! dlhandle->open ){
 	rb_raise(rb_eDLError, "closed handle");
@@ -235,16 +233,26 @@
 #define RTLD_DEFAULT NULL
 #endif
 
+/*
+ * Document-method: sym
+ * Document-method: []
+ *
+ * call-seq: sym(name)
+ *
+ * Get the address as an Integer for the function named +name+.  The function
+ * is searched via dlsym on RTLD_NEXT.  See man(3) dlsym() for more info.
+ */
 VALUE
 rb_dlhandle_s_sym(VALUE self, VALUE sym)
 {
-    rb_secure(2);
     return dlhandle_sym(RTLD_NEXT, StringValueCStr(sym));
 }
 
 static VALUE
 dlhandle_sym(void *handle, const char *name)
 {
+    rb_secure(2);
+
 #if defined(HAVE_DLERROR)
     const char *err;
 # define CHECK_DLERROR if( err = dlerror() ){ func = 0; }
Index: test/dl/test_handle.rb
===================================================================
--- test/dl/test_handle.rb	(revision 25459)
+++ test/dl/test_handle.rb	(revision 25460)
@@ -2,6 +2,25 @@
 
 module DL
   class TestHandle < TestBase
+    def test_static_sym_secure
+      assert_raises(SecurityError) do
+        Thread.new do
+          $SAFE = 2
+          DL::Handle.sym('calloc')
+        end.join
+      end
+    end
+
+    def test_static_sym_unknown
+      assert_raises(DL::DLError) { DL::Handle.sym('fooo') }
+      assert_raises(DL::DLError) { DL::Handle['fooo'] }
+    end
+
+    def test_static_sym
+      assert DL::Handle.sym('dlopen')
+      assert_equal DL::Handle.sym('dlopen'), DL::Handle['dlopen']
+    end
+
     def test_sym_closed_handle
       handle = DL::Handle.new(LIBC_SO)
       handle.close
@@ -21,6 +40,16 @@
       assert_raises(TypeError) { handle[nil] }
     end
 
+    def test_sym_secure
+      assert_raises(SecurityError) do
+        Thread.new do
+          $SAFE = 2
+          handle = DL::Handle.new(LIBC_SO)
+          handle.sym('calloc')
+        end.join
+      end
+    end
+
     def test_sym
       handle = DL::Handle.new(LIBC_SO)
       assert handle.sym('calloc')

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]