[dpdk-dev] app/testpmd: fix integer overflow

Message ID 20171019093818.126232-1-jasvinder.singh@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jasvinder Singh Oct. 19, 2017, 9:38 a.m. UTC
  Fixed integer overflow by casting link_params.link_speed to
uint64_t type.

CID 195016 (#1 of 1): Unintentional integer overflow
(OVERFLOW_BEFORE_WIDEN)

Fixes: 5b590fbe09b6 ("app/testpmd: add traffic management forwarding mode")

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 app/test-pmd/tm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ferruh Yigit Oct. 23, 2017, 6:53 p.m. UTC | #1
On 10/19/2017 2:38 AM, Jasvinder Singh wrote:
> Fixed integer overflow by casting link_params.link_speed to
> uint64_t type.

Coverity Issue: 195016> Fixes: 5b590fbe09b6 ("app/testpmd: add traffic
management forwarding mode")
> 
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Ferruh Yigit Oct. 23, 2017, 6:59 p.m. UTC | #2
On 10/23/2017 11:53 AM, Ferruh Yigit wrote:
> On 10/19/2017 2:38 AM, Jasvinder Singh wrote:
>> Fixed integer overflow by casting link_params.link_speed to
>> uint64_t type.
> 
> Coverity Issue: 195016> Fixes: 5b590fbe09b6 ("app/testpmd: add traffic
> management forwarding mode")
>>
>> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> 
> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/app/test-pmd/tm.c b/app/test-pmd/tm.c
index da1adda..dd837cb 100644
--- a/app/test-pmd/tm.c
+++ b/app/test-pmd/tm.c
@@ -335,7 +335,7 @@  set_tm_hiearchy_nodes_shaper_rate(portid_t port_id, struct tm_hierarchy *h)
 	memset(&link_params, 0, sizeof(link_params));
 
 	rte_eth_link_get(port_id, &link_params);
-	tm_port_rate = link_params.link_speed * BYTES_IN_MBPS;
+	tm_port_rate = (uint64_t)link_params.link_speed * BYTES_IN_MBPS;
 
 	if (tm_port_rate > UINT32_MAX)
 		tm_port_rate = UINT32_MAX;