DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] net/hinic: fix snprintf length
@ 2020-03-06 12:00 Kevin Traynor
  2020-03-06 12:00 ` [dpdk-dev] [PATCH 2/2] net/hinic: fix repeating log and length check Kevin Traynor
  2020-03-06 12:06 ` [dpdk-dev] [PATCH v2 1/2] net/hinic: fix snprintf length Kevin Traynor
  0 siblings, 2 replies; 5+ messages in thread
From: Kevin Traynor @ 2020-03-06 12:00 UTC (permalink / raw)
  To: dev; +Cc: Kevin Traynor, stable, xuanziyang2, cloud.wangxiaoyun, zhouguoyang

Correct length and remove unecessary brackets.

Fixes: d9ce1917941c ("net/hinic/base: add hardware operation")
Cc: stable@dpdk.org

Signed-off-by: Kevin Traynor <ktraynor@redhat.com>

---
Cc: xuanziyang2@huawei.com
Cc: cloud.wangxiaoyun@huawei.com
Cc: zhouguoyang@huawei.com
---
 drivers/net/hinic/base/hinic_pmd_hwdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c
index 8b16897ad..b6c821a2a 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwdev.c
+++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c
@@ -1391,5 +1391,5 @@ static void print_cable_info(struct hinic_link_info *info)
 
 	memcpy(tmp_vendor, info->vendor_name, sizeof(info->vendor_name));
-	snprintf(tmp_str, (sizeof(tmp_str) - 1),
+	snprintf(tmp_str, sizeof(tmp_str),
 		 "Vendor: %s, %s, %s, length: %um, max_speed: %uGbps",
 		 tmp_vendor, info->sfp_type ? "SFP" : "QSFP", port_type,
-- 
2.21.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH 2/2] net/hinic: fix repeating log and length check
  2020-03-06 12:00 [dpdk-dev] [PATCH 1/2] net/hinic: fix snprintf length Kevin Traynor
@ 2020-03-06 12:00 ` Kevin Traynor
  2020-03-06 12:06 ` [dpdk-dev] [PATCH v2 1/2] net/hinic: fix snprintf length Kevin Traynor
  1 sibling, 0 replies; 5+ messages in thread
From: Kevin Traynor @ 2020-03-06 12:00 UTC (permalink / raw)
  To: dev; +Cc: Kevin Traynor, stable, xuanziyang2, cloud.wangxiaoyun, zhouguoyang

gcc 10.0.1 reports:

../drivers/net/hinic/base/hinic_pmd_hwdev.c: In function ‘print_cable_info’:
../drivers/net/hinic/base/hinic_pmd_hwdev.c:1398:3:
warning:
‘snprintf’ argument 4 may overlap destination object ‘tmp_str’
[-Wrestrict]
 1398 |   snprintf(tmp_str + strlen(tmp_str), (sizeof(tmp_str) - 1),
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1399 |     "%s, Temperature: %u", tmp_str,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1400 |     info->cable_temp);
      |     ~~~~~~~~~~~~~~~~~

The warning is that tmp_str is in both src and dest.

Anyway, the current code is incorrect and because of the +strlen
the existing string will be repeated twice and max length
does not limit to the end of the string.

Fix by removing tmp_str from the src of snprintf and adding the
correct max length.

Fixes: d9ce1917941c ("net/hinic/base: add hardware operation")
Cc: stable@dpdk.org

Signed-off-by: Kevin Traynor <ktraynor@redhat.com>

---
Cc: xuanziyang2@huawei.com
Cc: cloud.wangxiaoyun@huawei.com
Cc: zhouguoyang@huawei.com
---
 drivers/net/hinic/base/hinic_pmd_hwdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c
index b6c821a2a..fd0292f84 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwdev.c
+++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c
@@ -1396,7 +1396,7 @@ static void print_cable_info(struct hinic_link_info *info)
 		 info->cable_length, info->cable_max_speed);
 	if (info->port_type != LINK_PORT_COPPER)
-		snprintf(tmp_str + strlen(tmp_str), (sizeof(tmp_str) - 1),
-			 "%s, Temperature: %u", tmp_str,
-			 info->cable_temp);
+		snprintf(tmp_str + strlen(tmp_str),
+			 sizeof(tmp_str) - strlen(tmp_str),
+			 ", Temperature: %u", info->cable_temp);
 
 	PMD_DRV_LOG(INFO, "Cable information: %s", tmp_str);
-- 
2.21.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH v2 1/2] net/hinic: fix snprintf length
  2020-03-06 12:00 [dpdk-dev] [PATCH 1/2] net/hinic: fix snprintf length Kevin Traynor
  2020-03-06 12:00 ` [dpdk-dev] [PATCH 2/2] net/hinic: fix repeating log and length check Kevin Traynor
@ 2020-03-06 12:06 ` Kevin Traynor
  2020-03-06 12:06   ` [dpdk-dev] [PATCH v2 2/2] net/hinic: fix repeating log and length check Kevin Traynor
  2020-03-09 16:00   ` [dpdk-dev] [dpdk-stable] [PATCH v2 1/2] net/hinic: fix snprintf length Ferruh Yigit
  1 sibling, 2 replies; 5+ messages in thread
From: Kevin Traynor @ 2020-03-06 12:06 UTC (permalink / raw)
  To: dev; +Cc: Kevin Traynor, stable, xuanziyang2, cloud.wangxiaoyun, zhouguoyang

Correct length and remove unnecessary brackets.

Fixes: d9ce1917941c ("net/hinic/base: add hardware operation")
Cc: stable@dpdk.org

Signed-off-by: Kevin Traynor <ktraynor@redhat.com>

---
v2: fix typo in commit msg

Cc: xuanziyang2@huawei.com
Cc: cloud.wangxiaoyun@huawei.com
Cc: zhouguoyang@huawei.com
---
 drivers/net/hinic/base/hinic_pmd_hwdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c
index 8b16897ad..b6c821a2a 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwdev.c
+++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c
@@ -1391,5 +1391,5 @@ static void print_cable_info(struct hinic_link_info *info)
 
 	memcpy(tmp_vendor, info->vendor_name, sizeof(info->vendor_name));
-	snprintf(tmp_str, (sizeof(tmp_str) - 1),
+	snprintf(tmp_str, sizeof(tmp_str),
 		 "Vendor: %s, %s, %s, length: %um, max_speed: %uGbps",
 		 tmp_vendor, info->sfp_type ? "SFP" : "QSFP", port_type,
-- 
2.21.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] net/hinic: fix repeating log and length check
  2020-03-06 12:06 ` [dpdk-dev] [PATCH v2 1/2] net/hinic: fix snprintf length Kevin Traynor
@ 2020-03-06 12:06   ` Kevin Traynor
  2020-03-09 16:00   ` [dpdk-dev] [dpdk-stable] [PATCH v2 1/2] net/hinic: fix snprintf length Ferruh Yigit
  1 sibling, 0 replies; 5+ messages in thread
From: Kevin Traynor @ 2020-03-06 12:06 UTC (permalink / raw)
  To: dev; +Cc: Kevin Traynor, stable, xuanziyang2, cloud.wangxiaoyun, zhouguoyang

gcc 10.0.1 reports:

../drivers/net/hinic/base/hinic_pmd_hwdev.c: In function ‘print_cable_info’:
../drivers/net/hinic/base/hinic_pmd_hwdev.c:1398:3:
warning:
‘snprintf’ argument 4 may overlap destination object ‘tmp_str’
[-Wrestrict]
 1398 |   snprintf(tmp_str + strlen(tmp_str), (sizeof(tmp_str) - 1),
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1399 |     "%s, Temperature: %u", tmp_str,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1400 |     info->cable_temp);
      |     ~~~~~~~~~~~~~~~~~

The warning is that tmp_str is in both src and dest.

Anyway, the current code is incorrect and because of the +strlen
the existing string will be repeated twice and max length
does not limit to the end of the string.

Fix by removing tmp_str from the src of snprintf and adding the
correct max length.

Fixes: d9ce1917941c ("net/hinic/base: add hardware operation")
Cc: stable@dpdk.org

Signed-off-by: Kevin Traynor <ktraynor@redhat.com>

---
Cc: xuanziyang2@huawei.com
Cc: cloud.wangxiaoyun@huawei.com
Cc: zhouguoyang@huawei.com
---
 drivers/net/hinic/base/hinic_pmd_hwdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c
index b6c821a2a..fd0292f84 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwdev.c
+++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c
@@ -1396,7 +1396,7 @@ static void print_cable_info(struct hinic_link_info *info)
 		 info->cable_length, info->cable_max_speed);
 	if (info->port_type != LINK_PORT_COPPER)
-		snprintf(tmp_str + strlen(tmp_str), (sizeof(tmp_str) - 1),
-			 "%s, Temperature: %u", tmp_str,
-			 info->cable_temp);
+		snprintf(tmp_str + strlen(tmp_str),
+			 sizeof(tmp_str) - strlen(tmp_str),
+			 ", Temperature: %u", info->cable_temp);
 
 	PMD_DRV_LOG(INFO, "Cable information: %s", tmp_str);
-- 
2.21.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [dpdk-stable] [PATCH v2 1/2] net/hinic: fix snprintf length
  2020-03-06 12:06 ` [dpdk-dev] [PATCH v2 1/2] net/hinic: fix snprintf length Kevin Traynor
  2020-03-06 12:06   ` [dpdk-dev] [PATCH v2 2/2] net/hinic: fix repeating log and length check Kevin Traynor
@ 2020-03-09 16:00   ` Ferruh Yigit
  1 sibling, 0 replies; 5+ messages in thread
From: Ferruh Yigit @ 2020-03-09 16:00 UTC (permalink / raw)
  To: Kevin Traynor, dev; +Cc: stable, xuanziyang2, cloud.wangxiaoyun, zhouguoyang

On 3/6/2020 12:06 PM, Kevin Traynor wrote:
> Correct length and remove unnecessary brackets.
> 
> Fixes: d9ce1917941c ("net/hinic/base: add hardware operation")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
> 
> ---
> v2: fix typo in commit msg
> 

For series,
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Series applied to dpdk-next-net/master, thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-09 16:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 12:00 [dpdk-dev] [PATCH 1/2] net/hinic: fix snprintf length Kevin Traynor
2020-03-06 12:00 ` [dpdk-dev] [PATCH 2/2] net/hinic: fix repeating log and length check Kevin Traynor
2020-03-06 12:06 ` [dpdk-dev] [PATCH v2 1/2] net/hinic: fix snprintf length Kevin Traynor
2020-03-06 12:06   ` [dpdk-dev] [PATCH v2 2/2] net/hinic: fix repeating log and length check Kevin Traynor
2020-03-09 16:00   ` [dpdk-dev] [dpdk-stable] [PATCH v2 1/2] net/hinic: fix snprintf length Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).