From 380f3552285fbb1d463802d0b66bc815b1e6fcad Mon Sep 17 00:00:00 2001 From: Ivan Malov Date: Mon, 9 Nov 2020 14:46:06 +0300 Subject: [PATCH] net/sfc: use more robust string comparison 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 Acked-by: Andrew Rybchenko --- drivers/net/sfc/sfc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index a4fe495788..671a166402 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; } -- 2.20.1