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

PYTHONHASHSEED=0 python3 -R should enable hash randomization #76510

Closed
vstinner opened this issue Dec 14, 2017 · 5 comments
Closed

PYTHONHASHSEED=0 python3 -R should enable hash randomization #76510

vstinner opened this issue Dec 14, 2017 · 5 comments
Labels
3.7 (EOL) end of life

Comments

@vstinner
Copy link
Member

BPO 32329
Nosy @vstinner
PRs
  • bpo-32329: Fix -R option for hash randomization #4873
  • [3.6] bpo-32329: Fix sys.flags.hash_randomization #4875
  • bpo-32329: Add versionchanged to -R option doc #4884
  • 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 2017-12-15.15:41:41.471>
    created_at = <Date 2017-12-14.23:11:19.999>
    labels = ['3.7']
    title = 'PYTHONHASHSEED=0 python3 -R should enable hash randomization'
    updated_at = <Date 2017-12-15.15:41:41.470>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-12-15.15:41:41.470>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-12-15.15:41:41.471>
    closer = 'vstinner'
    components = []
    creation = <Date 2017-12-14.23:11:19.999>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32329
    keywords = ['patch']
    message_count = 5.0
    messages = ['308343', '308348', '308354', '308355', '308405']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = ['4873', '4875', '4884']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32329'
    versions = ['Python 3.7']

    @vstinner
    Copy link
    Member Author

    Python pretends that hash randomization is always enabled, but it's not:

    $ PYTHONHASHSEED=0 python3 -c 'import sys; print(sys.flags.hash_randomization)'
    1
    vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
    4596069200710135518
    vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
    4596069200710135518
    vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
    4596069200710135518

    => sys.flags.hash_randomization must be zero

    Moreover, the -R flag is always ignored, it's not possible to override the PYTHONHASHSEED environment variable:

    vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(sys.flags.hash_randomization)'
    1
    vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
    4596069200710135518
    vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
    4596069200710135518
    vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
    4596069200710135518

    I expect that -R enables hash randomization and overrides PYTHONHASHSEED environment variable.

    Attached PR fixes these issues and adds an unit test.

    @vstinner vstinner added the 3.7 (EOL) end of life label Dec 14, 2017
    @vstinner
    Copy link
    Member Author

    New changeset 358e5e1 by Victor Stinner in branch 'master':
    bpo-32329: Fix -R option for hash randomization (bpo-4873)
    358e5e1

    @vstinner
    Copy link
    Member Author

    New changeset 22097aa by Victor Stinner in branch '3.6':
    bpo-32329: Fix sys.flags.hash_randomization (bpo-4875)
    22097aa

    @vstinner
    Copy link
    Member Author

    "PYTHONHASHSEED=0 python3 -R" now enables hash randomization on master (Python 3.7), I also fixed the sys.flags.hash_randomization value when using PYTHONHASHSEED=0.

    I chose to not modify the behaviour of the -R option in Python 3.6. I dislike having to document a behaviour change in a minor Python version (3.6.x). I only fixed the value of sys.flags.hash_randomization in Python 3.6.

    @vstinner
    Copy link
    Member Author

    New changeset 642d67b by Victor Stinner in branch 'master':
    bpo-32329: Add versionchanged to -R option doc (bpo-4884)
    642d67b

    @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.7 (EOL) end of life
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant