[ovs-dev] [PATCH] netdev-linux: Cast policer rate to uint64_t to avoid overflow

Thomas Graf tgraf at noironetworks.com
Fri Aug 29 10:20:21 UTC 2014


tc_fill_rate() takes a 64bit int, casting kbits_rate from int
to uint64_t avoids a possible overflow when translating from
kbits to bytes.

Signed-off-by: Thomas Graf <tgraf at noironetworks.com>
---
 lib/netdev-linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index e50392a..b4a768d 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -4045,7 +4045,7 @@ tc_add_policer(struct netdev *netdev, int kbits_rate, int kbits_burst)
     memset(&tc_police, 0, sizeof tc_police);
     tc_police.action = TC_POLICE_SHOT;
     tc_police.mtu = mtu;
-    tc_fill_rate(&tc_police.rate, (kbits_rate * 1000)/8, mtu);
+    tc_fill_rate(&tc_police.rate, ((uint64_t) kbits_rate * 1000)/8, mtu);
     tc_police.burst = tc_bytes_to_ticks(tc_police.rate.rate,
                                         kbits_burst * 1024);
 
-- 
1.9.3




More information about the dev mailing list