net/hinic: fix repeating cable log and length check
authorKevin Traynor <ktraynor@redhat.com>
Fri, 6 Mar 2020 12:06:52 +0000 (12:06 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 18 Mar 2020 09:21:42 +0000 (10:21 +0100)
commitece8e4c262f8091361e9b261c4e4c6257d2b8bda
tree36a4832e52c5988de284ebd39ba3fa0474673094
parent9c84acab47e8eee2736b70edc54f36bb1bc17c57
net/hinic: fix repeating cable log and length check

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>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
drivers/net/hinic/base/hinic_pmd_hwdev.c