bin/148881: libdisk emits errors w/ disks that contain spaces in labels

Jeremy Chadwick freebsd at jdc.parodius.com
Fri Jul 23 22:20:07 UTC 2010


>Number:         148881
>Category:       bin
>Synopsis:       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:
>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 at 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:


More information about the freebsd-bugs mailing list