diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-02-21 18:08:26 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-02-21 18:08:26 (GMT) |
commit | 528b54b2637ca2a0d96f1b597d50aa24f789e303 (patch) | |
tree | 5360d51e5e08ac823b822c8ac372317aa6edd4db /Modules/main.c | |
parent | 61f996b26a27d62ea48e550c774f562ec96fa3ab (diff) | |
parent | 86838b02f04a01445778584afb7acd0b05081335 (diff) | |
download | cpython-528b54b2637ca2a0d96f1b597d50aa24f789e303.zip cpython-528b54b2637ca2a0d96f1b597d50aa24f789e303.tar.gz cpython-528b54b2637ca2a0d96f1b597d50aa24f789e303.tar.bz2 |
Fix test failure in test_cmd_line by initializing the hash secret at the earliest point.
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/Modules/main.c b/Modules/main.c index a820a9e..d026033 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -339,7 +339,33 @@ Py_Main(int argc, wchar_t **argv) orig_argc = argc; /* For Py_GetArgcArgv() */ orig_argv = argv; + /* Hash randomization needed early for all string operations + (including -W and -X options). */ + while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { + if (c == 'm' || c == 'c') { + /* -c / -m is the last option: following arguments are + not interpreter options. */ + break; + } + switch (c) { + case 'E': + Py_IgnoreEnvironmentFlag++; + break; + case 'R': + Py_HashRandomizationFlag++; + break; + } + } + /* The variable is only tested for existence here; _PyRandom_Init will + check its value further. */ + if (!Py_HashRandomizationFlag && + (p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0') + Py_HashRandomizationFlag = 1; + + _PyRandom_Init(); + PySys_ResetWarnOptions(); + _PyOS_ResetGetOpt(); while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { if (c == 'c') { @@ -400,7 +426,7 @@ Py_Main(int argc, wchar_t **argv) break; case 'E': - Py_IgnoreEnvironmentFlag++; + /* Already handled above */ break; case 't': @@ -442,7 +468,7 @@ Py_Main(int argc, wchar_t **argv) break; case 'R': - Py_HashRandomizationFlag++; + /* Already handled above */ break; /* This space reserved for other options */ |