Commit f9ded55a authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Protect against overflow when computing metrics.

Reported by Gabriel Kerneis.
parent 0ae7d995
...@@ -974,7 +974,7 @@ flushupdates(struct network *net) ...@@ -974,7 +974,7 @@ flushupdates(struct network *net)
continue; continue;
if(!route_interferes(route, net)) { if(!route_interferes(route, net)) {
metric = metric =
route->refmetric + (int)route->refmetric +
(diversity_factor * route->cost / 128) / 256 + (diversity_factor * route->cost / 128) / 256 +
route->add_metric; route->add_metric;
metric = MAX(metric, route->refmetric + 1); metric = MAX(metric, route->refmetric + 1);
......
...@@ -44,7 +44,7 @@ struct route { ...@@ -44,7 +44,7 @@ struct route {
static inline int static inline int
route_metric(const struct route *route) route_metric(const struct route *route)
{ {
int m = route->refmetric + route->cost + route->add_metric; int m = (int)route->refmetric + route->cost + route->add_metric;
return MIN(m, INFINITY); return MIN(m, INFINITY);
} }
......
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