Skip to content

Commit bfadfc5

Browse files
sensei-hackerclaude
andcommitted
Fix CRSF buffer overflow and dashboard sizeof bug
CRSF buffer overflow (rx/crsf.c): - fullFrameLength computed from untrusted frameLength field - Malformed packet with large frameLength could overflow crsfFrame.bytes[] - Added bounds check against CRSF_FRAME_SIZE_MAX before writing Dashboard sizeof bug (io/dashboard.c): - tickerCharacters was a pointer, so sizeof() returned pointer size (4/8) - On 64-bit systems, TICKER_CHARACTER_COUNT was 8 instead of 4 - Could read past end of string when indexing tickerCharacters[] - Changed to array declaration and sizeof()-1 for correct count 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4720f62 commit bfadfc5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/io/dashboard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ static const char* const gpsFixTypeText[] = {
172172
"3D"
173173
};
174174

175-
static const char* tickerCharacters = "|/-\\"; // use 2/4/8 characters so that the divide is optimal.
176-
#define TICKER_CHARACTER_COUNT (sizeof(tickerCharacters) / sizeof(char))
175+
static const char tickerCharacters[] = "|/-\\"; // use 2/4/8 characters so that the divide is optimal.
176+
#define TICKER_CHARACTER_COUNT (sizeof(tickerCharacters) - 1)
177177

178178
static timeUs_t nextPageAt;
179179
static bool forcePageChange;

src/main/rx/crsf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ STATIC_UNIT_TESTED void crsfDataReceive(uint16_t c, void *rxCallbackData)
160160
// full frame length includes the length of the address and framelength fields
161161
const int fullFrameLength = crsfFramePosition < 3 ? 5 : crsfFrame.frame.frameLength + CRSF_FRAME_LENGTH_ADDRESS + CRSF_FRAME_LENGTH_FRAMELENGTH;
162162

163+
if (fullFrameLength > CRSF_FRAME_SIZE_MAX) {
164+
crsfFramePosition = 0;
165+
return;
166+
}
167+
163168
if (crsfFramePosition < fullFrameLength) {
164169
crsfFrame.bytes[crsfFramePosition++] = (uint8_t)c;
165170
crsfFrameDone = crsfFramePosition < fullFrameLength ? false : true;

0 commit comments

Comments
 (0)