From 0cb33438d0b52dd39ce67107613bc18fb7c613c1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 26 Sep 2017 17:48:33 +0100 Subject: mod_limits: Handle fractional outstanding balance values (caused by e3f7b6fa46ba) Fractional values were passed to string.sub() when doing buffer manipulations, and caused random bytes to be skipped in the stream. --- plugins/mod_limits.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins/mod_limits.lua') diff --git a/plugins/mod_limits.lua b/plugins/mod_limits.lua index 2a6ee8a2..66341618 100644 --- a/plugins/mod_limits.lua +++ b/plugins/mod_limits.lua @@ -4,6 +4,7 @@ module:set_global(); local filters = require "util.filters"; local throttle = require "util.throttle"; local timer = require "util.timer"; +local ceil = math.ceil; local limits_cfg = module:get_option("limits", {}); local limits_resolution = module:get_option_number("limits_resolution", 1); @@ -55,6 +56,7 @@ function default_filter_set.bytes_in(bytes, session) local ok, balance, outstanding = throttle:poll(#bytes, true); if not ok then session.log("debug", "Session over rate limit (%d) with %d (by %d), pausing", throttle.max, #bytes, outstanding); + outstanding = ceil(outstanding); session.conn:pause(); -- Read no more data from the connection until there is no outstanding data local outstanding_data = bytes:sub(-outstanding); bytes = bytes:sub(1, #bytes-outstanding); -- cgit v1.2.3