summaryrefslogtreecommitdiffstats
path: root/fdisk/fdisksgilabel.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2012-05-06 14:10:25 +0200
committerKarel Zak2012-05-10 11:40:21 +0200
commit50f6100a960d96471980a9a5354d9ee426b00673 (patch)
treedd5bf23e2332c7543db5bc7638283ab26c9d546b /fdisk/fdisksgilabel.c
parentfdisk: remove unused function declaration (diff)
downloadkernel-qcow2-util-linux-50f6100a960d96471980a9a5354d9ee426b00673.tar.gz
kernel-qcow2-util-linux-50f6100a960d96471980a9a5354d9ee426b00673.tar.xz
kernel-qcow2-util-linux-50f6100a960d96471980a9a5354d9ee426b00673.zip
fdisk: sgi: abort on HDIO_GETGEO failure
When the HDIO_GETGEO ioctl fails on non IRIX/MIPS platforms (ie: inappropriate ioctl for device) the variables that describe the geometry are compromissed. One clear example is a division by 0 bug because the cylinder size is 0 is verify_sgi(): $> fdisk sgi.img Welcome to fdisk (util-linux 2.21.392-4b1c). ... Command (m for help): x Expert command (m for help): g Building a new SGI disklabel. Partition 11 of type SGI volume and of size 7.9 MiB is set Floating point exception Fix this by simply exiting the program instead of leaving it in a vulnerable state. Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisk/fdisksgilabel.c')
-rw-r--r--fdisk/fdisksgilabel.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c
index 822f55d97..5e851bc8e 100644
--- a/fdisk/fdisksgilabel.c
+++ b/fdisk/fdisksgilabel.c
@@ -705,25 +705,26 @@ create_sgilabel(void)
res = blkdev_get_sectors(fd, &llsectors);
#ifdef HDIO_GETGEO
- if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
- heads = geometry.heads;
- sectors = geometry.sectors;
- if (res == 0) {
- /* the get device size ioctl was successful */
- unsigned long long llcyls;
- llcyls = llsectors / (heads * sectors * sec_fac);
- cylinders = llcyls;
- if (cylinders != llcyls) /* truncated? */
- cylinders = ~0;
- } else {
- /* otherwise print error and use truncated version */
- cylinders = geometry.cylinders;
- fprintf(stderr,
- _("Warning: BLKGETSIZE ioctl failed on %s. "
- "Using geometry cylinder value of %d.\n"
- "This value may be truncated for devices"
- " > 33.8 GB.\n"), disk_device, cylinders);
- }
+ if (ioctl(fd, HDIO_GETGEO, &geometry) < 0)
+ err(EXIT_FAILURE, _("HDIO_GETGEO ioctl failed on %s"), disk_device);
+
+ heads = geometry.heads;
+ sectors = geometry.sectors;
+ if (res == 0) {
+ /* the get device size ioctl was successful */
+ unsigned long long llcyls;
+ llcyls = llsectors / (heads * sectors * sec_fac);
+ cylinders = llcyls;
+ if (cylinders != llcyls) /* truncated? */
+ cylinders = ~0;
+ } else {
+ /* otherwise print error and use truncated version */
+ cylinders = geometry.cylinders;
+ fprintf(stderr,
+ _("Warning: BLKGETSIZE ioctl failed on %s. "
+ "Using geometry cylinder value of %d.\n"
+ "This value may be truncated for devices"
+ " > 33.8 GB.\n"), disk_device, cylinders);
}
#endif
for (i = 0; i < 4; i++) {