diff options
author | Christian Heimes <christian@python.org> | 2018-09-18 14:38:58 +0200 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-18 05:38:58 -0700 |
commit | cb5778f00ce48631c7140f33ba242496aaf7102b (patch) | |
tree | 9905106a1ee7ce94d9fa93b6ac395634c2f24c2f /Modules | |
parent | 0185f34ddcf07b78feb6ac666fbfd4615d26b028 (diff) | |
download | cpython-git-cb5778f00ce48631c7140f33ba242496aaf7102b.tar.gz |
bpo-34623: Use XML_SetHashSalt in _elementtree (GH-9146)
The C accelerated _elementtree module now initializes hash randomization
salt from _Py_HashSecret instead of libexpat's default CPRNG.
Signed-off-by: Christian Heimes <christian@python.org>
https://bugs.python.org/issue34623
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 5 | ||||
-rw-r--r-- | Modules/pyexpat.c | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 02781d5d89..bba6873887 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3272,6 +3272,11 @@ _elementtree_XMLParser___init___impl(XMLParserObject *self, PyObject *target, PyErr_NoMemory(); return -1; } + /* expat < 2.1.0 has no XML_SetHashSalt() */ + if (EXPAT(SetHashSalt) != NULL) { + EXPAT(SetHashSalt)(self->parser, + (unsigned long)_Py_HashSecret.expat.hashsalt); + } if (target) { Py_INCREF(target); diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index c8a01d4e08..c52079e518 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1877,6 +1877,11 @@ MODULE_INITFUNC(void) capi.SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler; capi.SetEncoding = XML_SetEncoding; capi.DefaultUnknownEncodingHandler = PyUnknownEncodingHandler; +#if XML_COMBINED_VERSION >= 20100 + capi.SetHashSalt = XML_SetHashSalt; +#else + capi.SetHashSalt = NULL; +#endif /* export using capsule */ capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL); |