Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] exec-used, can't reproduce the nefarious example writing in an intermediary file #9913

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Pierre-Sassoulas
Copy link
Member

Type of Changes

Type
βœ“ πŸ“œ Docs

Description

I wanted to make the example's formatting better in details, ended up trying to reproduce it, but it seems the allow_globals parameters is smarter than we thought when originally documenting it. I get this error when uncommenting # allowed_globals:

Traceback (most recent call last):
  File "/home/pierre/pylint/a.py", line 4, in <module>
    exec(
  File "<string>", line 2, in <module>
SystemError: ../Objects/dictobject.c:1490: bad argument to internal function
import textwrap
allowed_globals = {"__builtins__": None}
exec(
    textwrap.dedent("""
    import textwrap

    with open("nefarious.py", "w") as f:
        f.write(textwrap.dedent('''
            def connive():
                print("Here's some code as nefarious as imaginable")
        '''))

    import nefarious
    nefarious.connive()
    """),
    allowed_globals,
)

What am I doing wrong @DanielNoord ?

@Pierre-Sassoulas Pierre-Sassoulas added Documentation πŸ“— Skip news πŸ”‡ This change does not require a changelog entry labels Sep 4, 2024
@DanielNoord
Copy link
Collaborator

Where do you get this error? Locally this example also doesn't run? So perhaps it is just an invalid snippet?

@Pierre-Sassoulas
Copy link
Member Author

I created it :) If you remove allowed_global from the exec call, it's going to work as expected (print the nefarious conniving).

@DanielNoord
Copy link
Collaborator

Sorry I still don't understand the issue πŸ˜…

If I run this code locally without the comment then I also get a crash. So isn't it excepted that you get some kind of (System)Error when you uncomment it?

@Pierre-Sassoulas
Copy link
Member Author

Hmm not sure if it's due to mac vs Ubuntu or if there's some kind if misunderstanding. On my side it print when allowed_global is commented and crash when it's not. Maybe you can provide an exemple where print is being called inside an exec when allowed_globals should forbid it ?

@DanielNoord
Copy link
Collaborator

But in the old code there is no allowed_global right? So the new code without the comment is just invalid Python?

@jacobtylerwalls jacobtylerwalls changed the title [doc] exec-used, can't reproduce the nefarious example writting in an intermediary file [doc] exec-used, can't reproduce the nefarious example writing in an intermediary file Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation πŸ“— Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants