Skip to content

Commit

Permalink
FIX: disallowed loop variable context access
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jan 26, 2023
1 parent a27822c commit 6fb6e0f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/n-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2022 Rebol Open Source Developers
** Copyright 2012-2023 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -352,6 +352,9 @@ static int Check_Char_Range(REBVAL *val, REBINT limit)
// case like: ` f: func[a][context? 'a] f 1 `
*D_RET = frame[3];
} else {
if (IS_INT_SERIES(VAL_WORD_FRAME(word)))
// in case like: ` foreach x [1] [context? 'x] `
return R_NONE;
SET_OBJECT(D_RET, VAL_WORD_FRAME(word));
}
return R_RET;
Expand Down
4 changes: 4 additions & 0 deletions src/core/n-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ enum loop_each_mode {
SET_SELFLESS(frame);
SERIES_TAIL(frame) = len+1;
SERIES_TAIL(FRM_WORD_SERIES(frame)) = len+1;

// Mark the frame as internal series so it is not accessible!
// See: https://github.com/Oldes/Rebol-issues/issues/2531
INT_SERIES(frame);

// Setup for loop:
word = FRM_WORD(frame, 1); // skip SELF
Expand Down
3 changes: 3 additions & 0 deletions src/include/sys-value.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ enum {
SER_BARE = 1<<5, // Series has no links to GC-able values
SER_PROT = 1<<6, // Series is protected from modification
SER_MON = 1<<7, // Monitoring
SER_INT = 1<<8, // Series data is internal (loop frames) and should not be accessed by users
};

#define SERIES_SET_FLAG(s, f) (SERIES_FLAGS(s) |= ((f) << 8))
Expand All @@ -489,6 +490,8 @@ enum {
#define KEEP_SERIES(s,l) do {SERIES_SET_FLAG(s, SER_KEEP); LABEL_SERIES(s,l);} while(0)
#define EXT_SERIES(s) SERIES_SET_FLAG(s, SER_EXT)
#define IS_EXT_SERIES(s) SERIES_GET_FLAG(s, SER_EXT)
#define INT_SERIES(s) SERIES_SET_FLAG(s, SER_INT)
#define IS_INT_SERIES(s) SERIES_GET_FLAG(s, SER_INT)
#define LOCK_SERIES(s) SERIES_SET_FLAG(s, SER_LOCK)
#define IS_LOCK_SERIES(s) SERIES_GET_FLAG(s, SER_LOCK)
#define BARE_SERIES(s) SERIES_SET_FLAG(s, SER_BARE)
Expand Down
4 changes: 4 additions & 0 deletions src/tests/units/object-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ Rebol [
--assert object? o: context? use [x] ['x]
--assert object? append o 'self

--test-- "issue-2531"
;@@ https://github.com/Oldes/Rebol-issues/issues/2531
--assert none? foreach x [1] [context? 'x]

===end-group===

===start-group=== "PROTECT object!"
Expand Down

0 comments on commit 6fb6e0f

Please sign in to comment.