1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2006-05-16 06:38:18 +00:00
parent 34e8a8623f
commit c606447c00
2 changed files with 10 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Tue May 16 15:34:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* re.c (rb_reg_initialize): should not modify untainted objects in

6
re.c
View file

@ -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");
}