From c606447c00af509f26f4feec95332f832bcc4935 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 16 May 2006 06:38:18 +0000 Subject: * re.c (rb_reg_initialize): should not allow modifying literal regexps. frozen check moved from rb_reg_initialize_m as well. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ re.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 48b4f78a85..9398bfb255 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue May 16 15:34:18 2006 Yukihiro Matsumoto + + * re.c (rb_reg_initialize): should not allow modifying literal + regexps. frozen check moved from rb_reg_initialize_m as well. + Tue May 16 09:20:16 2006 Yukihiro Matsumoto * re.c (rb_reg_initialize): should not modify untainted objects in diff --git a/re.c b/re.c index f350bcbed1..44218cfd56 100644 --- a/re.c +++ b/re.c @@ -152,6 +152,7 @@ rb_memsearch(x0, m, y0, n) return s-y; } +#define REG_LITERAL FL_USER5 #define REG_CASESTATE FL_USER0 #define KCODE_NONE 0 #define KCODE_EUC FL_USER1 @@ -1335,6 +1336,9 @@ rb_reg_initialize(obj, s, len, options) if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify regexp"); + rb_check_frozen(obj); + if (FL_TEST(obj, REG_LITERAL)) + rb_raise(rb_eSecurityError, "can't modify literal regexp"); if (re->ptr) re_free_pattern(re->ptr); if (re->str) free(re->str); re->ptr = 0; @@ -1374,6 +1378,7 @@ rb_reg_initialize(obj, s, len, options) if (options & ~0xf) { kcode_reset_option(); } + if (ruby_in_compile) FL_SET(obj, REG_LITERAL); } static VALUE rb_reg_s_alloc _((VALUE)); @@ -1656,7 +1661,6 @@ rb_reg_initialize_m(argc, argv, self) long len; int flags = 0; - rb_check_frozen(self); if (argc == 0 || argc > 3) { rb_raise(rb_eArgError, "wrong number of arguments"); } -- cgit v1.2.3