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 <[email protected]> Reviewed-by: Petr Machata <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2e95c43 commit 4ce1f56

File tree

1 file changed

+3
-1
lines changed
  • drivers/net/netdevsim

1 file changed

+3
-1
lines changed

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)