Skip to content

Commit 19b6baa

Browse files
authored
Fix potential out of bounds access in msc_disk.c
1 parent 2495563 commit 19b6baa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/device/cdc_msc_freertos/src/msc_disk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
191191

192192
// out of ramdisk
193193
if ( lba >= DISK_BLOCK_NUM ) return -1;
194-
194+
// Check for overflow of offset + bufsize
195+
if ( offset + bufsize >= DISK_BLOCK_SIZE ) return -1;
196+
195197
uint8_t const* addr = msc_disk[lba] + offset;
196198
memcpy(buffer, addr, bufsize);
197199

0 commit comments

Comments
 (0)