netdev-linux: Cast policer rate to uint64_t to avoid overflow
authorThomas Graf <tgraf@noironetworks.com>
Fri, 29 Aug 2014 10:20:21 +0000 (12:20 +0200)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Aug 2014 17:48:42 +0000 (10:48 -0700)
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@noironetworks.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/netdev-linux.c

index 840022d..e05ba60 100644 (file)
@@ -4026,7 +4026,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);