Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 75066:f4b7ecf8a5f8 3.1
Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
in order to make algorithmic complexity attacks on (e.g.) web apps much more complicated.
The environment variable PYTHONHASHSEED and the new command line flag -R control this
behavior.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 20 Feb 2012 19:54:16 +0100 |
| parents | 0311f62714f7 |
| children | 4a31f6b11e7a |
comparison
equal
deleted
inserted
replaced
| 75016:4dd5a94fd3e3 | 75066:f4b7ecf8a5f8 |
|---|---|
| 71 static void call_ll_exitfuncs(void); | 71 static void call_ll_exitfuncs(void); |
| 72 extern void _PyUnicode_Init(void); | 72 extern void _PyUnicode_Init(void); |
| 73 extern void _PyUnicode_Fini(void); | 73 extern void _PyUnicode_Fini(void); |
| 74 extern int _PyLong_Init(void); | 74 extern int _PyLong_Init(void); |
| 75 extern void PyLong_Fini(void); | 75 extern void PyLong_Fini(void); |
| 76 extern void _PyRandom_Init(void); | |
| 76 | 77 |
| 77 #ifdef WITH_THREAD | 78 #ifdef WITH_THREAD |
| 78 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *); | 79 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *); |
| 79 extern void _PyGILState_Fini(void); | 80 extern void _PyGILState_Fini(void); |
| 80 #endif /* WITH_THREAD */ | 81 #endif /* WITH_THREAD */ |
| 89 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ | 90 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ |
| 90 int Py_FrozenFlag; /* Needed by getpath.c */ | 91 int Py_FrozenFlag; /* Needed by getpath.c */ |
| 91 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ | 92 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ |
| 92 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ | 93 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ |
| 93 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ | 94 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ |
| 95 int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */ | |
| 94 | 96 |
| 95 /* PyModule_GetWarningsModule is no longer necessary as of 2.6 | 97 /* PyModule_GetWarningsModule is no longer necessary as of 2.6 |
| 96 since _warnings is builtin. This API should not be used. */ | 98 since _warnings is builtin. This API should not be used. */ |
| 97 PyObject * | 99 PyObject * |
| 98 PyModule_GetWarningsModule(void) | 100 PyModule_GetWarningsModule(void) |
| 193 Py_VerboseFlag = add_flag(Py_VerboseFlag, p); | 195 Py_VerboseFlag = add_flag(Py_VerboseFlag, p); |
| 194 if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0') | 196 if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0') |
| 195 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p); | 197 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p); |
| 196 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0') | 198 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0') |
| 197 Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p); | 199 Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p); |
| 200 /* The variable is only tested for existence here; _PyRandom_Init will | |
| 201 check its value further. */ | |
| 202 if ((p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0') | |
| 203 Py_HashRandomizationFlag = add_flag(Py_HashRandomizationFlag, p); | |
| 204 | |
| 205 _PyRandom_Init(); | |
| 198 | 206 |
| 199 interp = PyInterpreterState_New(); | 207 interp = PyInterpreterState_New(); |
| 200 if (interp == NULL) | 208 if (interp == NULL) |
| 201 Py_FatalError("Py_Initialize: can't make first interpreter"); | 209 Py_FatalError("Py_Initialize: can't make first interpreter"); |
| 202 | 210 |
