Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* struct.c (rb_struct_modify): should check frozen and taint

  status.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 14cd9473173b69482adb1b4422f72d95d25b2ff7 1 parent f33a61c
matz authored
Showing with 18 additions and 2 deletions.
  1. +5 −0 ChangeLog
  2. +13 −2 struct.c
View
5 ChangeLog
@@ -4,6 +4,11 @@ Mon Aug 6 03:29:03 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_rstrip_bang): new method.
+Mon Aug 6 00:35:03 2001 Guy Decoux <decoux@moulon.inra.fr>
+
+ * struct.c (rb_struct_modify): should check frozen and taint
+ status.
+
Sun Aug 5 19:28:39 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* string.c (rb_str_associate): should consider STR_ASSOC too.
View
15 struct.c
@@ -124,6 +124,15 @@ static VALUE (*ref_func[10])() = {
rb_struct_ref9,
};
+static void
+rb_struct_modify(s)
+ VALUE s;
+{
+ if (OBJ_FROZEN(s)) rb_error_frozen("Struct");
+ if (!OBJ_TAINTED(s) && rb_safe_level() >= 4)
+ rb_raise(rb_eSecurityError, "Insecure: can't modify Struct");
+}
+
static VALUE
rb_struct_set(obj, val)
VALUE obj, val;
@@ -135,6 +144,7 @@ rb_struct_set(obj, val)
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}
+ rb_struct_modify(obj);
for (i=0; i<RARRAY(member)->len; i++) {
slot = RARRAY(member)->ptr[i];
if (rb_id_attrset(SYM2ID(slot)) == rb_frame_last_func()) {
@@ -254,6 +264,7 @@ rb_struct_initialize(self, values)
VALUE size;
long n;
+ rb_struct_modify(self);
size = iv_get(klass, "__size__");
n = FIX2LONG(size);
if (n < RARRAY(values)->len) {
@@ -474,7 +485,7 @@ rb_struct_aset_id(s, id, val)
rb_bug("non-initialized struct");
}
- if (OBJ_FROZEN(s)) rb_error_frozen("Struct");
+ rb_struct_modify(s);
len = RARRAY(member)->len;
for (i=0; i<len; i++) {
if (SYM2ID(RARRAY(member)->ptr[i]) == id) {
@@ -505,7 +516,7 @@ rb_struct_aset(s, idx, val)
rb_raise(rb_eIndexError, "offset %d too large for struct(size:%d)",
i, RSTRUCT(s)->len);
}
- if (OBJ_FROZEN(s)) rb_error_frozen("Struct");
+ rb_struct_modify(s);
return RSTRUCT(s)->ptr[i] = val;
}
Please sign in to comment.
Something went wrong with that request. Please try again.