Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mq: Discard messages with strings containing NUL #525

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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