Skip to content

Commit

Permalink
Prevent SBUS receivebuffer overflow
Browse files Browse the repository at this point in the history
To solve problem mentioned here: cleanflight#1512 (comment)
  • Loading branch information
ProDrone committed Nov 24, 2015
1 parent b069201 commit b1a22c6
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/rx/sbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,24 @@ static void sbusDataReceive(uint16_t c)
sbusFramePosition = 0;
}

sbusFrame.bytes[sbusFramePosition] = (uint8_t)c;

if (sbusFramePosition == 0) {
if (c != SBUS_FRAME_BEGIN_BYTE) {
return;
}
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;
}
}
}

Expand Down

0 comments on commit b1a22c6

Please sign in to comment.