Skip to content

Commit 4ce1f56

Browse files
Gax-ckuba-moo
authored andcommitted
netdevsim: Add trailing zero to terminate the string in nsim_nexthop_bucket_activity_write()
This was found by a static analyzer. We should not forget the trailing zero after copy_from_user() if we will further do some string operations, sscanf() in this case. Adding a trailing zero will ensure that the function performs properly. Fixes: c6385c0 ("netdevsim: Allow reporting activity on nexthop buckets") Signed-off-by: Zichen Xie <zichenxie0106@gmail.com> Reviewed-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20241022171907.8606-1-zichenxie0106@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2e95c43 commit 4ce1f56

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • drivers/net/netdevsim

drivers/net/netdevsim/fib.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,10 +1377,12 @@ static ssize_t nsim_nexthop_bucket_activity_write(struct file *file,
13771377

13781378
if (pos != 0)
13791379
return -EINVAL;
1380-
if (size > sizeof(buf))
1380+
if (size > sizeof(buf) - 1)
13811381
return -EINVAL;
13821382
if (copy_from_user(buf, user_buf, size))
13831383
return -EFAULT;
1384+
buf[size] = 0;
1385+
13841386
if (sscanf(buf, "%u %hu", &nhid, &bucket_index) != 2)
13851387
return -EINVAL;
13861388

0 commit comments

Comments
 (0)