- 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.
This commit is contained in:
parent
35956d32df
commit
3249f70d0f
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user