bpo-32329: Fix -R option for hash randomization (#4873)

bpo-32329, bpo-32030:

* The -R option now turns on hash randomization when the
  PYTHONHASHSEED environment variable is set to 0 Previously, the
  option was ignored.
* sys.flags.hash_randomization is now properly set to 0 when hash
  randomization is turned off by PYTHONHASHSEED=0.
* _PyCoreConfig_ReadEnv() now reads the PYTHONHASHSEED environment
  variable. _Py_HashRandomization_Init() now only apply the
  configuration, it doesn't read PYTHONHASHSEED anymore.
This commit is contained in:
Victor Stinner 2017-12-15 00:51:22 +01:00 committed by GitHub
parent 96a5e50a5d
commit 358e5e17a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 39 deletions

View file

@ -277,8 +277,9 @@ Miscellaneous options
.. cmdoption:: -R
Kept for compatibility. On Python 3.3 and greater, hash randomization is
turned on by default.
Turn on hash randomization. This option only has an effect if the
:envvar:`PYTHONHASHSEED` environment variable is set to ``0``, since hash
randomization is enabled by default.
On previous versions of Python, this option turns on hash randomization,
so that the :meth:`__hash__` values of str, bytes and datetime