[ruby-dev:24374] Re: eval dumps core

From: nobu@...
Date: 2004-09-30 04:41:32 UTC
List: ruby-dev #24374
なかだです。

At Thu, 30 Sep 2004 13:02:23 +0900,
Tanaka Akira wrote in [ruby-dev:24373]:
> 
> 次のようにすると core を吐きます。
> 
> % ./ruby -e '
> file = "\0" * 0x20000
> file[0,3] = "aaa"
> line = Object.new
> class << line; self end.send(:define_method, :to_int) {
>   file.replace ""
>   10
> }
> eval("p __FILE__", nil, file, line)
> '

なんかいい手ないですかねぇ。


Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.704
diff -u -2 -p -r1.704 eval.c
--- eval.c	27 Sep 2004 12:25:21 -0000	1.704
+++ eval.c	30 Sep 2004 04:33:26 -0000
@@ -6000,5 +6000,4 @@ compile(src, file, line)
 
     ruby_nerrs = 0;
-    StringValue(src);
     critical = rb_thread_critical;
     rb_thread_critical = Qtrue;
@@ -6188,5 +6187,6 @@ rb_f_eval(argc, argv, self)
     }
     if (argc >= 3) {
-	file = StringValuePtr(vfile);
+	StringValue(vfile);
+	file = 0;
     }
     if (argc >= 4) {
@@ -6194,4 +6194,5 @@ rb_f_eval(argc, argv, self)
     }
 
+    if (!file) file = RSTRING(vfile)->ptr;
     if (NIL_P(scope) && ruby_frame->prev) {
 	struct FRAME *prev;


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next