Blame 00310-use-xml-sethashsalt-in-elementtree.patch

47f3a0b
From d24304f014c2207365f691e60c868e0877ab5aa9 Mon Sep 17 00:00:00 2001
47f3a0b
From: "Miss Islington (bot)"
47f3a0b
 <31488909+miss-islington@users.noreply.github.com>
47f3a0b
Date: Tue, 18 Sep 2018 06:14:13 -0700
47f3a0b
Subject: [PATCH 1/2] bpo-34623: Use XML_SetHashSalt in _elementtree (GH-9146)
47f3a0b
47f3a0b
The C accelerated _elementtree module now initializes hash randomization
47f3a0b
salt from _Py_HashSecret instead of libexpat's default CPRNG.
47f3a0b
47f3a0b
Signed-off-by: Christian Heimes <christian@python.org>
47f3a0b
47f3a0b
https://bugs.python.org/issue34623
47f3a0b
(cherry picked from commit cb5778f00ce48631c7140f33ba242496aaf7102b)
47f3a0b
47f3a0b
Co-authored-by: Christian Heimes <christian@python.org>
47f3a0b
---
47f3a0b
 Include/pyexpat.h                                            | 4 +++-
47f3a0b
 .../next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst   | 2 ++
47f3a0b
 Modules/_elementtree.c                                       | 5 +++++
47f3a0b
 Modules/pyexpat.c                                            | 5 +++++
47f3a0b
 4 files changed, 15 insertions(+), 1 deletion(-)
47f3a0b
 create mode 100644 Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst
47f3a0b
47f3a0b
diff --git a/Include/pyexpat.h b/Include/pyexpat.h
47f3a0b
index 44259bf6d716..07020b5dc964 100644
47f3a0b
--- a/Include/pyexpat.h
47f3a0b
+++ b/Include/pyexpat.h
47f3a0b
@@ -3,7 +3,7 @@
47f3a0b
 
47f3a0b
 /* note: you must import expat.h before importing this module! */
47f3a0b
 
47f3a0b
-#define PyExpat_CAPI_MAGIC  "pyexpat.expat_CAPI 1.0"
47f3a0b
+#define PyExpat_CAPI_MAGIC  "pyexpat.expat_CAPI 1.1"
47f3a0b
 #define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI"
47f3a0b
 
47f3a0b
 struct PyExpat_CAPI
47f3a0b
@@ -48,6 +48,8 @@ struct PyExpat_CAPI
47f3a0b
     enum XML_Status (*SetEncoding)(XML_Parser parser, const XML_Char *encoding);
47f3a0b
     int (*DefaultUnknownEncodingHandler)(
47f3a0b
         void *encodingHandlerData, const XML_Char *name, XML_Encoding *info);
47f3a0b
+    /* might be none for expat < 2.1.0 */
47f3a0b
+    int (*SetHashSalt)(XML_Parser parser, unsigned long hash_salt);
47f3a0b
     /* always add new stuff to the end! */
47f3a0b
 };
47f3a0b
 
47f3a0b
diff --git a/Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst b/Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst
47f3a0b
new file mode 100644
47f3a0b
index 000000000000..31ad92ef8582
47f3a0b
--- /dev/null
47f3a0b
+++ b/Misc/NEWS.d/next/Security/2018-09-10-16-05-39.bpo-34623.Ua9jMv.rst
47f3a0b
@@ -0,0 +1,2 @@
47f3a0b
+The C accelerated _elementtree module now initializes hash randomization
47f3a0b
+salt from _Py_HashSecret instead of libexpat's default CSPRNG.
47f3a0b
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
47f3a0b
index cf819e896c3e..cb6db7707bb6 100644
47f3a0b
--- a/Modules/_elementtree.c
47f3a0b
+++ b/Modules/_elementtree.c
47f3a0b
@@ -3259,6 +3259,11 @@ xmlparser_init(PyObject *self, PyObject *args, PyObject *kwds)
47f3a0b
         PyErr_NoMemory();
47f3a0b
         return -1;
47f3a0b
     }
47f3a0b
+    /* expat < 2.1.0 has no XML_SetHashSalt() */
47f3a0b
+    if (EXPAT(SetHashSalt) != NULL) {
47f3a0b
+        EXPAT(SetHashSalt)(self_xp->parser,
47f3a0b
+                           (unsigned long)_Py_HashSecret.expat.hashsalt);
47f3a0b
+    }
47f3a0b
 
47f3a0b
     if (target) {
47f3a0b
         Py_INCREF(target);
47f3a0b
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
47f3a0b
index 53d34459d152..824c49ba1efa 100644
47f3a0b
--- a/Modules/pyexpat.c
47f3a0b
+++ b/Modules/pyexpat.c
47f3a0b
@@ -1857,6 +1857,11 @@ MODULE_INITFUNC(void)
47f3a0b
     capi.SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler;
47f3a0b
     capi.SetEncoding = XML_SetEncoding;
47f3a0b
     capi.DefaultUnknownEncodingHandler = PyUnknownEncodingHandler;
47f3a0b
+#if XML_COMBINED_VERSION >= 20100
47f3a0b
+    capi.SetHashSalt = XML_SetHashSalt;
47f3a0b
+#else
47f3a0b
+    capi.SetHashSalt = NULL;
47f3a0b
+#endif
47f3a0b
 
47f3a0b
     /* export using capsule */
47f3a0b
     capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL);