Vitezslav Samel <vitezslav(a)samel.cz> writes:
make sure interval is at least 1 (bug was made in
"tcplog_flowrate_msg(): cleanup and fix")
Reported-by: Erik K. <ummeegge(a)ipfire.org>
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
commit message say nothing about the root problem and I had to start
digging what's going on. That's not nice commit message. I'm not going
to argue about the patch as it fixes the bug, but I think, we could make
it better.
src/tcptable.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/tcptable.c b/src/tcptable.c
index a4133d9..e217b19 100644
--- a/src/tcptable.c
+++ b/src/tcptable.c
@@ -437,6 +437,8 @@ static char *tcplog_flowrate_msg(struct tcptableent *entry, char
*buf,
size_t bufsize)
{
time_t interval = time(NULL) - entry->conn_starttime;
+ if (interval < 1)
+ interval = 1;
The root problem is, that interval is 0, because of rate_print
updates happen in less then 1 sec.
time_t interval = time(NULL) - entry->conn_starttime;
and later on, we try to divide by interval, which is 0.
Now, grepping the code for time(NULL), I'm seeing bunch of same error
prone subtraction. And that leads me, that we should introduce macro or
func, which prevents it.
static inline time_t diff_time_t(time_t a, time_t b);
Ps: please always add commit sha1. something like: commit 0d55bee
("tcplog_flowrate_msg(): cleanup and fix")
--
Nikola