summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-15 15:15:57 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-15 15:15:57 (GMT)
commit54b2d2ec69c7fee3718b909ab2e61ce51a176437 (patch)
tree9a6494e482602cdecb13e52bd96a83aab825a3b1 /Modules
parent4958f714bde917c8dc1b087932f44608b4634452 (diff)
downloadcpython-54b2d2ec69c7fee3718b909ab2e61ce51a176437.zip
cpython-54b2d2ec69c7fee3718b909ab2e61ce51a176437.tar.gz
cpython-54b2d2ec69c7fee3718b909ab2e61ce51a176437.tar.bz2
Issue #18408: Fix pyexpat.ParserCreate()
Check if XML_ParserCreate_MM() failed (ex: MemoryError) before using self->itself.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/pyexpat.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index f04620f..8c9a07b 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1180,9 +1180,19 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
self->in_callback = 0;
self->ns_prefixes = 0;
self->handlers = NULL;
+ self->intern = intern;
+ Py_XINCREF(self->intern);
+ PyObject_GC_Track(self);
+
/* namespace_separator is either NULL or contains one char + \0 */
self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler,
namespace_separator);
+ if (self->itself == NULL) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "XML_ParserCreate failed");
+ Py_DECREF(self);
+ return NULL;
+ }
#if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT)
/* This feature was added upstream in libexpat 2.1.0. Our expat copy
* has a backport of this feature where we also define XML_HAS_SET_HASH_SALT
@@ -1190,15 +1200,6 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
XML_SetHashSalt(self->itself,
(unsigned long)_Py_HashSecret.prefix);
#endif
- self->intern = intern;
- Py_XINCREF(self->intern);
- PyObject_GC_Track(self);
- if (self->itself == NULL) {
- PyErr_SetString(PyExc_RuntimeError,
- "XML_ParserCreate failed");
- Py_DECREF(self);
- return NULL;
- }
XML_SetUserData(self->itself, (void *)self);
XML_SetUnknownEncodingHandler(self->itself,
(XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);