summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-05-16 06:38:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-05-16 06:38:18 +0000
commitc606447c00af509f26f4feec95332f832bcc4935 (patch)
tree014743ed24176e59665a91867f94334c219aa18f /re.c
parent34e8a8623f5591d9e36bac81e967d6c947be7f60 (diff)
* 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
Diffstat (limited to 're.c')
-rw-r--r--re.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/re.c b/re.c
index f350bcb..44218cf 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");
}