more hardening

This commit is contained in:
Riccardo Balbo 2025-02-22 12:27:22 +00:00
commit 686eda82b7

View file

@ -6,8 +6,8 @@ ENABLE_HARDENING = True
def panic(reason:str): def panic(reason:str):
if not ENABLE_HARDENING: if not ENABLE_HARDENING:
return return
logger.error(f"hardening error: {reason}") logger.error(f"hardening: {reason}")
raise ValueError(f"hardening error: {reason}") raise ValueError(f"hardening: {reason}")
# Throw if string contains any non-printable characters # Throw if string contains any non-printable characters
def assert_printable(v:str): def assert_printable(v:str):
@ -81,7 +81,7 @@ def assert_valid_timestamp_seconds(v:int):
if not ENABLE_HARDENING: if not ENABLE_HARDENING:
return return
assert_valid_int(v) assert_valid_int(v)
if v < 0: if v < 0 and v != -1:
panic("timestamp is negative") panic("timestamp is negative")
if v > 2**31: if v > 2**31:
panic("timestamp is too high") panic("timestamp is too high")