Skip to content

Commit 0159a93

Browse files
Dan Carpentermarckleinebudde
authored andcommitted
can: slcan: use scnprintf() as a hardening measure
The snprintf() function returns the number of bytes which *would* have been copied if there were no space. So, since this code does not check the return value, there if the buffer was not large enough then there would be a buffer overflow two lines later when it does: actual = sl->tty->ops->write(sl->tty, sl->xbuff, n); Use scnprintf() instead because that returns the number of bytes which were actually copied. Fixes: 52f9ac8 ("can: slcan: allow to send commands to the adapter") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/all/YsVA9KoY/ZSvNGYk@kili Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent e22c887 commit 0159a93

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/can/slcan/slcan-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd)
647647
return -ENODEV;
648648
}
649649

650-
n = snprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd);
650+
n = scnprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd);
651651
set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
652652
actual = sl->tty->ops->write(sl->tty, sl->xbuff, n);
653653
sl->xleft = n - actual;

0 commit comments

Comments
 (0)