]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: more robust whole-disk detection
authorKarel Zak <kzak@redhat.com>
Thu, 17 Feb 2011 10:02:26 +0000 (11:02 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Apr 2011 12:28:40 +0000 (14:28 +0200)
In lib/wholedisk.c, i is set to 0. If fd was a -1, then at
line 18 geometry.start is used without it being initialized.

Reported-by: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/wholedisk.c

index 35f143d28570963c2249bb71b79543f9b9eb4f07..4a5305229af9f9d116d41720bda89cbd434a143d 100644 (file)
@@ -9,13 +9,12 @@
 int is_whole_disk_fd(int fd, const char *name)
 {
 #ifdef HDIO_GETGEO
-       struct hd_geometry geometry;
-       int i = 0;
-
-       if (fd != -1)
-               i = ioctl(fd, HDIO_GETGEO, &geometry);
-       if (i == 0)
-               return geometry.start == 0;
+       if (fd != -1) {
+               struct hd_geometry geometry;
+               int i = ioctl(fd, HDIO_GETGEO, &geometry);
+               if (i == 0)
+                       return geometry.start == 0;
+       }
 #endif
        /*
         * The "silly heuristic" is still sexy for us, because