mirror of https://github.com/ARMmbed/mbed-os.git
update USBMSD::memoryRead implementation
Fix protects underlaying block device from out-of-bound readspull/12693/head
parent
ac105f5a18
commit
89e67d3136
|
|
@ -876,24 +876,26 @@ void USBMSD::memoryRead(void)
|
||||||
|
|
||||||
n = (_length > MAX_PACKET) ? MAX_PACKET : _length;
|
n = (_length > MAX_PACKET) ? MAX_PACKET : _length;
|
||||||
|
|
||||||
if ((_addr + n) > _memory_size) {
|
if (_addr > (_memory_size - n)) {
|
||||||
n = _memory_size - _addr;
|
n = _addr < _memory_size ? _memory_size - _addr : 0;
|
||||||
_stage = ERROR;
|
_stage = ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we read an entire block
|
if (n > 0) {
|
||||||
if (!(_addr % _block_size)) {
|
// we read an entire block
|
||||||
disk_read(_page, _addr / _block_size, 1);
|
if (!(_addr % _block_size)) {
|
||||||
|
disk_read(_page, _addr / _block_size, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// write data which are in RAM
|
||||||
|
_write_next(&_page[_addr % _block_size], MAX_PACKET);
|
||||||
|
|
||||||
|
_addr += n;
|
||||||
|
_length -= n;
|
||||||
|
|
||||||
|
_csw.DataResidue -= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write data which are in RAM
|
|
||||||
_write_next(&_page[_addr % _block_size], MAX_PACKET);
|
|
||||||
|
|
||||||
_addr += n;
|
|
||||||
_length -= n;
|
|
||||||
|
|
||||||
_csw.DataResidue -= n;
|
|
||||||
|
|
||||||
if (!_length || (_stage != PROCESS_CBW)) {
|
if (!_length || (_stage != PROCESS_CBW)) {
|
||||||
_csw.Status = (_stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED;
|
_csw.Status = (_stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED;
|
||||||
_stage = (_stage == PROCESS_CBW) ? SEND_CSW : _stage;
|
_stage = (_stage == PROCESS_CBW) ? SEND_CSW : _stage;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue