@@ -21,7 +21,7 @@ Command line
2121
2222When invoking Python, you may specify any of these options::
2323
24- python [-bBdEhiOsSuvVWx ?] [-c command | -m module-name | script | - ] [args]
24+ python [-bBdEhiORsSuvVWx ?] [-c command | -m module-name | script | - ] [args]
2525
2626The most common use case is, of course, a simple invocation of a script::
2727
@@ -215,6 +215,29 @@ Miscellaneous options
215215 Discard docstrings in addition to the :option: `-O ` optimizations.
216216
217217
218+ .. cmdoption :: -R
219+
220+ Turn on hash randomization, so that the :meth: `__hash__ ` values of str, bytes
221+ and datetime objects are "salted" with an unpredictable random value.
222+ Although they remain constant within an individual Python process, they are
223+ not predictable between repeated invocations of Python.
224+
225+ This is intended to provide protection against a denial-of-service caused by
226+ carefully-chosen inputs that exploit the worst case performance of a dict
227+ insertion, O(n^2) complexity. See
228+ http://www.ocert.org/advisories/ocert-2011-003.html for details.
229+
230+ Changing hash values affects the order in which keys are retrieved from a
231+ dict. Although Python has never made guarantees about this ordering (and it
232+ typically varies between 32-bit and 64-bit builds), enough real-world code
233+ implicitly relies on this non-guaranteed behavior that the randomization is
234+ disabled by default.
235+
236+ See also :envvar: `PYTHONHASHSEED `.
237+
238+ .. versionadded :: 3.1.5
239+
240+
218241.. cmdoption :: -s
219242
220243 Don't add user site directory to sys.path
@@ -314,6 +337,7 @@ Miscellaneous options
314337
315338 .. note :: The line numbers in error messages will be off by one.
316339
340+
317341Options you shouldn't use
318342~~~~~~~~~~~~~~~~~~~~~~~~~
319343
@@ -328,6 +352,7 @@ Options you shouldn't use
328352 Reserved for alternative implementations of Python to use for their own
329353 purposes.
330354
355+
331356.. _using-on-envvars :
332357
333358Environment variables
@@ -435,6 +460,27 @@ These environment variables influence Python's behavior.
435460 import of source modules.
436461
437462
463+ .. envvar :: PYTHONHASHSEED
464+
465+ If this variable is set to ``random ``, the effect is the same as specifying
466+ the :option: `-R ` option: a random value is used to seed the hashes of str,
467+ bytes and datetime objects.
468+
469+ If :envvar: `PYTHONHASHSEED ` is set to an integer value, it is used as a fixed
470+ seed for generating the hash() of the types covered by the hash
471+ randomization.
472+
473+ Its purpose is to allow repeatable hashing, such as for selftests for the
474+ interpreter itself, or to allow a cluster of python processes to share hash
475+ values.
476+
477+ The integer must be a decimal number in the range [0,4294967295]. Specifying
478+ the value 0 will lead to the same hash values as when hash randomization is
479+ disabled.
480+
481+ .. versionadded :: 3.1.5
482+
483+
438484.. envvar :: PYTHONIOENCODING
439485
440486 Overrides the encoding used for stdin/stdout/stderr, in the syntax
0 commit comments