Skip to content

Commit 597446f

Browse files
authored
Merge pull request #2939 from PwnVerse/patch-1
Fix potential out of bounds access in msc_disk.c
2 parents feb41ee + 19d28a9 commit 597446f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

examples/device/cdc_msc/src/msc_disk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
192192
// out of ramdisk
193193
if ( lba >= DISK_BLOCK_NUM ) return -1;
194194

195+
// Check for overflow of offset + bufsize
196+
if ( offset + bufsize >= DISK_BLOCK_SIZE ) return -1;
197+
195198
uint8_t const* addr = msc_disk[lba] + offset;
196199
memcpy(buffer, addr, bufsize);
197200

examples/device/cdc_msc_freertos/src/msc_disk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ 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+
// Check for overflow of offset + bufsize
195+
if ( offset + bufsize >= DISK_BLOCK_SIZE ) return -1;
194196

195197
uint8_t const* addr = msc_disk[lba] + offset;
196198
memcpy(buffer, addr, bufsize);

0 commit comments

Comments
 (0)