diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-02-21 19:42:48 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-02-21 19:42:48 (GMT) |
commit | 776af4002bb6edf6071f0b82f0354ed7b218695e (patch) | |
tree | db9510e763e2476783eb331b9a6fb396995bc815 /Modules | |
parent | 876e789f650a68b1fe05be7060794357cf13e3d3 (diff) | |
download | cpython-776af4002bb6edf6071f0b82f0354ed7b218695e.zip cpython-776af4002bb6edf6071f0b82f0354ed7b218695e.tar.gz cpython-776af4002bb6edf6071f0b82f0354ed7b218695e.tar.bz2 |
Fix crash at startup with -W options.
Diffstat (limited to 'Modules')
-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 780d877..929991a 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -261,7 +261,33 @@ Py_Main(int argc, char **argv) Py_RISCOSWimpFlag = 0; #endif + /* 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') { @@ -355,7 +381,7 @@ Py_Main(int argc, char **argv) break; case 'E': - Py_IgnoreEnvironmentFlag++; + /* Already handled above */ break; case 't': @@ -405,7 +431,7 @@ Py_Main(int argc, char **argv) break; case 'R': - Py_HashRandomizationFlag++; + /* Already handled above */ break; /* This space reserved for other options */ |