Skip to content

Commit 72d0d2f

Browse files
committed
FIX: don't allow code evaluation inside struct construction specification
related to: zsx#51
1 parent d135f0b commit 72d0d2f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/core/t-struct.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ static get_scalar(REBSTU *stu,
236236
} else {
237237
val = Append_Value(ser);
238238
get_scalar(stu, field, 0, val);
239+
#ifdef ALLOW_CODE_EVALUATION_INSIDE_STRUCT_CONSTRUCTION_SPEC
239240
if (IS_WORD(val)) SET_TYPE(val, REB_LIT_WORD);
241+
#endif
240242
}
241243
}
242244
return ser;
@@ -735,7 +737,8 @@ static REBOOL parse_field_type(struct Struct_Field *field, REBVAL *spec, REBVAL
735737
if (IS_END(blk)) {
736738
Trap_Types(RE_EXPECT_VAL, REB_STRUCT, REB_END);
737739
}
738-
else if (IS_BLOCK(blk)) {
740+
#ifdef ALLOW_CODE_EVALUATION_INSIDE_STRUCT_CONSTRUCTION_SPEC
741+
else if (IS_BLOCK(blk)) {
739742
Reduce_Block(VAL_SERIES(blk), 0, NULL); //result is on stack
740743
init = DS_POP;
741744
++ blk;
@@ -747,7 +750,9 @@ static REBOOL parse_field_type(struct Struct_Field *field, REBVAL *spec, REBVAL
747750
blk = VAL_BLK_SKIP(data, eval_idx);
748751
init = DS_POP; //Do_Next saves result on stack
749752
}
750-
753+
#else
754+
init = blk++;
755+
#endif
751756
if (field->array) {
752757
if (IS_INTEGER(init)) { /* interpreted as a C pointer */
753758
void *ptr = (void *)VAL_INT64(init);

src/tests/units/struct-test.r3

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Rebol [
4343
--assert (mold u64) = "make struct! [a: [uint64!] 0]"
4444
--assert (mold f32) = "make struct! [a: [float!] 0.0]"
4545
--assert (mold f64) = "make struct! [a: [double!] 0.0]"
46-
--assert (mold w) = "make struct! [a: [word!] 'none]"
46+
--assert (mold w) = "make struct! [a: [word!] none]"
4747
===end-group===
4848

4949

@@ -104,6 +104,12 @@ Rebol [
104104
error? e: try [make struct! [ c: [struct! [a [uint8!]]] ]]
105105
e/id = 'expect-val
106106
]
107+
--test-- "Don't allow evaluation inside struct construction"
108+
;@@ https://github.com/zsx/r3/issues/51
109+
--assert all [
110+
error? e: try [make struct! [ a: [uint8!] probe random 100 ]]
111+
e/id = 'invalid-type
112+
]
107113
===end-group===
108114

109115

0 commit comments

Comments
 (0)