net/sfc: use more robust string comparison
authorIvan Malov <ivan.malov@oktetlabs.ru>
Mon, 9 Nov 2020 11:46:06 +0000 (14:46 +0300)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Nov 2020 18:43:25 +0000 (19:43 +0100)
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>
drivers/net/sfc/sfc.c

index a4fe495..671a166 100644 (file)
@@ -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;
 }