Browse code

Fix potential division by zero in shaper_reset()

shaper_reset() is only ever called with "bytes_per_second" set to
a non-zero value - so the whole check "is it zero? if not, use
constrain_int() to make sure it is within bounds" is not needed ->
reduce check to just constrain_int() so even if somebody would
call shaper_reset(..., 0) it would not lead to a div-by-zero.

Found by Coverity.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <1478598242-23514-1-git-send-email-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg12942.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Gert Doering authored on 2016/11/08 18:44:02
Showing 1 changed files
... ...
@@ -75,7 +75,7 @@ bool shaper_soonest_event (struct timeval *tv, int delay);
75 75
 static inline void
76 76
 shaper_reset (struct shaper *s, int bytes_per_second)
77 77
 {
78
-  s->bytes_per_second = bytes_per_second ? constrain_int (bytes_per_second, SHAPER_MIN, SHAPER_MAX) : 0;
78
+  s->bytes_per_second = constrain_int (bytes_per_second, SHAPER_MIN, SHAPER_MAX);
79 79
 
80 80
 #ifdef SHAPER_USE_FP
81 81
   s->factor = 1000000.0 / (double)s->bytes_per_second;