diff --git a/src/communication/Commander.cpp b/src/communication/Commander.cpp index 2bfa3f33..ddd67b83 100644 --- a/src/communication/Commander.cpp +++ b/src/communication/Commander.cpp @@ -47,6 +47,10 @@ void Commander::run(Stream& serial, char eol){ received_chars[0] = 0; rec_cnt=0; } + if (rec_cnt>=MAX_COMMAND_LENGTH) { // prevent buffer overrun if message is too long + received_chars[0] = 0; + rec_cnt=0; + } } com_port = tmp; // reset the instance to the internal value diff --git a/src/communication/Commander.h b/src/communication/Commander.h index 6067e4d6..aaa55b11 100644 --- a/src/communication/Commander.h +++ b/src/communication/Commander.h @@ -7,6 +7,10 @@ #include "../common/lowpass_filter.h" #include "commands.h" + +#define MAX_COMMAND_LENGTH 20 + + // Commander verbose display to the user type enum VerboseMode{ nothing = 0, // display nothing - good for monitoring @@ -178,7 +182,7 @@ class Commander int call_count = 0;//!< number callbacks that are subscribed // helping variable for serial communication reading - char received_chars[20] = {0}; //!< so far received user message - waiting for newline + char received_chars[MAX_COMMAND_LENGTH] = {0}; //!< so far received user message - waiting for newline int rec_cnt = 0; //!< number of characters receives // serial printing functions