File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ void Commander::run(){
32
32
received_chars[0 ] = 0 ;
33
33
rec_cnt=0 ;
34
34
}
35
+ if (rec_cnt>=MAX_COMMAND_LENGTH) { // prevent buffer overrun if message is too long
36
+ received_chars[0 ] = 0 ;
37
+ rec_cnt=0 ;
38
+ }
35
39
}
36
40
}
37
41
Original file line number Diff line number Diff line change 7
7
#include " ../common/lowpass_filter.h"
8
8
#include " commands.h"
9
9
10
+
11
+ #define MAX_COMMAND_LENGTH 20
12
+
13
+
10
14
// Commander verbose display to the user type
11
15
enum VerboseMode{
12
16
nothing = 0 , // display nothing - good for monitoring
@@ -174,7 +178,7 @@ class Commander
174
178
int call_count = 0 ;// !< number callbacks that are subscribed
175
179
176
180
// helping variable for serial communication reading
177
- char received_chars[20 ] = {0 }; // !< so far received user message - waiting for newline
181
+ char received_chars[MAX_COMMAND_LENGTH ] = {0 }; // !< so far received user message - waiting for newline
178
182
int rec_cnt = 0 ; // !< number of characters receives
179
183
180
184
// serial printing functions
You can’t perform that action at this time.
0 commit comments