Lua CAN bus index: let's fail if invalid value specified

This commit is contained in:
rusefi 2022-08-21 22:31:52 -04:00
parent 3bc2bf63f4
commit 26eda07424
4 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "pch.h"
#include "can_filter.h"
#include "can_hw.h"
static constexpr size_t maxFilterCount = 48;
@ -26,6 +27,10 @@ void resetLuaCanRx() {
}
void addLuaCanRxFilter(int32_t eid, uint32_t mask, int bus, int callback) {
if (bus != ANY_BUS) {
assertHwCanBusIndex(bus);
}
if (filterCount >= maxFilterCount) {
firmwareError(OBD_PCM_Processor_Fault, "Too many Lua CAN RX filters");
}

View File

@ -334,3 +334,10 @@ bool getIsCanEnabled(void) {
}
#endif /* EFI_CAN_SUPPORT */
void assertHwCanBusIndex(const size_t busIndex) {
// 'size_t' is an unsigned type so we are never below zero here
if (busIndex > 1) {
firmwareError(CUSTOM_OBD_70, "Invalid HW CAN bus index %d", busIndex);
}
}

View File

@ -19,7 +19,11 @@ void stopCanPins();
void startCanPins();
void enableFrankensoCan();
bool getIsCanEnabled(void);
#if EFI_TUNER_STUDIO
void postCanState();
#endif /* EFI_TUNER_STUDIO */
#endif /* EFI_CAN_SUPPORT */
void assertHwCanBusIndex(const size_t busIndex);

View File

@ -34,6 +34,7 @@ CPPSRC += $(ALLCPPSRC) \
$(DEVELOPMENT_DIR)/engine_sniffer.cpp \
$(CONSOLE_COMMON_SRC_CPP) \
$(PROJECT_DIR)/config/boards/hellen/hellen_board_id.cpp \
$(PROJECT_DIR)/hw_layer/drivers/can/can_hw.cpp \
$(PROJECT_DIR)/../unit_tests/logicdata.cpp \
$(PROJECT_DIR)/../unit_tests/native/native_impl.cpp \
$(PROJECT_DIR)/../unit_tests/main.cpp \