diff --git a/sarracenia/flow/__init__.py b/sarracenia/flow/__init__.py index 3cd0db90a..f54e5baab 100644 --- a/sarracenia/flow/__init__.py +++ b/sarracenia/flow/__init__.py @@ -2829,6 +2829,10 @@ def do_send(self): self.reject(msg, 422, f"new_file message field missing, do not know name of file to write. skipping." ) continue + if self.o.fileSizeMax > 0 and msg['size'] > self.o.fileSizeMax: + self.reject(msg, 413, f"Payload Too Large {msg.getIDStr()}") + continue + # weed out non-file transfer operations that are configured to not be done. if 'fileOp' in msg: if ('directory' in msg['fileOp']) and ('remove' in msg['fileOp']) and ( 'rmdir' not in self.o.fileEvents ): diff --git a/sarracenia/flowcb/send/am.py b/sarracenia/flowcb/send/am.py index 70b10f1ad..002e99371 100755 --- a/sarracenia/flowcb/send/am.py +++ b/sarracenia/flowcb/send/am.py @@ -53,6 +53,11 @@ def __init__(self, options): self.o.add_option('MaxBulLen', 'count', 32768) + # Get a default value if not set + if self.o.fileSizeMax <= 0: + self.o.fileSizeMax = self.o.MaxBulLen + logger.warning(f"Attributing fileSizeMax, MaxBulLen value : {self.o.MaxBulLen} bytes max") + # Initialise socket ## Create a TCP/IP socket self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -80,8 +85,9 @@ def wrapbulletin(self, sarra_msg): header = strdata[0:size] # Step out of the function if the bulletin size is too big - if len(strdata) > self.o.MaxBulLen: - raise Exception(f"Bulletin length too long. Bulletin limit length: {self.o.MaxBulLen}. Latest bulletin length: {len(strdata)}. Path to bulletin: {msg_path}") + if len(strdata) > self.o.fileSizeMax: + logger.error(f"Bulletin length too long. Bulletin limit length: {self.o.fileSizeMax}. Latest bulletin length: {len(strdata)}. Path to bulletin: {msg_path}") + return None ## Attach rest of header with NULLs (if not long enough) nulheader = ['\0' for _ in range(size)] @@ -145,6 +151,10 @@ def send(self, bulletin): try: self.packed_bulletin = self.wrapbulletin(bulletin) + # We don't want to send nothing. + if self.packed_bulletin == None: + return False + while True: try: bytesSent = self.s.send(self.packed_bulletin)