Skip to content

Commit d309634

Browse files
Merge pull request #301 from seuros/fix-bluetooth-buffer-overflow
Fix critical buffer overflow vulnerability in Bluetooth REPL
2 parents de885b0 + 3f6af80 commit d309634

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

source/application/luaport.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ static volatile char repl_buffer[BLE_PREFERRED_MAX_MTU];
3939

4040
void lua_write_to_repl(uint8_t *buffer, uint8_t length)
4141
{
42+
// Bounds check to prevent buffer overflow (CVE-PENDING)
43+
// Buffer size is BLE_PREFERRED_MAX_MTU (247), length can be 0-255
44+
if (length >= BLE_PREFERRED_MAX_MTU)
45+
{
46+
length = BLE_PREFERRED_MAX_MTU - 1; // Reserve space for null terminator
47+
}
48+
4249
// Loop copy because memcpy isn't compatible with volatile
4350
for (size_t buffer_index = 0; buffer_index < length; buffer_index++)
4451
{

0 commit comments

Comments
 (0)