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

Possible issues when remove not completely initialized module from sys.module #86159

Closed
serhiy-storchaka opened this issue Oct 10, 2020 · 3 comments
Labels
3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 41993
Nosy @brettcannon, @ncoghlan, @ericsnowcurrently, @serhiy-storchaka, @miss-islington
PRs
  • bpo-41993: Fix possible issues in remove_module() #22631
  • [3.9] bpo-41993: Fix possible issues in remove_module() (GH-22631) #22647
  • [3.8] bpo-41993: Fix possible issues in remove_module() (GH-22631) #22649
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-10-11.16:21:50.456>
    created_at = <Date 2020-10-10.10:51:27.945>
    labels = ['interpreter-core', 'type-bug', '3.9', '3.10']
    title = 'Possible issues when remove not completely initialized module from sys.module'
    updated_at = <Date 2020-10-14.09:10:13.921>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-10-14.09:10:13.921>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-10-11.16:21:50.456>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2020-10-10.10:51:27.945>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41993
    keywords = ['patch']
    message_count = 3.0
    messages = ['378382', '378434', '378608']
    nosy_count = 5.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'eric.snow', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['22631', '22647', '22649']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41993'
    versions = ['Python 3.9', 'Python 3.10']

    @serhiy-storchaka
    Copy link
    Member Author

    There are several issues in remove_module() in Python/import.c.

    1. PyMapping_HasKey() is used to determine if the module was in sys.modules before removing it. But it can return 0 not only when the key is absent in the mapping, but also when some exceptions was raised during checking (including MemoryError, KeybordInterraption and RecursionError). The corresponding exception will be silenced and the module will be left in sys.modules.

    2. If PyMapping_DelItem() fails, a RuntimeError is raised. It is chained with the exception raised in PyMapping_DelItem(), but the original exception, raised before calling remove_module() will be lost.

    3. There is a possible race condition between PyMapping_HasKey() and PyMapping_DelItem().

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes 3.10 only security fixes 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Oct 10, 2020
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 8287aad by Serhiy Storchaka in branch 'master':
    bpo-41993: Fix possible issues in remove_module() (GH-22631)
    8287aad

    @serhiy-storchaka serhiy-storchaka removed the 3.8 only security fixes label Oct 11, 2020
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 391a544 by Miss Skeleton (bot) in branch '3.9':
    bpo-41993: Fix possible issues in remove_module() (GH-22631) (GH-22647)
    391a544

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant