Issue #18408: Fix pyexpat.ParserCreate()
Check if XML_ParserCreate_MM() failed (ex: MemoryError) before using self->itself.
This commit is contained in:
parent
4958f714bd
commit
54b2d2ec69
|
@ -1180,9 +1180,19 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
|
||||||
self->in_callback = 0;
|
self->in_callback = 0;
|
||||||
self->ns_prefixes = 0;
|
self->ns_prefixes = 0;
|
||||||
self->handlers = NULL;
|
self->handlers = NULL;
|
||||||
|
self->intern = intern;
|
||||||
|
Py_XINCREF(self->intern);
|
||||||
|
PyObject_GC_Track(self);
|
||||||
|
|
||||||
/* namespace_separator is either NULL or contains one char + \0 */
|
/* namespace_separator is either NULL or contains one char + \0 */
|
||||||
self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler,
|
self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler,
|
||||||
namespace_separator);
|
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)
|
#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
|
/* 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
|
* 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,
|
XML_SetHashSalt(self->itself,
|
||||||
(unsigned long)_Py_HashSecret.prefix);
|
(unsigned long)_Py_HashSecret.prefix);
|
||||||
#endif
|
#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_SetUserData(self->itself, (void *)self);
|
||||||
XML_SetUnknownEncodingHandler(self->itself,
|
XML_SetUnknownEncodingHandler(self->itself,
|
||||||
(XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);
|
(XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);
|
||||||
|
|
Loading…
Reference in New Issue