Sanity check media size and sector counts to ensure that we don't

produce negative sector numbers in the testing algorithm.

CID: 1198994
This commit is contained in:
imp 2018-01-06 12:34:03 +00:00
parent 0a7ff7d651
commit ab687701c5

View File

@ -407,9 +407,14 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
int bulk, i;
off_t b0, b1, sectorcount, step;
/*
* Drives smaller than 1MB produce negative sector numbers,
* as do 2048 or fewer sectors.
*/
sectorcount = mediasize / sectorsize;
if (sectorcount <= 0)
return; /* Can't test devices with no sectors */
if (mediasize < 1024 * 1024 || sectorcount < 2048)
return;
step = 1ULL << (flsll(sectorcount / (4 * 200)) - 1);
if (step > 16384)