mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-11-12 10:06:53 +00:00
Do sanity checks of input values for Driver_Read.
This commit is contained in:
parent
8532c14ee1
commit
3f3c14b8a1
16
driver.c
16
driver.c
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user