Skip to content

Commit 38e0f74

Browse files
tiwaidavem330
authored andcommitted
net: ionic: Use scnprintf() for avoiding potential buffer overflow
Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf(). Reviewed-by: Simon Horman <[email protected]> Acked-by: Shannon Nelson <[email protected]> Cc: "David S . Miller" <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 413ae54 commit 38e0f74

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/net/ethernet/pensando/ionic/ionic_lif.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,18 @@ static void ionic_lif_rx_mode(struct ionic_lif *lif, unsigned int rx_mode)
948948
int i;
949949
#define REMAIN(__x) (sizeof(buf) - (__x))
950950

951-
i = snprintf(buf, sizeof(buf), "rx_mode 0x%04x -> 0x%04x:",
952-
lif->rx_mode, rx_mode);
951+
i = scnprintf(buf, sizeof(buf), "rx_mode 0x%04x -> 0x%04x:",
952+
lif->rx_mode, rx_mode);
953953
if (rx_mode & IONIC_RX_MODE_F_UNICAST)
954-
i += snprintf(&buf[i], REMAIN(i), " RX_MODE_F_UNICAST");
954+
i += scnprintf(&buf[i], REMAIN(i), " RX_MODE_F_UNICAST");
955955
if (rx_mode & IONIC_RX_MODE_F_MULTICAST)
956-
i += snprintf(&buf[i], REMAIN(i), " RX_MODE_F_MULTICAST");
956+
i += scnprintf(&buf[i], REMAIN(i), " RX_MODE_F_MULTICAST");
957957
if (rx_mode & IONIC_RX_MODE_F_BROADCAST)
958-
i += snprintf(&buf[i], REMAIN(i), " RX_MODE_F_BROADCAST");
958+
i += scnprintf(&buf[i], REMAIN(i), " RX_MODE_F_BROADCAST");
959959
if (rx_mode & IONIC_RX_MODE_F_PROMISC)
960-
i += snprintf(&buf[i], REMAIN(i), " RX_MODE_F_PROMISC");
960+
i += scnprintf(&buf[i], REMAIN(i), " RX_MODE_F_PROMISC");
961961
if (rx_mode & IONIC_RX_MODE_F_ALLMULTI)
962-
i += snprintf(&buf[i], REMAIN(i), " RX_MODE_F_ALLMULTI");
962+
i += scnprintf(&buf[i], REMAIN(i), " RX_MODE_F_ALLMULTI");
963963
netdev_dbg(lif->netdev, "lif%d %s\n", lif->index, buf);
964964

965965
err = ionic_adminq_post_wait(lif, &ctx);

0 commit comments

Comments
 (0)