correct offset check logic

This commit is contained in:
hathach
2025-01-25 23:07:34 +07:00
parent 597446fbea
commit f6f02f1893
2 changed files with 13 additions and 4 deletions

View File

@@ -190,10 +190,14 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
(void) lun; (void) lun;
// out of ramdisk // out of ramdisk
if ( lba >= DISK_BLOCK_NUM ) return -1; if ( lba >= DISK_BLOCK_NUM ) {
return -1;
}
// Check for overflow of offset + bufsize // 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; uint8_t const* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize); memcpy(buffer, addr, bufsize);

View File

@@ -190,9 +190,14 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
(void) lun; (void) lun;
// out of ramdisk // out of ramdisk
if ( lba >= DISK_BLOCK_NUM ) return -1; if ( lba >= DISK_BLOCK_NUM ) {
return -1;
}
// Check for overflow of offset + bufsize // 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; uint8_t const* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize); memcpy(buffer, addr, bufsize);