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

ruby-changes:51132

From: shyouhei <ko1@a...>
Date: Sat, 5 May 2018 00:18:47 +0900 (JST)
Subject: [ruby-changes:51132] shyouhei:r63339 (trunk): passing rb_thread_sleep to rb_protect is IMHO dangerous

shyouhei	2018-05-05 00:18:42 +0900 (Sat, 05 May 2018)

  New Revision: 63339

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63339

  Log:
    passing rb_thread_sleep to rb_protect is IMHO dangerous
    
    rb_thread_sleep's argument is int, while rb_protect expects the function
    to take VALUE. Depending on ABI this could be a problem.
    
    We should wrap rb_thread_sleep here.

  Modified files:
    trunk/process.c
Index: process.c
===================================================================
--- process.c	(revision 63338)
+++ process.c	(revision 63339)
@@ -3270,6 +3270,13 @@ pipe_nocrash(int filedes[2], VALUE fds) https://github.com/ruby/ruby/blob/trunk/process.c#L3270
 #define O_BINARY 0
 #endif
 
+static VALUE
+rb_thread_sleep_that_takes_VALUE_as_sole_argument(VALUE n)
+{
+    rb_thread_sleep(NUM2INT(n));
+    return Qundef;
+}
+
 static int
 handle_fork_error(int err, int *status, int *ep, volatile int *try_gc_p)
 {
@@ -3291,7 +3298,7 @@ handle_fork_error(int err, int *status, https://github.com/ruby/ruby/blob/trunk/process.c#L3298
             return 0;
         }
         else {
-            rb_protect((VALUE (*)())rb_thread_sleep, 1, &state);
+            rb_protect(rb_thread_sleep_that_takes_VALUE_as_sole_argument, 1, &state);
             if (status) *status = state;
             if (!state) return 0;
         }

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

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