From 3d0b09e2e22769d6795387f8d56a1f0a7af3cbe5 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 14 Dec 2024 15:52:51 +0100 Subject: [PATCH] xmlstream: prevent stanza parsing from crashing the whole thing If an error happened while parsing a stanza, it would bring the whole program down and disconnect instead of logging an error. And the DEBUG log happened afterwards (so, never). --- slixmpp/xmlstream/xmlstream.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index ed1c17a2..5192bf73 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -1414,7 +1414,11 @@ class XMLStream(asyncio.BaseProtocol): # Convert the raw XML object into a stanza object. If no registered # stanza type applies, a generic StanzaBase stanza will be used. - stanza: Optional[StanzaBase] = self._build_stanza(xml) + try: + stanza: Optional[StanzaBase] = self._build_stanza(xml) + except Exception as exc: + log.exception("Unable to parse stanza: %s,\n%s", exc, xml) + stanza = None for filter in self.__filters['in']: if stanza is not None: filter = cast(SyncFilter, filter)