From ce8fe756e5e6d36dcbf5d42d107a82ae6445d322 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 2 Sep 2023 17:47:31 +0200 Subject: [PATCH] Checker Lib: Check types of arguments in public API --- src/ctf_gameserver/checkerlib/lib.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ctf_gameserver/checkerlib/lib.py b/src/ctf_gameserver/checkerlib/lib.py index 934143b..b66b7f8 100644 --- a/src/ctf_gameserver/checkerlib/lib.py +++ b/src/ctf_gameserver/checkerlib/lib.py @@ -120,6 +120,9 @@ def get_flag(tick: int) -> str: current run. The returned flag can be used for both placement and checks. """ + if not isinstance(tick, int): + raise TypeError('tick must be of type int') + # Return dummy flag when launched locally if _launched_without_runner(): try: @@ -140,6 +143,9 @@ def set_flagid(data: str) -> None: Stores the Flag ID for the current team and tick. """ + if not isinstance(data, str): + raise TypeError('data must be of type str') + if not _launched_without_runner(): _send_ctrl_message({'action': 'FLAGID', 'param': data}) # Wait for acknowledgement @@ -154,6 +160,9 @@ def store_state(key: str, data: Any) -> None: service and team with the given key as an additional identifier. """ + if not isinstance(key, str): + raise TypeError('key must be of type str') + serialized_data = base64.b64encode(pickle.dumps(data)).decode('ascii') if not _launched_without_runner(): @@ -178,6 +187,9 @@ def load_state(key: str) -> Any: current service and team), None is returned. """ + if not isinstance(key, str): + raise TypeError('key must be of type str') + if not _launched_without_runner(): _send_ctrl_message({'action': 'LOAD', 'param': key}) result = _recv_ctrl_message()