Subject: bin/9865: fdisk(8) can end up using garbage hardware geometry info
To: None <gnats-bugs@gnats.netbsd.org>
From: None <thorpej@zembu.com>
List: netbsd-bugs
Date: 04/12/2000 11:49:12
>Number:         9865
>Category:       bin
>Synopsis:       fdisk(8) can end up using garbage hardware geometry info
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 12 11:50:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Jason R. Thorpe
>Release:        NetBSD 1.4X, March 31, 2000
>Organization:
Zembu Labs, Inc.
>Environment:
NetBSD 1.4X on Intel server hardware

>Description:
	If an incorrect disklabel is present on the disk, fdisk(8) can
	wind up using potentially bogus hardware geometry information
	present in that disklabel.

>How-To-Repeat:

>Fix:
	The following patch fixes the problem by changing fdisk(8) to
	use the DIOCGDEFLABEL ioctl before falling back on the
	DIOCGDLABEL ioctl.

Index: fdisk.c
===================================================================
RCS file: /home/cvsfiles/netbsd/src/sbin/fdisk/fdisk.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** fdisk.c	2000/03/31 19:56:20	1.1
--- fdisk.c	2000/04/11 19:23:06	1.2
***************
*** 1274,1282 ****
  get_params()
  {
  
! 	if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
! 		warn("DIOCGDINFO");
! 		return (-1);
  	}
  
  	dos_cylinders = cylinders = disklabel.d_ncylinders;
--- 1274,1285 ----
  get_params()
  {
  
! 	if (ioctl(fd, DIOCGDEFLABEL, &disklabel) == -1) {
! 		warn("DIOCGDEFLABEL");
! 		if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
! 			warn("DIOCGDINFO");
! 			return (-1);
! 		}
  	}
  
  	dos_cylinders = cylinders = disklabel.d_ncylinders;
>Release-Note:
>Audit-Trail:
>Unformatted: