Skip to content

Commit

Permalink
mq: Discard messages with strings containing NUL
Browse files Browse the repository at this point in the history
Discard messages with strings containing NUL characters in the
kcidb.mq.IOSubscriber. This will help us clear a submission queue
containing a number of such messages at the moment, but should be done
inside the I/O JSON schema instead.

See kernelci/kcidb-io#79
  • Loading branch information
spbnick committed May 31, 2024
1 parent 4ef03b1 commit 2541de7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion kcidb/mq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from kcidb.misc import LIGHT_ASSERTS


# TODO: Break down the module along data type lines, but meanwhile:
# Dinna fash yersel', pylint: disable=too-many-lines


# Module's logger
LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -440,9 +444,26 @@ def decode_data(self, message_data):
Raises:
An exception in case data decoding failed.
"""
# TODO move the check to the I/O schema
def reject_nul_chars(data):
"""Raise an Exception if a string in data contains NUL"""
if isinstance(data, dict):
for key, value in data.items():
reject_nul_chars(key)
reject_nul_chars(value)
elif isinstance(data, list):
for value in data:
reject_nul_chars(value)
elif isinstance(data, str):
if '\0' in data:
raise Exception(f"NUL character in string {data!r}")
return data

return self.schema.upgrade(
self.schema.validate(
super().decode_data(message_data)
reject_nul_chars(
super().decode_data(message_data)
)
)
)

Expand Down

0 comments on commit 2541de7

Please sign in to comment.