Subject: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <zeurkous@nichten.info>
List: netbsd-bugs
Date: 07/05/2007 20:45:00
>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 '/'.