From jdc@koitsu.dyndns.org  Fri Jul 23 22:16:22 2010
Return-Path: <jdc@koitsu.dyndns.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id CDBAF1065670
	for <freebsd-gnats-submit@freebsd.org>; Fri, 23 Jul 2010 22:16:22 +0000 (UTC)
	(envelope-from jdc@koitsu.dyndns.org)
Received: from qmta05.westchester.pa.mail.comcast.net (qmta05.westchester.pa.mail.comcast.net [76.96.62.48])
	by mx1.freebsd.org (Postfix) with ESMTP id 7F0518FC0A
	for <freebsd-gnats-submit@freebsd.org>; Fri, 23 Jul 2010 22:16:21 +0000 (UTC)
Received: from omta21.westchester.pa.mail.comcast.net ([76.96.62.72])
	by qmta05.westchester.pa.mail.comcast.net with comcast
	id lSvD1e0091ZXKqc55aGMxr; Fri, 23 Jul 2010 22:16:21 +0000
Received: from koitsu.dyndns.org ([98.248.41.155])
	by omta21.westchester.pa.mail.comcast.net with comcast
	id laGL1e00A3LrwQ23haGMCW; Fri, 23 Jul 2010 22:16:21 +0000
Received: by icarus.home.lan (Postfix, from userid 1000)
	id 771339B425; Fri, 23 Jul 2010 15:16:19 -0700 (PDT)
Message-Id: <20100723221619.771339B425@icarus.home.lan>
Date: Fri, 23 Jul 2010 15:16:19 -0700 (PDT)
From: Jeremy Chadwick <freebsd@jdc.parodius.com>
Reply-To: Jeremy Chadwick <freebsd@jdc.parodius.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: libdisk emits errors w/ disks that contain spaces in labels
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         148881
>Category:       kern
>Synopsis:       [libdisk] [patch] libdisk emits errors w/ disks that contain spaces in labels
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 23 22:20:06 UTC 2010
>Closed-Date:    
>Last-Modified:  Sat Jul 24 03:11:02 UTC 2010
>Originator:     Jeremy Chadwick
>Release:        FreeBSD 8.1-PRERELEASE amd64
>Organization:
>Environment:
System: FreeBSD icarus.home.lan 8.1-PRERELEASE FreeBSD 8.1-PRERELEASE #0: Tue Jul 13 05:58:50 PDT 2010 root@icarus.home.lan:/usr/obj/usr/src/sys/X7SBA_RELENG_8_amd64 amd64
>Description:
	libdisk(3)'s Int_Open_Disk() function makes some bad assumptions
	about the syntax of the lines come from sysctl kern.geom.conftxt
	(passed in via sysinstall).

	Disks, slices, or partitions which have spaces in their label
	names -- such as FAT-formatted USB flash drives with spaces in
	their volume name, or anything glabel'd -- will cause libdisk
	to spit out an error similar to the below.  Use of dialog
	in sysinstall hides portions of the error string:

	Int_Open_Disk(da1): can't parse length 'V100W' in line 3 (r='V100W')

	In this situation, the disk da1 was a FAT32-formatted USB flash
	drive with a volume name of "HP V100W".  kern.geom.conftxt showed:

0 DISK da1 4009754624 512 hd 255 sc 63
1 PART da1s1 4009722368 512 i 1 o 32256 ty !12 xs MBR xt 12
2 LABEL msdosfs/HP V100W 4009722368 512 i 0 o 0

>How-To-Repeat:
	glabel create "some label" /dev/da0s1a
	sysinstall
>Fix:
	I've spent the past 6-7 hours going over the libdisk(3) code's
	parser, and determined that (probably) the easiest way to deal
	with this is to ignore LABEL lines altogether.  There is probably
	a cleaner way to deal with this, such as using libgeom(3) (which I
	did try but the API is severely lacking in documentation), but
	this is what I came up with.  This should be thoroughly analysed
	before being considered for commit.

	Also, I want to point out that the inline comment for "t"
	assignment doesn't appear to be correct (see above example, re: MBR).
	This makes me wonder if we have further parser problems in this
	library (maybe this could explain PR 140972)?

--- src/lib/libdisk/open_disk.c.orig	2009-08-03 01:13:06.000000000 -0700
+++ src/lib/libdisk/open_disk.c	2010-07-23 15:09:14.337845551 -0700
@@ -160,6 +160,13 @@
 
 		}
 		t = strsep(&p, " ");	/* Type {SUN, BSD, MBR, PC98, GPT} */
+		/*
+		 * Skip LABEL lines.  This solves parsing errors when it
+		 * comes to disks which contain volume labels or glabels
+		 * with spaces, such as FAT-formatted USB flash drives.
+		 */
+		if (!strcmp(t, "LABEL"))
+			continue;
 		n = strsep(&p, " ");	/* name */
 		a = strsep(&p, " ");	/* len */
 		len = strtoimax(a, &r, 0);
>Release-Note:
>Audit-Trail:
>Unformatted:
