-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-wqc8-x2pr-7jqh
* move the commented fix into this branch * more verbose infos, and linting * 3 tests for generators * - add change log entry --------- Co-authored-by: Jens Vagelpohl <[email protected]>
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from RestrictedPython import compile_restricted_exec | ||
|
||
|
||
def test_get_inspect_frame_on_generator(): | ||
source_code = """ | ||
generator = (statement.gi_frame for _ in (1,)) | ||
generator_element = [elem for elem in generator][0] | ||
""" | ||
result = compile_restricted_exec(source_code) | ||
assert result.errors == ( | ||
'Line 2: "gi_frame" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
) | ||
|
||
|
||
def test_get_inspect_frame_back_on_generator(): | ||
source_code = """ | ||
generator = (statement.gi_frame.f_back.f_back for _ in (1,)) | ||
generator_element = [elem for elem in generator][0] | ||
""" | ||
result = compile_restricted_exec(source_code) | ||
assert result.errors == ( | ||
'Line 2: "f_back" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
'Line 2: "f_back" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
'Line 2: "gi_frame" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
) | ||
|
||
|
||
def test_call_inspect_frame_on_generator(): | ||
source_code = """ | ||
generator = None | ||
frame = None | ||
def test(): | ||
global generator, frame | ||
frame = g.gi_frame.f_back.f_back | ||
yield frame | ||
generator = test() | ||
generator.send(None) | ||
os = frame.f_builtins.get('__import__')('os') | ||
result = os.listdir('/') | ||
""" | ||
result = compile_restricted_exec(source_code) | ||
assert result.errors == ( | ||
'Line 7: "f_back" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
'Line 7: "f_back" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
'Line 7: "gi_frame" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
'Line 12: "f_builtins" is a restricted name, ' | ||
'that is forbidden to access in RestrictedPython.', | ||
) |