mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 20:44:39 +08:00
drivers/can: protect against write buffer overrun
The message size is being calculated from the message itself. If application sets value cm_hdr.ch_dlc greater than buflen (that is size_t) then calculation in while condition underflows and multiple messages are attempted to be sent. This check prevents that by verifying that the message size that was encoded in the dlc is not greater than indicated size of the buffer. Signed-off-by: Karel Kočí <cynerd@email.cz>
This commit is contained in:
@@ -679,6 +679,13 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer,
|
||||
nbytes = can_dlc2bytes(msg->cm_hdr.ch_dlc);
|
||||
msglen = CAN_MSGLEN(nbytes);
|
||||
|
||||
if (nsent + msglen > buflen)
|
||||
{
|
||||
/* Do not send message if not fully passed. */
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
can_add_sendnode(sender, msg, msglen);
|
||||
|
||||
/* Increment the number of bytes that were sent */
|
||||
|
||||
Reference in New Issue
Block a user