[2/2] net/sfc: use more robust string comparison

Message ID 20201109114606.23876-2-ivan.malov@oktetlabs.ru (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [1/2] common/sfc_efx/base: apply MCDI version/boot clarity fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Ivan Malov Nov. 9, 2020, 11:46 a.m. UTC
  When it comes to comparing HW switch ID strings,
use strncmp to avoid reading past the buffer.

Fixes: e86b48aa46d4 ("net/sfc: add HW switch ID helpers")

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
 drivers/net/sfc/sfc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Andrew Rybchenko Nov. 9, 2020, 11:49 a.m. UTC | #1
On 11/9/20 2:46 PM, Ivan Malov wrote:
> When it comes to comparing HW switch ID strings,
> use strncmp to avoid reading past the buffer.
> 
> Fixes: e86b48aa46d4 ("net/sfc: add HW switch ID helpers")
> 
> Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>

Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  

Patch

diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index a4fe49578..671a16640 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -1301,5 +1301,6 @@  bool
 sfc_hw_switch_ids_equal(const struct sfc_hw_switch_id *left,
 			const struct sfc_hw_switch_id *right)
 {
-	return strcmp(left->board_sn, right->board_sn) == 0;
+	return strncmp(left->board_sn, right->board_sn,
+		       sizeof(left->board_sn)) == 0;
 }