On Monday 27 June 2016 10:36:13 Antonio Quartulli wrote:
On Mon, Jun 13, 2016 at 01:26:31PM +0200, Sven Eckelmann wrote:
On Sunday 12 June 2016 12:14:25 Antonio Quartulli wrote:
if (orig_throughput < (gw_throughput + threshold))
goto out;
Possible overflow problem in batadv_v_gw_is_eligible. We don't know what the user will add here and what the gw_throughput is.
We already had a similar problem in the BATMAN_IV gw selection code which resulted in weird gw selections. See f63c54bba31d ("batman-adv: Avoid u32 overflow during gateway select").
Sven, correct me if I am wrong, but in f63c54bba31d we are changing the type of the variables aimed to contain the value computed by the "overflowing" operation, while in this case we have everything in a if condition: should the temporary result be implicitly casted to a larger variable as required ?
No, it isn't casted to a larger type. Yes, C has some wild casting rules but I would not be aware of an "help the programmer to avoid overflows" casting rule.
We had no other idea how to fix it in the mentioned commit. But here we can do it without casting to u64.
Kind regards, Sven