Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e09c26

Browse files
committed
Issue #18501, #18408: Fix expat handlers in pyexpat, don't call Python
functions if a Python exception was raised
1 parent 3fd8cbd commit 9e09c26

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Modules/pyexpat.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ static void
402402
my_CharacterDataHandler(void *userData, const XML_Char *data, int len)
403403
{
404404
xmlparseobject *self = (xmlparseobject *) userData;
405+
406+
if (PyErr_Occurred())
407+
return;
408+
405409
if (self->buffer == NULL)
406410
call_character_handler(self, data, len);
407411
else {
@@ -436,6 +440,9 @@ my_StartElementHandler(void *userData,
436440
PyObject *container, *rv, *args;
437441
int i, max;
438442

443+
if (PyErr_Occurred())
444+
return;
445+
439446
if (flush_character_buffer(self) < 0)
440447
return;
441448
/* Set max to the number of slots filled in atts[]; max/2 is
@@ -519,6 +526,8 @@ my_##NAME##Handler PARAMS {\
519526
INIT \
520527
\
521528
if (have_handler(self, NAME)) { \
529+
if (PyErr_Occurred()) \
530+
return RETURN; \
522531
if (flush_character_buffer(self) < 0) \
523532
return RETURN; \
524533
args = Py_BuildValue PARAM_FORMAT ;\
@@ -633,6 +642,9 @@ my_ElementDeclHandler(void *userData,
633642
PyObject *rv = NULL;
634643
PyObject *modelobj, *nameobj;
635644

645+
if (PyErr_Occurred())
646+
return;
647+
636648
if (flush_character_buffer(self) < 0)
637649
goto finally;
638650
modelobj = conv_content_model(model, (conv_string_to_unicode));
@@ -1125,6 +1137,9 @@ PyUnknownEncodingHandler(void *encodingHandlerData,
11251137
void *data;
11261138
unsigned int kind;
11271139

1140+
if (PyErr_Occurred())
1141+
return XML_STATUS_ERROR;
1142+
11281143
if (template_buffer[1] == 0) {
11291144
for (i = 0; i < 256; i++)
11301145
template_buffer[i] = i;

0 commit comments

Comments
 (0)