GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — trace.__main__ does not use io.open_code · Issue #103935 · python/cpython

trace.__main__ does not use io.open_code #103935

New issue
Copy link
New issue
Copy link
Closed
Closed
trace.__main__ does not use io.open_code#103935
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifetype-securityA security issueA security issue

Description

@zooba
zooba
opened on Apr 27, 2023
Issue body actions

When used as an entry point, the trace module opens code files without using io.open_code:

https://github.com/python/cpython/blob/main/Lib/trace.py#L719

This should use the io.open_code method instead of open(..., 'rb').

Linked PRs

  • gh-103935: Use io.open_code() to open executable file #103947
  • [3.11] gh-103935: Use io.open_code() when executing code in trace and profile modules (GH-103947) #103950
  • [3.10] gh-103935: Use io.open_code() when executing code in trace and profile modules (GH-103947) #103952
  • [3.9] gh-103935: Use io.open_code() when executing code in trace and profile modules (GH-103947) #103953
  • [3.8] gh-103935: Use io.open_code() when executing code in trace and profile modules (GH-103947) #103954

Activity

Next
  1. zooba
    added
    type-securityA security issueA security issue
    needs backport to 3.7
    needs backport to 3.8
    needs backport to 3.9
    needs backport to 3.10
    needs backport to 3.11only security fixesonly security fixes
    on Apr 27, 2023
  2. Agent-Hellboy commented on Apr 27, 2023

    @Agent-Hellboy
    Agent-Hellboy
    on Apr 27, 2023
    Contributor
    More actions

    Hi @zooba
    I was exploring this and in the mean time i got this error
    ▶ ./python -m trace --trace Lib/calendar.py

      File "Lib/calendar.py", line 155, in monthrange
        ndays = mdays[month] + (month == FEBRUARY and isleap(year))
                                         ^^^^^^^^
    NameError: name 'FEBRUARY' is not defined
    

    FEBRUARY is a global attribute for this module which is made using the global_enum decorator over an enum but trace is throwing an exception that FEBRUARY is not defined

    several std libs are throwing one or the other error

    Btw, is the issue just about changing the open to io.open_code?

  3. gaogaotiantian commented on Apr 27, 2023

    @gaogaotiantian
    gaogaotiantian
    on Apr 27, 2023
    Member
    More actions

    Could you explain why this is a security issue? A similar PR was done for pdb a couple of days ago #103581.

  4. zooba
    removed
    needs backport to 3.7
    on Apr 27, 2023
  5. zooba commented on Apr 27, 2023

    @zooba
    zooba
    on Apr 27, 2023
    MemberAuthor
    More actions

    Because we made a promise that files being opened for execution would go through open_code, and execution is a sensitive path. Plus it's something that anyone building their own security releases would want to backport, so we can save them all the work.

    The pdb change should be backported as well.

    (I removed 3.7 because this was all added in 3.8.)

  6. zooba commented on Apr 27, 2023

    @zooba
    zooba
    on Apr 27, 2023
    MemberAuthor
    More actions

    I stand corrected - pdb was fine in 3.8-3.10, someone regressed it in 3.11, which has now been fixed.

  7. gaogaotiantian commented on Apr 27, 2023

    @gaogaotiantian
    gaogaotiantian
    on Apr 27, 2023
    Member
    More actions

    Thank you for the explanation! In that case, do you want me to submit a PR to fix profile and cProfile which also use raw open for executable code?

  8. zooba commented on Apr 27, 2023

    @zooba
    zooba
    on Apr 27, 2023
    MemberAuthor
    More actions

    Sure, go ahead. They can all go in the same PR

  9. zooba commented on Apr 27, 2023

    @zooba
    zooba
    on Apr 27, 2023
    MemberAuthor
    More actions

    Incidentally, I checked out the other open() calls in trace and they're all fine. It's just the one that I point out in the first message.

  10. gaogaotiantian commented on Apr 27, 2023

    @gaogaotiantian
    gaogaotiantian
    on Apr 27, 2023
    Member
    More actions

    I also did a quick scan for other similar usages, but did not find any Lib code that loads an executable file.

    Reacted by Steve Dower
  11. 1 remaining item

  12. zooba
    added 5 commits that reference this issue on Apr 27, 2023

    pythongh-103935: Use `io.open_code()` when executing code in trace an…

    f3d8215

    pythongh-103935: Use `io.open_code()` when executing code in trace an…

    a17c329

    pythongh-103935: Use `io.open_code()` when executing code in trace an…

    4926515

    gh-103935: Use `io.open_code()` when executing code in trace and prof…

    57d198e

    gh-103935: Use `io.open_code()` when executing code in trace and prof…

    e277266
  13. ambv
    added 2 commits that reference this issue on May 22, 2023

    [3.8] gh-103935: Use `io.open_code()` when executing code in trace an…

    9f89c47

    [3.9] gh-103935: Use `io.open_code()` when executing code in trace an…

    d1645ce
  14. zooba
    closed this as completedon Jun 21, 2023
  15. carlosroman
    added a commit that references this issue on Jun 22, 2023

    Upgrade to 3.8.17 (#26)

    e0a363f
  16. hugovk
    added
    3.11only security fixesonly security fixes
    3.10 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    and removed
    needs backport to 3.9
    needs backport to 3.10
    needs backport to 3.11only security fixesonly security fixes
    on Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifetype-securityA security issueA security issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.