diff options
author | yar <yar@FreeBSD.org> | 2007-11-28 07:54:42 +0000 |
---|---|---|
committer | yar <yar@FreeBSD.org> | 2007-11-28 07:54:42 +0000 |
commit | 2a850cfe1a353a518c1765120d606127bdefa060 (patch) | |
tree | b93350e4dd8e96d78a70afb14056dccb4139d093 /sbin/newfs | |
parent | 13b1c70facfd50df5e26ab1d2cb15ec557a2c480 (diff) | |
download | FreeBSD-src-2a850cfe1a353a518c1765120d606127bdefa060.zip FreeBSD-src-2a850cfe1a353a518c1765120d606127bdefa060.tar.gz |
- Pay attention to the fact that ioctl(2) is only known to
return -1 on error while any other return value from it can
indicate success. (See RETURN VALUE in our ioctl(2) manpage
and the POSIX spec.)
- Avoid assumptions about the state of the data buffer after
ioctl(2) failure.
Diffstat (limited to 'sbin/newfs')
-rw-r--r-- | sbin/newfs/newfs.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 532e066..f69411c 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -312,8 +312,9 @@ main(int argc, char *argv[]) errx(1, "%s: not a character-special device", special); if (sectorsize == 0) - ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize); - if (sectorsize && !ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize)) + if (ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize) == -1) + sectorsize = 0; /* back out on error for safety */ + if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1) getfssize(&fssize, special, mediasize / sectorsize, reserved); pp = NULL; lp = getdisklabel(special); @@ -409,7 +410,7 @@ getdisklabel(char *s) static struct disklabel lab; struct disklabel *lp; - if (!ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab)) + if (ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab) != -1) return (&lab); unlabeled++; if (disktype) { @@ -427,7 +428,7 @@ rewritelabel(char *s, struct disklabel *lp) return; lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) < 0) + if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) == -1) warn("ioctl (WDINFO): %s: can't rewrite disk label", s); } |