Skip to content

Commit b13559b

Browse files
Binary-EaterSaeed Mahameed
authored andcommitted
net/mlx5e: Correct snprintf truncation handling for fw_version buffer used by representors
snprintf returns the length of the formatted string, excluding the trailing null, without accounting for truncation. This means that is the return value is greater than or equal to the size parameter, the fw_version string was truncated. Link: https://docs.kernel.org/core-api/kernel-api.html#c.snprintf Fixes: 1b2bd0c ("net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors") Signed-off-by: Rahul Rameshbabu <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent ad436b9 commit b13559b

File tree

1 file changed

+1
-1
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+1
-1
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void mlx5e_rep_get_drvinfo(struct net_device *dev,
7878
count = snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
7979
"%d.%d.%04d (%.16s)", fw_rev_maj(mdev),
8080
fw_rev_min(mdev), fw_rev_sub(mdev), mdev->board_id);
81-
if (count == sizeof(drvinfo->fw_version))
81+
if (count >= sizeof(drvinfo->fw_version))
8282
snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
8383
"%d.%d.%04d", fw_rev_maj(mdev),
8484
fw_rev_min(mdev), fw_rev_sub(mdev));

0 commit comments

Comments
 (0)