@@ -24,7 +24,7 @@ Command line
2424
2525When invoking Python, you may specify any of these options::
2626
27- python [-bBdEhiOsSuvVWx ?] [-c command | -m module-name | script | - ] [args]
27+ python [-bBdEhiORqsSuvVWx ?] [-c command | -m module-name | script | - ] [args]
2828
2929The most common use case is, of course, a simple invocation of a script::
3030
@@ -227,6 +227,29 @@ Miscellaneous options
227227 .. versionadded :: 3.2
228228
229229
230+ .. cmdoption :: -R
231+
232+ Turn on hash randomization, so that the :meth: `__hash__ ` values of str, bytes
233+ and datetime objects are "salted" with an unpredictable random value.
234+ Although they remain constant within an individual Python process, they are
235+ not predictable between repeated invocations of Python.
236+
237+ This is intended to provide protection against a denial-of-service caused by
238+ carefully-chosen inputs that exploit the worst case performance of a dict
239+ insertion, O(n^2) complexity. See
240+ http://www.ocert.org/advisories/ocert-2011-003.html for details.
241+
242+ Changing hash values affects the order in which keys are retrieved from a
243+ dict. Although Python has never made guarantees about this ordering (and it
244+ typically varies between 32-bit and 64-bit builds), enough real-world code
245+ implicitly relies on this non-guaranteed behavior that the randomization is
246+ disabled by default.
247+
248+ See also :envvar: `PYTHONHASHSEED `.
249+
250+ .. versionadded :: 3.2.3
251+
252+
230253.. cmdoption :: -s
231254
232255 Don't add the :data: `user site-packages directory <site.USER_SITE> ` to
@@ -350,6 +373,7 @@ Options you shouldn't use
350373
351374.. _Jython : http://jython.org
352375
376+
353377.. _using-on-envvars :
354378
355379Environment variables
@@ -458,6 +482,27 @@ These environment variables influence Python's behavior.
458482 option.
459483
460484
485+ .. envvar :: PYTHONHASHSEED
486+
487+ If this variable is set to ``random ``, the effect is the same as specifying
488+ the :option: `-R ` option: a random value is used to seed the hashes of str,
489+ bytes and datetime objects.
490+
491+ If :envvar: `PYTHONHASHSEED ` is set to an integer value, it is used as a fixed
492+ seed for generating the hash() of the types covered by the hash
493+ randomization.
494+
495+ Its purpose is to allow repeatable hashing, such as for selftests for the
496+ interpreter itself, or to allow a cluster of python processes to share hash
497+ values.
498+
499+ The integer must be a decimal number in the range [0,4294967295]. Specifying
500+ the value 0 will lead to the same hash values as when hash randomization is
501+ disabled.
502+
503+ .. versionadded :: 3.2.3
504+
505+
461506.. envvar :: PYTHONIOENCODING
462507
463508 If this is set before running the interpreter, it overrides the encoding used
0 commit comments