Skip to contentSkip to conversation

openvswitch: meter: Use 64-bit arithmetic instead of 32-bit

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages Jan 31, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openvswitch: meter: Use 64-bit arithmetic instead of 32-bit

Add suffix LL to constant 1000 in order to give the compiler complete information about the proper arithmetic to use. Notice that this constant is used in a context that expects an expression of type long long int (64 bits, signed).

The expression (band->burst_size + band->rate) * 1000 is currently being evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1461563 ("Unintentional integer overflow")

---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/meter.c +1 -1
index 3fbfc78..04b9428 100644
@@ -488,7 +488,7 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
 		long long int max_bucket_size;
 
 		band = &meter->bands[i];
-		max_bucket_size = (band->burst_size + band->rate) * 1000;
+		max_bucket_size = (band->burst_size + band->rate) * 1000LL;
 
 		band->bucket += delta_ms * band->rate;
 		if (band->bucket > max_bucket_size)
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw

From: "Gustavo A. R. Silva" <gustavo-L1vi/[email protected]>
Date: Tue, 30 Jan 2018 22:55:33 -0600

Quoted 10 lines

Add suffix LL to constant 1000 in order to give the compiler complete information about the proper arithmetic to use. Notice that this constant is used in a context that expects an expression of type long long int (64 bits, signed).

The expression (band->burst_size + band->rate) * 1000 is currently being evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1461563 ("Unintentional integer overflow")

Applied.