Skip to content

Commit 5a9f092

Browse files
committed
prevent buffer overrun when commands sent are too long
1 parent ebd4906 commit 5a9f092

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/communication/Commander.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ void Commander::run(){
3232
received_chars[0] = 0;
3333
rec_cnt=0;
3434
}
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+
}
3539
}
3640
}
3741

src/communication/Commander.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "../common/lowpass_filter.h"
88
#include "commands.h"
99

10+
11+
#define MAX_COMMAND_LENGTH 20
12+
13+
1014
// Commander verbose display to the user type
1115
enum VerboseMode{
1216
nothing = 0, // display nothing - good for monitoring
@@ -174,7 +178,7 @@ class Commander
174178
int call_count = 0;//!< number callbacks that are subscribed
175179

176180
// 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
178182
int rec_cnt = 0; //!< number of characters receives
179183

180184
// serial printing functions

0 commit comments

Comments
 (0)