Skip to content

Commit 518eb6d

Browse files
committed
CAN: read only up to 8 bytes
If HAL implementation writes more than 8 bytes of data, error immediately. CANMessage defines only 8 bytes of data, lenght cannot be > 8. This fixes #15361 Signed-off-by: Martin Kojtal <[email protected]>
1 parent 81f40fc commit 518eb6d

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)