From: Karel Zak Date: Thu, 17 Feb 2011 10:02:26 +0000 (+0100) Subject: fdisk: more robust whole-disk detection X-Git-Tag: v2.20-rc1~553 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2fa3fbe858fe194069a30b1b991b2473d4edc307;p=thirdparty%2Futil-linux.git fdisk: more robust whole-disk detection 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 Signed-off-by: Karel Zak --- diff --git a/lib/wholedisk.c b/lib/wholedisk.c index 35f143d285..4a5305229a 100644 --- a/lib/wholedisk.c +++ b/lib/wholedisk.c @@ -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