From 8251de682ac0c301dda31d8c480870ec3f2683f6 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Wed, 20 Dec 2017 12:44:54 +0100 Subject: [PATCH] gluon-radv-filterd: Fix integer underflow with low TQs The TQ of the best router can be lower than the hysteresis_thresh. The check could cause an integer underflow which then causes an election which is not necessary. This can be avoided by reordering the check slightly and only substracting values which will not cause underflows. Signed-off-by: Sven Eckelmann --- package/gluon-radv-filterd/src/gluon-radv-filterd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package/gluon-radv-filterd/src/gluon-radv-filterd.c b/package/gluon-radv-filterd/src/gluon-radv-filterd.c index 5cd00a59..3cb2d7a5 100644 --- a/package/gluon-radv-filterd/src/gluon-radv-filterd.c +++ b/package/gluon-radv-filterd/src/gluon-radv-filterd.c @@ -538,7 +538,14 @@ static bool election_required(void) if (!G.best_router) return true; - return G.best_router->tq < G.max_tq - G.hysteresis_thresh; + /* should never happen. G.max_tq also contains G.best_router->tq */ + if (G.max_tq < G.best_router->tq) + return false; + + if ((G.max_tq - G.best_router->tq) <= G.hysteresis_thresh) + return false; + + return true; } static void update_ebtables(void) {