# HG changeset patch # User Stephen Paul Weber # Date 1742824290 18000 # Node ID 051974b4c900c311167bef6974e0ea8deeb61e05 # Parent a1a33f0f6f6e37026cc6ddbafc551bd3572f1f6b mod_push2: Fix counting bugs If padding would be negative size, we obviously can't generate it. diff -r a1a33f0f6f6e -r 051974b4c900 mod_push2/mod_push2.lua --- a/mod_push2/mod_push2.lua Sun Mar 16 21:56:25 2025 +0100 +++ b/mod_push2/mod_push2.lua Mon Mar 24 08:51:30 2025 -0500 @@ -222,7 +222,7 @@ end if string.len(envelope_bytes) > max_data_size then local body = stanza:get_child_text("body") - if string.len(body) > 50 then + if body and string.len(body) > 50 then stanza_clone:maptags(function(el) if el.name == "body" then return nil @@ -251,8 +251,9 @@ end) envelope_bytes = tostring(envelope) end - if string.len(envelope_bytes) < max_data_size/2 then - envelope:text_tag("rpad", base64.encode(random.bytes(math.min(150, max_data_size/3 - string.len(envelope_bytes))))) + local padding_size = math.min(150, max_data_size/3 - string.len(envelope_bytes)) + if padding_size > 0 then + envelope:text_tag("rpad", base64.encode(random.bytes(padding_size))) envelope_bytes = tostring(envelope) end