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

_Random.seed() is called twice #88426

Closed
serhiy-storchaka opened this issue May 28, 2021 · 3 comments
Closed

_Random.seed() is called twice #88426

serhiy-storchaka opened this issue May 28, 2021 · 3 comments
Labels
3.11 only security fixes extension-modules C modules in the Modules dir

Comments

@serhiy-storchaka
Copy link
Member

BPO 44260
Nosy @rhettinger, @mdickinson, @serhiy-storchaka
PRs
  • bpo-44260: Do not read system entropy without need in Random() #26455
  • 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 2021-05-31.20:24:57.127>
    created_at = <Date 2021-05-28.14:27:28.976>
    labels = ['extension-modules', '3.11']
    title = '_Random.seed() is called twice'
    updated_at = <Date 2021-05-31.20:24:57.126>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-05-31.20:24:57.126>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-05-31.20:24:57.127>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2021-05-28.14:27:28.976>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44260
    keywords = ['patch']
    message_count = 3.0
    messages = ['394663', '394754', '394823']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'serhiy.storchaka']
    pr_nums = ['26455']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44260'
    versions = ['Python 3.11']

    @serhiy-storchaka
    Copy link
    Member Author

    _Random.seed() is called twice: first it is called in _Random.__new__(), then it is called in Random.__init__(). By default it reads system enthropy, so it consumes global system resource without need.

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir labels May 28, 2021
    @rhettinger
    Copy link
    Contributor

    Consider moving seeding from _random.Random.__new__ to _random.Random.__init__. Since random.Random.__init__ doesn't call the super(), the C version never gets called, avoiding the double seeding. But, it still lets _random.Random function as a standalone class.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset a6a2065 by Serhiy Storchaka in branch 'main':
    bpo-44260: Do not read system entropy without need in Random() (GH-26455)
    a6a2065

    @serhiy-storchaka serhiy-storchaka added the 3.11 only security fixes label May 31, 2021
    @serhiy-storchaka serhiy-storchaka added the 3.11 only security fixes label May 31, 2021
    @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.11 only security fixes extension-modules C modules in the Modules dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants