Changeset

6212:051974b4c900

mod_push2: Fix counting bugs If padding would be negative size, we obviously can't generate it.
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Mon, 24 Mar 2025 08:51:30 -0500
parents 6207:a1a33f0f6f6e
children 6213:811bd0872682
files mod_push2/mod_push2.lua
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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