Skip to content

fix bug introduced by 2939, with correct offset check logic #2964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading