aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/diskinfo
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2017-01-04 00:39:06 +0000
committerAlan Somers <asomers@FreeBSD.org>2017-01-04 00:39:06 +0000
commit4c9f98e28a0c934eaa4afb7666715b8a311529b2 (patch)
tree7fe63da857542d238f05403cd4ac327a26b99036 /usr.sbin/diskinfo
parent0642856a1e7aa5af07fcaa6e4a95a956878433d1 (diff)
downloadsrc-4c9f98e28a0c934eaa4afb7666715b8a311529b2.tar.gz
src-4c9f98e28a0c934eaa4afb7666715b8a311529b2.zip
Quell Coverity for diskinfo(8)
* CID 1198994: Don't run the speed disk on a disk with no sectors * CID 1011442: Don't call close(2) if open(2) fails * CID 1011161: Use snprintf instead of sprintf * CID 1009825: Check the return value of lseek Reported by: Coverity CID: 1198994 1011442 1011161 1009825 MFC after: 4 weeks Sponsored by: Spectra Logic Corp
Notes
Notes: svn path=/head/; revision=311210
Diffstat (limited to 'usr.sbin/diskinfo')
-rw-r--r--usr.sbin/diskinfo/diskinfo.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c
index df51aac2691e..438f1b8b9655 100644
--- a/usr.sbin/diskinfo/diskinfo.c
+++ b/usr.sbin/diskinfo/diskinfo.c
@@ -104,13 +104,12 @@ main(int argc, char **argv)
for (i = 0; i < argc; i++) {
fd = open(argv[i], O_RDONLY | O_DIRECT);
if (fd < 0 && errno == ENOENT && *argv[i] != '/') {
- sprintf(buf, "%s%s", _PATH_DEV, argv[i]);
+ snprintf(buf, BUFSIZ, "%s%s", _PATH_DEV, argv[i]);
fd = open(buf, O_RDONLY);
}
if (fd < 0) {
warn("%s", argv[i]);
- exitval = 1;
- goto out;
+ exit(1);
}
error = fstat(fd, &sb);
if (error != 0) {
@@ -213,7 +212,8 @@ rdsect(int fd, off_t blockno, u_int sectorsize)
{
int error;
- lseek(fd, (off_t)blockno * sectorsize, SEEK_SET);
+ if (lseek(fd, (off_t)blockno * sectorsize, SEEK_SET) == -1)
+ err(1, "lseek");
error = read(fd, sector, sectorsize);
if (error == -1)
err(1, "read");
@@ -296,6 +296,9 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
off_t b0, b1, sectorcount, step;
sectorcount = mediasize / sectorsize;
+ if (sectorcount <= 0)
+ return; /* Can't test devices with no sectors */
+
step = 1ULL << (flsll(sectorcount / (4 * 200)) - 1);
if (step > 16384)
step = 16384;