Skip to content

Commit b10783c

Browse files
authored
Merge pull request #15374 from 0xc0170/dev/martin.kojtal/fix-can-lenght-message
CAN: read can do only up to 8 bytes, error if more is reported
2 parents 1dd0bce + 518eb6d commit b10783c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/source/CAN.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#if DEVICE_CAN
2020

2121
#include "platform/mbed_power_mgmt.h"
22+
#include "platform/mbed_error.h"
2223

2324
namespace mbed {
2425

@@ -82,6 +83,9 @@ int CAN::read(CANMessage &msg, int handle)
8283
{
8384
lock();
8485
int ret = can_read(&_can, &msg, handle);
86+
if (msg.len > 8) {
87+
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_CAN, MBED_ERROR_CODE_READ_FAILED), "Read tried to write more than 8 bytes");
88+
}
8589
unlock();
8690
return ret;
8791
}

0 commit comments

Comments
 (0)