Skip to content

Commit ad436b9

Browse files
Binary-EaterSaeed Mahameed
authored andcommitted
net/mlx5e: Correct snprintf truncation handling for fw_version buffer
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. Reported-by: David Laight <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Link: https://docs.kernel.org/core-api/kernel-api.html#c.snprintf Fixes: 41e63c2 ("net/mlx5e: Check return value of snprintf writing to fw_version buffer") Signed-off-by: Rahul Rameshbabu <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent d792e5f commit ad436b9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv,
4949
count = snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
5050
"%d.%d.%04d (%.16s)", fw_rev_maj(mdev),
5151
fw_rev_min(mdev), fw_rev_sub(mdev), mdev->board_id);
52-
if (count == sizeof(drvinfo->fw_version))
52+
if (count >= sizeof(drvinfo->fw_version))
5353
snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
5454
"%d.%d.%04d", fw_rev_maj(mdev),
5555
fw_rev_min(mdev), fw_rev_sub(mdev));

0 commit comments

Comments
 (0)