[ruby-dev:31848] huge `if' dumps core

From: "Yusuke ENDOH" <mame@...>
Date: 2007-09-24 17:24:48 UTC
List: ruby-dev #31848
遠藤と申します。

以下のようにすると 1.8 、1.9 共に落ちます。


$ ./ruby -ve 'eval("if false then;" + "elsif false then;" * 1000000 + "end")'
ruby 1.8.6 (2007-09-23 patchlevel 5000) [i686-linux]
セグメンテーション違反です

$ ./ruby -ve 'eval("if false then;" + "elsif false then;" * 1000000 + "end")'
ruby 1.9.0 (2007-09-24 patchlevel 0) [i686-linux]
セグメンテーション違反です


ALLOCA_N が原因のようです。

Index: parse.y
===================================================================
--- parse.y	(revision 13509)
+++ parse.y	(working copy)
@@ -4593,7 +4593,7 @@
     len = pe - p;
     if (len > 4) {
 	char *p2;
-	buf = ALLOCA_N(char, len+2);
+	buf = ALLOC_N(char, len+2);
 	MEMCPY(buf, p, char, len);
 	buf[len] = '\0';
 	rb_compile_error_append("%s", buf);
@@ -4608,6 +4608,7 @@
 	buf[i] = '^';
 	buf[i+1] = '\0';
 	rb_compile_error_append("%s", buf);
+	free(buf);
     }
 #else
     dispatch1(parse_error, STR_NEW2(msg));

--
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread

Prev Next