From 632e9335f35fdbc3973b2c95dcf36fec374c7adc Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 6 Jul 2022 20:35:58 +0200 Subject: [PATCH 1/2] fix broken 'a' command after broken commit c7b3817 --- DCCEXParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 14b6bfe..2cd6c4c 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -316,7 +316,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) ((address & 0x01FF) != address) // invalid address (limit 9 bits ) || ((subaddress & 0x03) != subaddress) // invalid subaddress (limit 2 bits ) || ((p[activep] & 0x01) != p[activep]) // invalid activate 0|1 - || ((onoff & 0x01) != onoff) // invalid onoff 0|1 + || (onoff > 2) // invalid onoff 0|1|2 ) break; // Honour the configuration option (config.h) which allows the command to be reversed #ifdef DCC_ACCESSORY_COMMAND_REVERSE From 76d6759d9863399a2fd7eb2d29a90a9d5c4f5c63 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 6 Jul 2022 21:12:10 +0200 Subject: [PATCH 2/2] improve parameter check for 'a' command --- DCCEXParser.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 2cd6c4c..9862902 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -308,16 +308,17 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) address=p[0]; subaddress=p[1]; activep=2; + if ((p[3] < 0) || (p[3] > 1)) // invalid onoff 0|1 + break; onoff=p[3]; } else break; // invalid no of parameters if ( - ((address & 0x01FF) != address) // invalid address (limit 9 bits ) - || ((subaddress & 0x03) != subaddress) // invalid subaddress (limit 2 bits ) - || ((p[activep] & 0x01) != p[activep]) // invalid activate 0|1 - || (onoff > 2) // invalid onoff 0|1|2 - ) break; + ((address & 0x01FF) != address) // invalid address (limit 9 bits) + || ((subaddress & 0x03) != subaddress) // invalid subaddress (limit 2 bits) + || (p[activep] > 1) || (p[activep] < 0) // invalid activate 0|1 + ) break; // Honour the configuration option (config.h) which allows the command to be reversed #ifdef DCC_ACCESSORY_COMMAND_REVERSE DCC::setAccessory(address, subaddress,p[activep]==0,onoff);