From 1104a7d1e8a314ed5e5a6d2ec9d1640616e134f6 Mon Sep 17 00:00:00 2001 From: ProDrone Date: Wed, 25 Nov 2015 00:20:05 +0100 Subject: [PATCH] Prevent SBUS receivebuffer overflow To solve problem mentioned here: https://github.com/cleanflight/cleanflight/issues/1512#issuecomment-159267342 --- src/main/rx/sbus.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/rx/sbus.c b/src/main/rx/sbus.c index 230a520d002..6c0f5a7d975 100644 --- a/src/main/rx/sbus.c +++ b/src/main/rx/sbus.c @@ -152,8 +152,6 @@ static void sbusDataReceive(uint16_t c) sbusFramePosition = 0; } - sbusFrame.bytes[sbusFramePosition] = (uint8_t)c; - if (sbusFramePosition == 0) { if (c != SBUS_FRAME_BEGIN_BYTE) { return; @@ -161,16 +159,17 @@ static void sbusDataReceive(uint16_t c) sbusFrameStartAt = now; } - sbusFramePosition++; - - if (sbusFramePosition == SBUS_FRAME_SIZE) { - // endByte currently ignored - sbusFrameDone = true; + if (sbusFramePosition < SBUS_FRAME_SIZE) { + sbusFrame.bytes[sbusFramePosition++] = (uint8_t)c; + if (sbusFramePosition == SBUS_FRAME_SIZE) { + // endByte currently ignored + sbusFrameDone = true; #ifdef DEBUG_SBUS_PACKETS - debug[2] = sbusFrameTime; + debug[2] = sbusFrameTime; #endif - } else { - sbusFrameDone = false; + } else { + sbusFrameDone = false; + } } }