svn commit: r327617 - head/usr.sbin/diskinfo

Warner Losh imp at FreeBSD.org
Sat Jan 6 12:34:05 UTC 2018


Author: imp
Date: Sat Jan  6 12:34:03 2018
New Revision: 327617
URL: https://svnweb.freebsd.org/changeset/base/327617

Log:
  Sanity check media size and sector counts to ensure that we don't
  produce negative sector numbers in the testing algorithm.
  
  CID: 1198994

Modified:
  head/usr.sbin/diskinfo/diskinfo.c

Modified: head/usr.sbin/diskinfo/diskinfo.c
==============================================================================
--- head/usr.sbin/diskinfo/diskinfo.c	Sat Jan  6 09:48:04 2018	(r327616)
+++ head/usr.sbin/diskinfo/diskinfo.c	Sat Jan  6 12:34:03 2018	(r327617)
@@ -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)


More information about the svn-src-all mailing list