diff mbox series

IB/mlx4: Fix the size of a buffer in add_port_entries()

Message ID 0bb1443eb47308bc9be30232cc23004c4d4cf43e.1695448530.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Headers show
Series IB/mlx4: Fix the size of a buffer in add_port_entries() | expand

Commit Message

Christophe JAILLET Sept. 23, 2023, 5:55 a.m. UTC
In order to be sure that 'buff' is never truncated, its size should be
12, not 11.

When building with W=1, this fixes the following warnings:

  drivers/infiniband/hw/mlx4/sysfs.c: In function ‘add_port_entries’:
  drivers/infiniband/hw/mlx4/sysfs.c:268:34: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
    268 |                 sprintf(buff, "%d", i);
        |                                  ^
  drivers/infiniband/hw/mlx4/sysfs.c:268:17: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 11
    268 |                 sprintf(buff, "%d", i);
        |                 ^~~~~~~~~~~~~~~~~~~~~~
  drivers/infiniband/hw/mlx4/sysfs.c:286:34: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
    286 |                 sprintf(buff, "%d", i);
        |                                  ^
  drivers/infiniband/hw/mlx4/sysfs.c:286:17: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 11
    286 |                 sprintf(buff, "%d", i);
        |                 ^~~~~~~~~~~~~~~~~~~~~~

Fixes: c1e7e466120b ("IB/mlx4: Add iov directory in sysfs under the ib device")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
We could also use snprintf(), but it would just lead to a bigger patch for
no additional benefit.
This patch is already certainly more a clean-up than a fix.
---
 drivers/infiniband/hw/mlx4/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Leon Romanovsky Sept. 23, 2023, 6:54 p.m. UTC | #1
On Sat, 23 Sep 2023 07:55:56 +0200, Christophe JAILLET wrote:
> In order to be sure that 'buff' is never truncated, its size should be
> 12, not 11.
> 
> When building with W=1, this fixes the following warnings:
> 
>   drivers/infiniband/hw/mlx4/sysfs.c: In function ‘add_port_entries’:
>   drivers/infiniband/hw/mlx4/sysfs.c:268:34: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
>     268 |                 sprintf(buff, "%d", i);
>         |                                  ^
>   drivers/infiniband/hw/mlx4/sysfs.c:268:17: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 11
>     268 |                 sprintf(buff, "%d", i);
>         |                 ^~~~~~~~~~~~~~~~~~~~~~
>   drivers/infiniband/hw/mlx4/sysfs.c:286:34: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
>     286 |                 sprintf(buff, "%d", i);
>         |                                  ^
>   drivers/infiniband/hw/mlx4/sysfs.c:286:17: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 11
>     286 |                 sprintf(buff, "%d", i);
>         |                 ^~~~~~~~~~~~~~~~~~~~~~
> 
> [...]

Applied, thanks!

[1/1] IB/mlx4: Fix the size of a buffer in add_port_entries()
      https://git.kernel.org/rdma/rdma/c/d7f393430a17c2

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mlx4/sysfs.c b/drivers/infiniband/hw/mlx4/sysfs.c
index 24ee79aa2122..88f534cf690e 100644
--- a/drivers/infiniband/hw/mlx4/sysfs.c
+++ b/drivers/infiniband/hw/mlx4/sysfs.c
@@ -223,7 +223,7 @@  void del_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
 static int add_port_entries(struct mlx4_ib_dev *device, int port_num)
 {
 	int i;
-	char buff[11];
+	char buff[12];
 	struct mlx4_ib_iov_port *port = NULL;
 	int ret = 0 ;
 	struct ib_port_attr attr;