patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Kevin Traynor <ktraynor@redhat.com>
To: dev@dpdk.org
Cc: Kevin Traynor <ktraynor@redhat.com>,
	stable@dpdk.org, xuanziyang2@huawei.com,
	cloud.wangxiaoyun@huawei.com, zhouguoyang@huawei.com
Subject: [dpdk-stable] [PATCH 2/2] net/hinic: fix repeating log and length check
Date: Fri,  6 Mar 2020 12:00:47 +0000	[thread overview]
Message-ID: <20200306120047.29392-2-ktraynor@redhat.com> (raw)
In-Reply-To: <20200306120047.29392-1-ktraynor@redhat.com>

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


  reply	other threads:[~2020-03-06 12:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-06 12:00 [dpdk-stable] [PATCH 1/2] net/hinic: fix snprintf length Kevin Traynor
2020-03-06 12:00 ` Kevin Traynor [this message]
2020-03-06 12:06 ` [dpdk-stable] [PATCH v2 " Kevin Traynor
2020-03-06 12:06   ` [dpdk-stable] [PATCH v2 2/2] net/hinic: fix repeating log and length check Kevin Traynor
2020-03-09 16:00   ` [dpdk-stable] [PATCH v2 1/2] net/hinic: fix snprintf length Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200306120047.29392-2-ktraynor@redhat.com \
    --to=ktraynor@redhat.com \
    --cc=cloud.wangxiaoyun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    --cc=xuanziyang2@huawei.com \
    --cc=zhouguoyang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).