Subject: Re: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-bugs
Date: 07/05/2007 20:55:02
The following reply was made to PR bin/36609; it has been noted by GNATS.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Cc: 
Subject: Re: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
Date: Thu, 5 Jul 2007 16:51:01 -0400

 On Jul 5,  8:45pm, zeurkous@nichten.info (zeurkous@nichten.info) wrote:
 -- Subject: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
 
 | >Number:         36609
 | >Category:       bin
 | >Synopsis:       Fix {fdisk,disklabel}(8) device path parsing
 | >Confidential:   no
 | >Severity:       non-critical
 | >Priority:       low
 | >Responsible:    bin-bug-people
 | >State:          open
 | >Class:          sw-bug
 | >Submitter-Id:   net
 | >Arrival-Date:   Thu Jul 05 20:45:00 +0000 2007
 | >Originator:     De Zeurkous
 | >Release:        NetBSD-3.1/i386
 | >Organization:
 | NichtNet
 | >Environment:
 | NetBSD lichee.nichten.info 3.1 NetBSD 3.1 (GENERIC) #0: Tue Oct 31 04:27:07 UTC 2006  builds@b0.netbsd.org:/home/builds/ab/netbsd-3-1-RELEASE/i386/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/i386/compile/GENERIC i386
 | >Description:
 | Obvious from other input.
 | >How-To-Repeat:
 | lichee# pwd
 | /root
 | lichee# ls -l | grep 'wd2'
 | drwxr-xr-x  2 root  wheel   512 Jul  5 18:42 wd2
 | lichee# disklabel wd2
 | disklabel: Invalid signature in mbr record 0
 | disklabel: ioctl DIOCGDINFO: Inappropriate ioctl for device
 | lichee# fdisk wd2
 | fdisk: DIOCGDEFLABEL: Inappropriate ioctl for device
 | fdisk: DIOCGDINFO: Inappropriate ioctl for device
 | lichee# disklabel wd2d
 | [snip correct output]
 | lichee# fdisk wd2d
 | [snip correct output]
 | lichee# ( cd / && disklabel wd2; )
 | [snip correct output]
 | lichee# ( cd / && fdisk wd2; )
 | [snip correct output]
 | >Fix:
 | My proposal for a fix is to only parse explicit paths:
 | 
 | example# pwd
 | /root
 | example# ls -l | grep 'wd2'
 | drwxr-xr-x  2 root  wheel   512 Jul  5 18:42 wd2
 | example# disklabel wd2
 | [snip correct output]
 | example# fdisk wd2
 | [snip correct output]
 | example# disklabel ./wd2
 | disklabel: Invalid signature in mbr record 0
 | disklabel: ioctl DIOCGDINFO: Inappropriate ioctl for device
 | lichee# fdisk ./wd2
 | fdisk: DIOCGDEFLABEL: Inappropriate ioctl for device
 | fdisk: DIOCGDINFO: Inappropriate ioctl for device
 | 
 | Detection can obviously be arranged by grepping the argument for a '/'.
 
 Although what you proposed satisfies POLA, it is un-unix-like to parse and
 treat filenames specially, when filenames are accepted. Here the mistake
 was made when for convenience wd2 was magically rewritten to /dev/rwd2{c,d}.
 We could even do one better and stat the file to see if it is a directory,
 and then auto-process the device file... I am not sure I like all this
 magic though; at least it is centralized in opendisk(3).
 
 christos