[dpdk-dev] net/i40e: fix unsecure usage of strncpy function

Message ID 1508836958-76512-1-git-send-email-kirill.rybalchenko@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

Rybalchenko, Kirill Oct. 24, 2017, 9:22 a.m. UTC
  Use more secure snprintf function instead of strncpy
to prevent memory access violation.

Fixes: 40d1324423a4 ("net/i40e: get ddp profile protocol info")

Signed-off-by: Kirill Rybalchenko <kirill.rybalchenko@intel.com>
---
 drivers/net/i40e/rte_pmd_i40e.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson Oct. 24, 2017, 9:50 a.m. UTC | #1
On Tue, Oct 24, 2017 at 10:22:38AM +0100, Kirill Rybalchenko wrote:
> Use more secure snprintf function instead of strncpy
> to prevent memory access violation.
> 
> Fixes: 40d1324423a4 ("net/i40e: get ddp profile protocol info")
> 
> Signed-off-by: Kirill Rybalchenko <kirill.rybalchenko@intel.com>

Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>
  
Ferruh Yigit Oct. 24, 2017, 6:12 p.m. UTC | #2
On 10/24/2017 2:50 AM, Bruce Richardson wrote:
> On Tue, Oct 24, 2017 at 10:22:38AM +0100, Kirill Rybalchenko wrote:
>> Use more secure snprintf function instead of strncpy
>> to prevent memory access violation.
>>
>> Fixes: 40d1324423a4 ("net/i40e: get ddp profile protocol info")
>>
>> Signed-off-by: Kirill Rybalchenko <kirill.rybalchenko@intel.com>
> 
> Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>

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

Patch

diff --git a/drivers/net/i40e/rte_pmd_i40e.c b/drivers/net/i40e/rte_pmd_i40e.c
index 4881ea0..3df4dcc 100644
--- a/drivers/net/i40e/rte_pmd_i40e.c
+++ b/drivers/net/i40e/rte_pmd_i40e.c
@@ -1927,8 +1927,8 @@  int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
 		tlv = (struct i40e_profile_tlv_section_record *)&proto[1];
 		for (i = j = 0; i < nb_rec; j++) {
 			pinfo[j].proto_id = tlv->data[0];
-			strncpy(pinfo[j].name, (const char *)&tlv->data[1],
-				I40E_DDP_NAME_SIZE);
+			snprintf(pinfo[j].name, I40E_DDP_NAME_SIZE, "%s",
+				 (const char *)&tlv->data[1]);
 			i += tlv->len;
 			tlv = &tlv[tlv->len];
 		}