Do sanity checks of input values for Driver_Read.

This commit is contained in:
Stephen Heumann 2018-08-15 21:56:36 -05:00
parent 8532c14ee1
commit 3f3c14b8a1
1 changed files with 15 additions and 1 deletions

View File

@ -311,12 +311,26 @@ static Word DoRead(struct GSOSDP *dp) {
return drvrOffLine;
}
//TODO check size is multiple of a block
//TODO disk-switched logic
unsigned long readStart = dp->blockNum * dp->blockSize + sess->dataOffset;
unsigned long readEnd = readStart + dp->requestCount - 1;
/* Do sanity checks of input values */
if (dp->blockSize == 0) {
dp->transferCount = 0;
return drvrBadBlock;
}
if (dp->requestCount % dp->blockSize != 0) {
dp->transferCount = 0;
return drvrBadCount;
}
if (readEnd < readStart || readStart / dp->blockSize != dp->blockNum)
{
dp->transferCount = 0;
return drvrBadBlock;
}
enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd);
if (err != OPERATION_SUCCESSFUL) {
dp->transferCount = 0;