comparison Python/pythonrun.c @ 75073:4a31f6b11e7a 3.2

Merge from 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 21:31:46 +0100
parents 93e86b9318f7 f4b7ecf8a5f8
children 0e8bd4785ea0 ed76dc34b39d
comparison
equal deleted inserted replaced
75062:a72e0e1d0292 75073:4a31f6b11e7a
68 static void call_ll_exitfuncs(void); 68 static void call_ll_exitfuncs(void);
69 extern void _PyUnicode_Init(void); 69 extern void _PyUnicode_Init(void);
70 extern void _PyUnicode_Fini(void); 70 extern void _PyUnicode_Fini(void);
71 extern int _PyLong_Init(void); 71 extern int _PyLong_Init(void);
72 extern void PyLong_Fini(void); 72 extern void PyLong_Fini(void);
73 extern void _PyRandom_Init(void);
73 74
74 #ifdef WITH_THREAD 75 #ifdef WITH_THREAD
75 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *); 76 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
76 extern void _PyGILState_Fini(void); 77 extern void _PyGILState_Fini(void);
77 #endif /* WITH_THREAD */ 78 #endif /* WITH_THREAD */
87 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ 88 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
88 int Py_FrozenFlag; /* Needed by getpath.c */ 89 int Py_FrozenFlag; /* Needed by getpath.c */
89 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ 90 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
90 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ 91 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */
91 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ 92 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */
93 int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */
92 94
93 PyThreadState *_Py_Finalizing = NULL; 95 PyThreadState *_Py_Finalizing = NULL;
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. */
205 Py_VerboseFlag = add_flag(Py_VerboseFlag, p); 207 Py_VerboseFlag = add_flag(Py_VerboseFlag, p);
206 if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0') 208 if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')
207 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p); 209 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);
208 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0') 210 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0')
209 Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p); 211 Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p);
212 /* The variable is only tested for existence here; _PyRandom_Init will
213 check its value further. */
214 if ((p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0')
215 Py_HashRandomizationFlag = add_flag(Py_HashRandomizationFlag, p);
216
217 _PyRandom_Init();
210 218
211 interp = PyInterpreterState_New(); 219 interp = PyInterpreterState_New();
212 if (interp == NULL) 220 if (interp == NULL)
213 Py_FatalError("Py_Initialize: can't make first interpreter"); 221 Py_FatalError("Py_Initialize: can't make first interpreter");
214 222