From 79e33ab2a5963c421ecf021ac208408b4c74ef43 Mon Sep 17 00:00:00 2001 From: ole00 Date: Tue, 19 Mar 2024 20:41:43 +0000 Subject: [PATCH] PC app: fix serial port read buffer overflow Overflow happened when verbose printouts were enabled in the Arduino sketch. --- src_pc/afterburner.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src_pc/afterburner.c b/src_pc/afterburner.c index e825dc2..33ba181 100644 --- a/src_pc/afterburner.c +++ b/src_pc/afterburner.c @@ -50,7 +50,7 @@ To compile: gcc -g3 -O0 -o afterburner afterburner.c #define VERSION "v.0.5.8" -#define MAX_LINE 1024 +#define MAX_LINE (16*1024) #define MAXFUSES 30000 #define GALBUFSIZE 65536 @@ -723,6 +723,10 @@ static int waitForSerialPrompt(char* buf, int bufSize, int maxDelay) { } else { buf += readSize; bufSize -= readSize; + if (bufSize <= 0) { + printf("ERROR: serial port read buffer is too small!\nAre you dumping large amount of data?\n"); + return -1; + } } if (printSerialWhileWaiting) { bufPrint = printBuffer(bufPrint, readSize); @@ -771,6 +775,9 @@ static int sendLine(char* buf, int bufSize, int maxDelay) { } total = waitForSerialPrompt(obuf, bufSize, (maxDelay < 0) ? 6 : maxDelay); + if (total < 0) { + return total; + } obuf[total] = 0; obuf = stripPrompt(obuf); if (verbose) {