Commit 4ee703d7 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Protect token bucket against overflow.

This could happen when the clock is stepped.
parent 1fef22a2
......@@ -331,7 +331,9 @@ check_bucket(struct network *net)
{
if(net->bucket > 0 && now.tv_sec > net->bucket_time) {
net->bucket =
MAX(0, (int)net->bucket - 40 * (now.tv_sec - net->bucket_time));
MIN(MAX((int)net->bucket - 40 * (now.tv_sec - net->bucket_time),
0),
400);
}
net->bucket_time = now.tv_sec;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment