comparison Python/sysmodule.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 febb6cf195e7
children 4a31f6b11e7a
comparison
equal deleted inserted replaced
75016:4dd5a94fd3e3 75066:f4b7ecf8a5f8
1124 {"riscos_wimp", "???"}, 1124 {"riscos_wimp", "???"},
1125 #endif 1125 #endif
1126 /* {"unbuffered", "-u"}, */ 1126 /* {"unbuffered", "-u"}, */
1127 /* {"skip_first", "-x"}, */ 1127 /* {"skip_first", "-x"}, */
1128 {"bytes_warning", "-b"}, 1128 {"bytes_warning", "-b"},
1129 {"hash_randomization", "-R"},
1129 {0} 1130 {0}
1130 }; 1131 };
1131 1132
1132 static PyStructSequence_Desc flags_desc = { 1133 static PyStructSequence_Desc flags_desc = {
1133 "sys.flags", /* name */ 1134 "sys.flags", /* name */
1134 flags__doc__, /* doc */ 1135 flags__doc__, /* doc */
1135 flags_fields, /* fields */ 1136 flags_fields, /* fields */
1136 #ifdef RISCOS 1137 #ifdef RISCOS
1138 13
1139 #else
1137 12 1140 12
1138 #else
1139 11
1140 #endif 1141 #endif
1141 }; 1142 };
1142 1143
1143 static PyObject* 1144 static PyObject*
1144 make_flags(void) 1145 make_flags(void)
1167 SetFlag(Py_RISCOSWimpFlag); 1168 SetFlag(Py_RISCOSWimpFlag);
1168 #endif 1169 #endif
1169 /* SetFlag(saw_unbuffered_flag); */ 1170 /* SetFlag(saw_unbuffered_flag); */
1170 /* SetFlag(skipfirstline); */ 1171 /* SetFlag(skipfirstline); */
1171 SetFlag(Py_BytesWarningFlag); 1172 SetFlag(Py_BytesWarningFlag);
1173 SetFlag(Py_HashRandomizationFlag);
1172 #undef SetFlag 1174 #undef SetFlag
1173 1175
1174 if (PyErr_Occurred()) { 1176 if (PyErr_Occurred()) {
1175 return NULL; 1177 return NULL;
1176 } 1178 }