Skip to content

Commit

Permalink
Merge pull request #2964 from hathach/fix-2939
Browse files Browse the repository at this point in the history
fix bug introduced by 2939, with correct offset check logic
  • Loading branch information
hathach authored Jan 25, 2025
2 parents 597446f + f6f02f1 commit 37e6f49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions examples/device/cdc_msc/src/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,14 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
(void) lun;

// out of ramdisk
if ( lba >= DISK_BLOCK_NUM ) return -1;
if ( lba >= DISK_BLOCK_NUM ) {
return -1;
}

// Check for overflow of offset + bufsize
if ( offset + bufsize >= DISK_BLOCK_SIZE ) return -1;
if ( offset + bufsize > DISK_BLOCK_SIZE ) {
return -1;
}

uint8_t const* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize);
Expand Down
9 changes: 7 additions & 2 deletions examples/device/cdc_msc_freertos/src/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,14 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
(void) lun;

// out of ramdisk
if ( lba >= DISK_BLOCK_NUM ) return -1;
if ( lba >= DISK_BLOCK_NUM ) {
return -1;
}

// Check for overflow of offset + bufsize
if ( offset + bufsize >= DISK_BLOCK_SIZE ) return -1;
if ( offset + bufsize > DISK_BLOCK_SIZE ) {
return -1;
}

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

0 comments on commit 37e6f49

Please sign in to comment.