summaryrefslogtreecommitdiffstats
path: root/usr.sbin/diskinfo/diskinfo.c
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2017-02-02 18:27:20 +0000
committerasomers <asomers@FreeBSD.org>2017-02-02 18:27:20 +0000
commita766b842dd5c8d955f98bec419d78c2c143734db (patch)
treec705fab6d5ca9b83a4b12abb07036a4d2546d510 /usr.sbin/diskinfo/diskinfo.c
parent96413020c324b010a7fe7febe571f213bdedb892 (diff)
downloadFreeBSD-src-a766b842dd5c8d955f98bec419d78c2c143734db.zip
FreeBSD-src-a766b842dd5c8d955f98bec419d78c2c143734db.tar.gz
MFC r311160, r311210, r311288, r311292, r311298, r311340
r311160: misc minor fixes in mpr(4) sys/dev/mpr/mpr_sas.c * Fix a potential null pointer dereference (CID 1305731) * Check for overrun of the ccb_scsiio.cdb_io.cdb_bytes buffer (CID 1211934) sys/dev/mpr/mpr_sas_lsi.c * Nullify a dangling pointer in mprsas_get_sata_identify * Fix a memory leak in mprsas_SSU_to_SATA_devices (CID 1211935) Reported by: Coverity (partially) CID: 1305731 1211934 1211935 Reviewed by: slm MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D8880 r311210: 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 r311288: Delete dead code in chat(8) It's always been dead, ever since first import in 1994. It's still dead in OpenBSD's version, too. Reported by: Coverity CID: 270586 MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311292: Remove dead code in rpc_parse.c It's been dead ever since it was imported from TI-RPC in 1995. The dead code is still present in Illumos today, but was removed from NetBSD in 2006. Reported by: Coverity CID: 270097 Obtained from: NetBSD MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311298: Remove dead code in dhclient(8) The offending code has been dead ever since the import from OpenBSD in r195805. OpenBSD later deleted that entire function. Reported by: Coverity CID: 500059 MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311340: Misc Coverity fixes for tail(1) CID 1006402: Initialize stack variable CID 271580: Don't leak memory when ENOMEM. Reported by: Coverity CID: 271580 1006402 MFC after: 4 weeks Sponsored by: Spectra Logic Corp
Diffstat (limited to 'usr.sbin/diskinfo/diskinfo.c')
-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 373b3fe..c984f3e 100644
--- a/usr.sbin/diskinfo/diskinfo.c
+++ b/usr.sbin/diskinfo/diskinfo.c
@@ -94,13 +94,12 @@ main(int argc, char **argv)
for (i = 0; i < argc; i++) {
fd = open(argv[i], O_RDONLY);
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 = ioctl(fd, DIOCGMEDIASIZE, &mediasize);
if (error) {
@@ -186,7 +185,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");
@@ -251,6 +251,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;
OpenPOWER on IntegriCloud