From 030cb654b4010abba02a1961a94f120f64bc9386 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 23 Jun 2020 20:00:34 +0100 Subject: [PATCH] Accessory command validations --- DCC.cpp | 5 +++++ DCCEXParser.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DCC.cpp b/DCC.cpp index 433911d..f776b04 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -81,6 +81,11 @@ static void DCC::setFn( int cab, byte functionNumber, bool on) { } void DCC::setAccessory(int address, byte number, bool activate) { + // use masks to detect wrong values and do nothing + if(address != address & 511) + return; + if(number != number & 3) + return; byte b[2]; b[0] = address % 64 + 128; // first byte is of the form 10AAAAAA, where AAAAAA represent 6 least signifcant bits of accessory address diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 77faf0a..4bfed24 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -133,7 +133,8 @@ void DCCEXParser::parse(Print & stream, const char *com) { break; case 'a': // ACCESSORY - DCC::setAccessory(p[0],p[1],p[2]); + if(p[2] != p[2] & 1) return; + DCC::setAccessory(p[0],p[1],p[2]==1); return; case 'T': // TURNOUT