From nobody@FreeBSD.org  Fri Oct 13 20:43:16 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B731616A403
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Oct 2006 20:43:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 34FEC43DB5
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Oct 2006 20:43:04 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k9DKh3g3055023
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Oct 2006 20:43:03 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k9DKh3lW055022;
	Fri, 13 Oct 2006 20:43:03 GMT
	(envelope-from nobody)
Message-Id: <200610132043.k9DKh3lW055022@www.freebsd.org>
Date: Fri, 13 Oct 2006 20:43:03 GMT
From: douglas steinwand<dzs-pr@dzs.fx.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sys/geom/geom_dump.c doesn't encode XML entities
X-Send-Pr-Version: www-3.0

>Number:         104389
>Category:       kern
>Synopsis:       [geom] [patch] sys/geom/geom_dump.c doesn't encode XML entities
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 13 20:50:19 GMT 2006
>Closed-Date:    Wed Aug 11 18:20:42 UTC 2010
>Last-Modified:  Wed Aug 11 18:20:42 UTC 2010
>Originator:     douglas steinwand
>Release:        6.2-PRERELEASE
>Organization:
>Environment:
FreeBSD sun-x2100.fx.org 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #1: Fri Oct 13 07:15:37 PDT 2006     root@sun-x2100.fx.org:/usr/obj/usr/src/sys/HAWK6-SMP  amd64
>Description:
The sysctl kern.geom.confxml can return invalid XML if, for example, the label has characters that are not safe in XML. This breaks libgeom's geom_xml2tree and utilities that use it, like glabel and gstat.
>How-To-Repeat:
# glabel list
# mdconfig -at swap -s 1m
md0
# glabel create bread\&butter /dev/md0
GEOM_LABEL: Label for provider md0 is label/bread&butter.
# glabel list
Cannot get GEOM tree: Unknown error: -1.
# gstat
gstat: geom_gettree = -1: Unknown error: 0

>Fix:
geom_dump.c should encode XML entities. Attached is a patch.





Patch attached with submission follows:

--- sys/geom/geom_dump.c.orig	Wed Mar 10 00:49:08 2004
+++ sys/geom/geom_dump.c	Fri Oct 13 13:04:11 2006
@@ -45,6 +45,43 @@
 #include <geom/geom.h>
 #include <geom/geom_int.h>
 
+static void
+_encode_entities(char *d, size_t dlen, const char *s)
+{
+	const char *e;
+	char *t;
+
+	if (dlen < 1)
+		return;
+	for(; *s && dlen > 1; s++) {
+		switch(*s) {
+		case '&':
+			e = "&amp;";
+			break;
+		case '<':
+			e = "&lt;";
+			break;
+		case '>':
+			e = "&gt;";
+			break;
+		case '\'':
+			e = "&apos;";
+			break;
+		case '"':
+			e = "&quot;";
+			break;
+		default:
+			*d++ = *s;
+			dlen--;
+			continue;
+		}
+		for(t = d; *e && dlen >= 1; e++, d++, dlen--)
+			*d = *e;
+		if (dlen < 1)
+			d = t;
+	}
+	*d = 0;
+}
 
 static void
 g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
@@ -177,12 +214,14 @@
 static void
 g_conf_provider(struct sbuf *sb, struct g_provider *pp)
 {
+	char buf[128];
 
 	sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
 	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
 	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
 	    pp->acr, pp->acw, pp->ace);
-	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
+	_encode_entities(buf, sizeof(buf), pp->name);
+	sbuf_printf(sb, "\t  <name>%s</name>\n", buf);
 	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
 	    (intmax_t)pp->mediasize);
 	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
@@ -202,10 +241,12 @@
 {
 	struct g_consumer *cp2;
 	struct g_provider *pp2;
+	char buf[128];
 
 	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
 	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
-	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
+	_encode_entities(buf, sizeof(buf), gp->name);
+	sbuf_printf(sb, "      <name>%s</name>\n", buf);
 	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
 	if (gp->flags & G_GEOM_WITHER)
 		sbuf_printf(sb, "      <wither/>\n");
@@ -232,9 +273,11 @@
 g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
 {
 	struct g_geom *gp2;
+	char buf[128];
 
 	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
-	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
+	_encode_entities(buf, sizeof(buf), mp->name);
+	sbuf_printf(sb, "    <name>%s</name>\n", buf);
 	LIST_FOREACH(gp2, &mp->geom, geom) {
 		if (gp != NULL && gp != gp2)
 			continue;

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-geom 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Oct 14 18:55:35 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=104389 

From: "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To: douglas steinwand <dzs-pr@dzs.fx.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/104389: sys/geom/geom_dump.c doesn't encode XML entities 
Date: Sun, 15 Oct 2006 18:12:56 +0000

 In message <200610132043.k9DKh3lW055022@www.freebsd.org>, douglas steinwand wri
 tes:
 
 >geom_dump.c should encode XML entities. Attached is a patch.
 
 I don't like it in two ways.
 
 I'm not keep on the encoding, and would be inclined to say
 "Don't use such names then", but I can probably be convinced
 that this is actually a good idea if sensible examples are shown.
 
 The other thing is that in the patch, the _encode_entities()
 function should not have a leading underscore and should
 take arguments:
 
 	static void
 	encode_entities(struct sbuf *sb, const char *fmt,
 	    const char *str, int len);
 
 So that usage would not need a randomsized local buffer and
 double enveloping of the call:
 
 >-	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 
 Should be:
 
 	encode_entities(sb, "\t  <name>%s</name>\n", pp->name, -1);
 
 (-1 for len means "use strlen")
 
 
 -- 
 Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
 phk@FreeBSD.ORG         | TCP/IP since RFC 956
 FreeBSD committer       | BSD since 4.3-tahoe    
 Never attribute to malice what can adequately be explained by incompetence.

From: douglas steinwand <dzs-pr@dzs.fx.org>
To: Poul-Henning Kamp <phk@phk.freebsd.dk>
Cc: douglas steinwand <dzs-pr@dzs.fx.org>, freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/104389: sys/geom/geom_dump.c doesn't encode XML entities
Date: Sun, 15 Oct 2006 13:20:41 -0700

 --BXVAT5kNtrzKuDFl
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 * Poul-Henning Kamp <phk@phk.freebsd.dk> [2006-10-15 18:12:56 +0000]:
 > I'm not keep on the encoding, and would be inclined to say
 > "Don't use such names then", but I can probably be convinced
 > that this is actually a good idea if sensible examples are shown.
 
 I encountered this issue thanks to a CD from Sun Microsystems:
 
 # glabel status
                       Name  Status  Components
 iso9660/tools_&_driver_1.0     N/A  acd0
 
 The label on its ISO9660 filesystem has "&", which must be encoded
 in XML.
 
 > The other thing is that in the patch, the _encode_entities()
 > function should not have a leading underscore and should
 > take arguments:
 > 
 > 	static void
 > 	encode_entities(struct sbuf *sb, const char *fmt,
 > 	    const char *str, int len);
 
 My initial patch was just a quick hack to work around the problem.
 I didn't know how FreeBSD's developers wanted to address it. For
 example, if XML will be used widely in the kernel, should a new
 format code for kvprintf() do this XML encoding?
 
 > So that usage would not need a randomsized local buffer and
 > double enveloping of the call:
 > 
 > >-	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 > 
 > Should be:
 > 
 > 	encode_entities(sb, "\t  <name>%s</name>\n", pp->name, -1);
 > 
 > (-1 for len means "use strlen")
 
 Attached is a new patch for geom_dump.c which follows your
 recommendations.
 
 Thanks,
  - doug
 
 --BXVAT5kNtrzKuDFl
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=patch-geom_dump
 
 --- sys/geom/geom_dump.c.orig	Wed Mar 10 00:49:08 2004
 +++ sys/geom/geom_dump.c	Sun Oct 15 12:53:42 2006
 @@ -45,6 +45,47 @@
  #include <geom/geom.h>
  #include <geom/geom_int.h>
  
 +static void
 +encode_entities(struct sbuf *sb, const char *fmt, const char *str, int len)
 +{
 +	char *d, *dst;
 +	const char *e;
 +	int i;
 +
 +	if (len == -1)
 +		len = strlen(str);
 +	/* Assume worst case expansion. */
 +	dst = d = g_malloc(len * 6 + 1, M_WAITOK); 
 +
 +	for(i = 0; i < len; i++) {
 +		switch(str[i]) {
 +		case '&':
 +			e = "&amp;";
 +			break;
 +		case '<':
 +			e = "&lt;";
 +			break;
 +		case '>':
 +			e = "&gt;";
 +			break;
 +		case '\'':
 +			e = "&apos;";
 +			break;
 +		case '"':
 +			e = "&quot;";
 +			break;
 +		default:
 +			*d++ = str[i];
 +			continue;
 +		}
 +		while(*e != '\0')
 +			*d++ = *e++;
 +	}
 +	*d = '\0';
 +
 +	sbuf_printf(sb, fmt, dst);
 +	g_free(dst);
 +}
  
  static void
  g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
 @@ -182,7 +223,7 @@
  	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  	    pp->acr, pp->acw, pp->ace);
 -	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 +	encode_entities(sb, "\t  <name>%s</name>\n", pp->name, -1);
  	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  	    (intmax_t)pp->mediasize);
  	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
 @@ -205,7 +246,7 @@
  
  	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
 -	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
 +	encode_entities(sb, "      <name>%s</name>\n", gp->name, -1);
  	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  	if (gp->flags & G_GEOM_WITHER)
  		sbuf_printf(sb, "      <wither/>\n");
 @@ -234,7 +275,7 @@
  	struct g_geom *gp2;
  
  	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
 -	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
 +	encode_entities(sb, "    <name>%s</name>\n", mp->name, -1);
  	LIST_FOREACH(gp2, &mp->geom, geom) {
  		if (gp != NULL && gp != gp2)
  			continue;
 
 --BXVAT5kNtrzKuDFl--

From: Dennis Berger <db@nipsi.de>
To: bug-followup@FreeBSD.org,  dzs-pr@dzs.fx.org, 
 freebsd-geom@freebsd.org
Cc:  
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode
 XML entities
Date: Tue, 06 Mar 2007 16:53:44 +0100

 Hi,
 today I tried PJDs ZFS patches. After invoking zpool create I always got
 a coredump.
 After further debugging I recognized gstat isn't working either, which
 seems to be because of an NTFS partition with a certain name not
 correctly encoded as XML specification requires. Its the German "Lokaler
 Datentrger" which is the defaultname for drive "c". So we have to deal
 with those characters. I'm voting against encoding specification or
 something like that, but I do recommend using the escape method. For
 example using "&#e4;"  for encoding E4 german  and &#60; for a "<"
 character. This way we can escape all illegal characters.
 What do you suggest?
 regards,
 -Dennis Berger

From: Dennis Berger <db@nipsi.de>
To: Cc: bug-followup@FreeBSD.org,  dzs-pr@dzs.fx.org, 
 freebsd-geom@freebsd.org
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode
 XML entities
Date: Tue, 06 Mar 2007 17:00:10 +0100

 Dennis Berger schrieb:
 > Hi,
 > today I tried PJDs ZFS patches. After invoking zpool create I always got
 > a coredump.
 > After further debugging I recognized gstat isn't working either, which
 > seems to be because of an NTFS partition with a certain name not
 > correctly encoded as XML specification requires. Its the German "Lokaler
 > Datentrger" which is the defaultname for drive "c". So we have to deal
 > with those characters. I'm voting against encoding specification or
 > something like that, but I do recommend using the escape method. For
 > example using "&#e4;"  for encoding E4 german  and &#60; for a "<"
 > character. This way we can escape all illegal characters.
 > What do you suggest?
 > regards,
 > -Dennis Berger
 > _______________________________________________
 > freebsd-geom@freebsd.org mailing list
 > http://lists.freebsd.org/mailman/listinfo/freebsd-geom
 > To unsubscribe, send any mail to "freebsd-geom-unsubscribe@freebsd.org"
 >   
 
 &#xE4; of cause!
 

From: doug steinwand <dzs-pr@dzs.fx.org>
To: Dennis Berger <db@nipsi.de>
Cc: bug-followup@FreeBSD.org, dzs-pr@dzs.fx.org, freebsd-geom@freebsd.org
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode XML entities
Date: Wed, 7 Mar 2007 07:10:26 -0800

 --PNTmBPCT7hxwcZjr
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 * Dennis Berger <db@nipsi.de> [2007-03-06 16:53:44 +0100]:
 > This way we can escape all illegal characters.
 > What do you suggest?
 
 The gstat and other geom applications basically use expat to parse
 the equivalent of "sysctl -b kern.geom.confxml". This output does
 not have an encoding specified, so expat accepts only ASCII.  As
 such, bytes greater than 0x7e must be encoded.
 
 http://skew.org/xml/tutorial/
 http://www.w3.org/TR/1998/REC-xml-19980210
 
 Attached is a patch which attempts to output valid XML for all cases
 (any value between 0x00 and 0xff). One issue is that many bytes
 between 0x00 and 0x1f have no valid XML coding, so this patch
 replaces them with '?' (such things should not appear in geom names,
 though).
 
 Also, it seems that expat is attempting to convert bytes from
 iso-8859-1 into utf8 characters, so gstat and glabel output may
 look weird.
 
  - doug
 
 --PNTmBPCT7hxwcZjr
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="geom_xml_encode.patch"
 
 --- sys/geom/geom_dump.c.orig	Wed Mar 10 00:49:08 2004
 +++ sys/geom/geom_dump.c	Tue Mar  6 20:15:20 2007
 @@ -45,6 +45,31 @@
  #include <geom/geom.h>
  #include <geom/geom_int.h>
  
 +static void
 +encode_bytes(struct sbuf *sb, const char *fmt, const char *str, int len)
 +{
 +	char *d, *dst;
 +	unsigned char c;
 +	int i;
 +
 +	if (len == -1)
 +		len = strlen(str);
 +	/* allocate for worst-case expansion. */
 +	dst = d = g_malloc(len * 6 + 1, M_WAITOK); 
 +	for(i = 0; i < len; i++) {
 +		c = (unsigned char) str[i];
 +		if (c == '&' || c == '<' || c == '>' ||
 +		    c == '\'' || c == '"' || c > 0x7e)
 +			d += sprintf(d, "&#x%X;", c);
 +		else if (c == 0x9 || c == 0xa || c == 0xd || c > 0x1f)
 +			*d++ = c;
 +		else
 +			*d++ = '?';
 +	}
 +	*d = '\0';
 +	sbuf_printf(sb, fmt, dst);
 +	g_free(dst);
 +}
  
  static void
  g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
 @@ -182,7 +207,7 @@
  	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  	    pp->acr, pp->acw, pp->ace);
 -	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 +	encode_bytes(sb, "\t  <name>%s</name>\n", pp->name, -1);
  	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  	    (intmax_t)pp->mediasize);
  	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
 @@ -205,7 +230,7 @@
  
  	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
 -	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
 +	encode_bytes(sb, "      <name>%s</name>\n", gp->name, -1);
  	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  	if (gp->flags & G_GEOM_WITHER)
  		sbuf_printf(sb, "      <wither/>\n");
 @@ -234,7 +259,7 @@
  	struct g_geom *gp2;
  
  	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
 -	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
 +	encode_bytes(sb, "    <name>%s</name>\n", mp->name, -1);
  	LIST_FOREACH(gp2, &mp->geom, geom) {
  		if (gp != NULL && gp != gp2)
  			continue;
 
 --PNTmBPCT7hxwcZjr--

From: Dennis Berger <db@bsdsystems.de>
To: doug steinwand <dzs-pr@dzs.fx.org>
Cc: bug-followup@FreeBSD.org,  freebsd-geom@freebsd.org
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode
 XML entities
Date: Wed, 07 Mar 2007 17:29:36 +0100

 Yes I found this version much better than the one before.
 
 regards,
 -Dennis
 
 doug steinwand schrieb:
 > * Dennis Berger <db@nipsi.de> [2007-03-06 16:53:44 +0100]:
 >   
 >> This way we can escape all illegal characters.
 >> What do you suggest?
 >>     
 >
 > The gstat and other geom applications basically use expat to parse
 > the equivalent of "sysctl -b kern.geom.confxml". This output does
 > not have an encoding specified, so expat accepts only ASCII.  As
 > such, bytes greater than 0x7e must be encoded.
 >
 > http://skew.org/xml/tutorial/
 > http://www.w3.org/TR/1998/REC-xml-19980210
 >
 > Attached is a patch which attempts to output valid XML for all cases
 > (any value between 0x00 and 0xff). One issue is that many bytes
 > between 0x00 and 0x1f have no valid XML coding, so this patch
 > replaces them with '?' (such things should not appear in geom names,
 > though).
 >
 > Also, it seems that expat is attempting to convert bytes from
 > iso-8859-1 into utf8 characters, so gstat and glabel output may
 > look weird.
 >
 >  - doug
 >   
 > ------------------------------------------------------------------------
 >
 > _______________________________________________
 > freebsd-geom@freebsd.org mailing list
 > http://lists.freebsd.org/mailman/listinfo/freebsd-geom
 > To unsubscribe, send any mail to "freebsd-geom-unsubscribe@freebsd.org"
 
 
 -- 
 Dennis Berger
 BSDSystems
 Eduardstrasse 43b
 20257 Hamburg
 
 Phone: +49 (0)40 54 00 18 17
 Mobile: +49 (0) 179 123 15 09
 E-Mail: db@bsdsystems.de
 

From: "Philip M. Gollucci" <pgollucci@p6m7g8.com>
To: bug-followup@FreeBSD.org, dzs-pr@eagle.ul.net
Cc:  
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode
 XML entities
Date: Mon, 23 Apr 2007 10:11:58 -0700

 Any word on this ?
 
 some kind of time-out ?
 
 -- 
 ------------------------------------------------------------------------
 Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
 Consultant / http://p6m7g8.net/Resume
 Senior Software Engineer - TicketMaster - http://ticketmaster.com
 1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF
 
 Work like you don't need the money,
 love like you'll never get hurt,
 and dance like nobody's watching.

From: Dennis Berger <db@nipsi.de>
To: bug-followup@FreeBSD.org,  dzs-pr@dzs.fx.org
Cc:  
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode
 XML entities
Date: Tue, 24 Apr 2007 15:31:48 +0200

 Is this fixed? Any comment from a committer?
 regards,
 Dennis

From: Eugene Grosbein <eugen@kuzbass.ru>
To: bug-followup@freebsd.org
Cc: qa@freebsd.org
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode XML entities
Date: Wed, 23 Sep 2009 11:59:59 +0800

 Hi!
 
 This it still the problem for 8.0-RC1 and patch-3 really helps.
 Please note, that localized versions of Windows assing to newly formatted
 USB flash drives the label "NEW VOLUME" translated to national language.
 
 So, inserting such drive instantly breaks geom utilities until drive removed.
 
 patch-3.diff in the PR solves the problem.
 
 Eugene Grosbein

From: Jaakko Heinonen <jh@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc: dzs-pr@dzs.fx.org
Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't
 encode XML entities
Date: Thu, 11 Mar 2010 17:31:50 +0200

 Hi,
 
 I have updated Doug's patch to use a sbuf instead of allocating the
 buffer by hand.
 
 %%%
 Index: sys/geom/geom_dump.c
 ===================================================================
 --- sys/geom/geom_dump.c	(revision 204950)
 +++ sys/geom/geom_dump.c	(working copy)
 @@ -154,6 +154,29 @@ g_conftxt(void *p, int flag)
  
  
  static void
 +g_conf_print_encoded(struct sbuf *sb, const char *fmt, const char *str)
 +{
 +	struct sbuf *s;
 +	const u_char *c;
 +
 +	s = sbuf_new_auto();
 +
 +	for (c = str; *c != '\0'; c++) {
 +		if (*c == '&' || *c == '<' || *c == '>' ||
 +		    *c == '\'' || *c == '"' || *c > 0x7e)
 +			sbuf_printf(s, "&#x%X;", *c);
 +		else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
 +			sbuf_putc(s, *c);
 +		else
 +			sbuf_putc(s, '?');
 +	}
 +
 +	sbuf_finish(s);
 +	sbuf_printf(sb, fmt, sbuf_data(s));
 +	sbuf_delete(s);
 +}
 +
 +static void
  g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
  {
  
 @@ -181,7 +204,7 @@ g_conf_provider(struct sbuf *sb, struct 
  	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  	    pp->acr, pp->acw, pp->ace);
 -	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 +	g_conf_print_encoded(sb, "\t  <name>%s</name>\n", pp->name);
  	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  	    (intmax_t)pp->mediasize);
  	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
 @@ -208,7 +231,7 @@ g_conf_geom(struct sbuf *sb, struct g_ge
  
  	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
 -	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
 +	g_conf_print_encoded(sb, "      <name>%s</name>\n", gp->name);
  	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  	if (gp->flags & G_GEOM_WITHER)
  		sbuf_printf(sb, "      <wither/>\n");
 @@ -237,7 +260,7 @@ g_conf_class(struct sbuf *sb, struct g_c
  	struct g_geom *gp2;
  
  	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
 -	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
 +	g_conf_print_encoded(sb, "    <name>%s</name>\n", mp->name);
  	LIST_FOREACH(gp2, &mp->geom, geom) {
  		if (gp != NULL && gp != gp2)
  			continue;
 %%%
Responsible-Changed-From-To: freebsd-geom->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Fri Mar 19 12:43:09 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=104389 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/104389: commit references a PR
Date: Sat, 20 Mar 2010 16:16:26 +0000 (UTC)

 Author: jh
 Date: Sat Mar 20 16:16:13 2010
 New Revision: 205385
 URL: http://svn.freebsd.org/changeset/base/205385
 
 Log:
   Escape characters unsafe for XML output in GEOM class, instance and
   provider names.
   
   - Characters in range 0x01-0x1f except '\t', '\n', and '\r' are replaced
     with '?'. Those characters are disallowed in XML.
   - '&', '<', '>', '\'', '"' and characters in range 0x7f-0xff are
     replaced with XML numeric character reference.
   
   If the kern.geom.confxml sysctl provides invalid XML, libgeom
   geom_xml2tree() fails and utilities using it do not work. Unsafe
   characters are common in msdosfs and cd9660 labels.
   
   PR:		kern/104389
   Submitted by:	Doug Steinwand (original version)
   Reviewed by:	pjd
   Discussed on:	freebsd-geom
   MFC after:	3 weeks
 
 Modified:
   head/sys/geom/geom_dump.c
 
 Modified: head/sys/geom/geom_dump.c
 ==============================================================================
 --- head/sys/geom/geom_dump.c	Sat Mar 20 15:30:26 2010	(r205384)
 +++ head/sys/geom/geom_dump.c	Sat Mar 20 16:16:13 2010	(r205385)
 @@ -154,6 +154,28 @@ g_conftxt(void *p, int flag)
  
  
  static void
 +g_conf_print_escaped(struct sbuf *sb, const char *fmt, const char *str)
 +{
 +	struct sbuf *s;
 +	const u_char *c;
 +
 +	s = sbuf_new_auto();
 +
 +	for (c = str; *c != '\0'; c++) {
 +		if (*c == '&' || *c == '<' || *c == '>' ||
 +		    *c == '\'' || *c == '"' || *c > 0x7e)
 +			sbuf_printf(s, "&#x%X;", *c);
 +		else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
 +			sbuf_putc(s, *c);
 +		else
 +			sbuf_putc(s, '?');
 +	}
 +	sbuf_finish(s);
 +	sbuf_printf(sb, fmt, sbuf_data(s));
 +	sbuf_delete(s);
 +}
 +
 +static void
  g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
  {
  
 @@ -181,7 +203,7 @@ g_conf_provider(struct sbuf *sb, struct 
  	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  	    pp->acr, pp->acw, pp->ace);
 -	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 +	g_conf_print_escaped(sb, "\t  <name>%s</name>\n", pp->name);
  	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  	    (intmax_t)pp->mediasize);
  	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
 @@ -208,7 +230,7 @@ g_conf_geom(struct sbuf *sb, struct g_ge
  
  	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
 -	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
 +	g_conf_print_escaped(sb, "      <name>%s</name>\n", gp->name);
  	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  	if (gp->flags & G_GEOM_WITHER)
  		sbuf_printf(sb, "      <wither/>\n");
 @@ -237,7 +259,7 @@ g_conf_class(struct sbuf *sb, struct g_c
  	struct g_geom *gp2;
  
  	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
 -	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
 +	g_conf_print_escaped(sb, "    <name>%s</name>\n", mp->name);
  	LIST_FOREACH(gp2, &mp->geom, geom) {
  		if (gp != NULL && gp != gp2)
  			continue;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jh 
State-Changed-When: Sat Mar 20 16:26:28 UTC 2010 
State-Changed-Why:  
Patched in head (r205385). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=104389 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/104389: commit references a PR
Date: Sat, 10 Apr 2010 14:29:18 +0000 (UTC)

 Author: jh
 Date: Sat Apr 10 14:28:58 2010
 New Revision: 206458
 URL: http://svn.freebsd.org/changeset/base/206458
 
 Log:
   MFC r205385:
   
   Escape characters unsafe for XML output in GEOM class, instance and
   provider names.
   
   - Characters in range 0x01-0x1f except '\t', '\n', and '\r' are replaced
     with '?'. Those characters are disallowed in XML.
   - '&', '<', '>', '\'', '"' and characters in range 0x7f-0xff are
     replaced with XML numeric character reference.
   
   If the kern.geom.confxml sysctl provides invalid XML, libgeom
   geom_xml2tree() fails and utilities using it do not work. Unsafe
   characters are common in msdosfs and cd9660 labels.
   
   PR:		kern/104389
 
 Modified:
   stable/8/sys/geom/geom_dump.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
   stable/8/sys/dev/xen/xenpci/   (props changed)
 
 Modified: stable/8/sys/geom/geom_dump.c
 ==============================================================================
 --- stable/8/sys/geom/geom_dump.c	Sat Apr 10 13:54:00 2010	(r206457)
 +++ stable/8/sys/geom/geom_dump.c	Sat Apr 10 14:28:58 2010	(r206458)
 @@ -154,6 +154,28 @@ g_conftxt(void *p, int flag)
  
  
  static void
 +g_conf_print_escaped(struct sbuf *sb, const char *fmt, const char *str)
 +{
 +	struct sbuf *s;
 +	const u_char *c;
 +
 +	s = sbuf_new_auto();
 +
 +	for (c = str; *c != '\0'; c++) {
 +		if (*c == '&' || *c == '<' || *c == '>' ||
 +		    *c == '\'' || *c == '"' || *c > 0x7e)
 +			sbuf_printf(s, "&#x%X;", *c);
 +		else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
 +			sbuf_putc(s, *c);
 +		else
 +			sbuf_putc(s, '?');
 +	}
 +	sbuf_finish(s);
 +	sbuf_printf(sb, fmt, sbuf_data(s));
 +	sbuf_delete(s);
 +}
 +
 +static void
  g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
  {
  
 @@ -181,7 +203,7 @@ g_conf_provider(struct sbuf *sb, struct 
  	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  	    pp->acr, pp->acw, pp->ace);
 -	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 +	g_conf_print_escaped(sb, "\t  <name>%s</name>\n", pp->name);
  	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  	    (intmax_t)pp->mediasize);
  	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
 @@ -204,7 +226,7 @@ g_conf_geom(struct sbuf *sb, struct g_ge
  
  	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
 -	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
 +	g_conf_print_escaped(sb, "      <name>%s</name>\n", gp->name);
  	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  	if (gp->flags & G_GEOM_WITHER)
  		sbuf_printf(sb, "      <wither/>\n");
 @@ -233,7 +255,7 @@ g_conf_class(struct sbuf *sb, struct g_c
  	struct g_geom *gp2;
  
  	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
 -	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
 +	g_conf_print_escaped(sb, "    <name>%s</name>\n", mp->name);
  	LIST_FOREACH(gp2, &mp->geom, geom) {
  		if (gp != NULL && gp != gp2)
  			continue;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/104389: commit references a PR
Date: Thu, 22 Apr 2010 14:55:15 +0000 (UTC)

 Author: jh
 Date: Thu Apr 22 14:54:54 2010
 New Revision: 207065
 URL: http://svn.freebsd.org/changeset/base/207065
 
 Log:
   MFC r205385:
   
   Escape characters unsafe for XML output in GEOM class, instance and
   provider names.
   
   - Characters in range 0x01-0x1f except '\t', '\n', and '\r' are replaced
     with '?'. Those characters are disallowed in XML.
   - '&', '<', '>', '\'', '"' and characters in range 0x7f-0xff are
     replaced with XML numeric character reference.
   
   If the kern.geom.confxml sysctl provides invalid XML, libgeom
   geom_xml2tree() fails and utilities using it do not work. Unsafe
   characters are common in msdosfs and cd9660 labels.
   
   PR:		kern/104389
 
 Modified:
   stable/7/sys/geom/geom_dump.c
 Directory Properties:
   stable/7/sys/   (props changed)
   stable/7/sys/cddl/contrib/opensolaris/   (props changed)
   stable/7/sys/contrib/dev/acpica/   (props changed)
   stable/7/sys/contrib/pf/   (props changed)
 
 Modified: stable/7/sys/geom/geom_dump.c
 ==============================================================================
 --- stable/7/sys/geom/geom_dump.c	Thu Apr 22 14:11:59 2010	(r207064)
 +++ stable/7/sys/geom/geom_dump.c	Thu Apr 22 14:54:54 2010	(r207065)
 @@ -154,6 +154,28 @@ g_conftxt(void *p, int flag)
  
  
  static void
 +g_conf_print_escaped(struct sbuf *sb, const char *fmt, const char *str)
 +{
 +	struct sbuf *s;
 +	const u_char *c;
 +
 +	s = sbuf_new_auto();
 +
 +	for (c = str; *c != '\0'; c++) {
 +		if (*c == '&' || *c == '<' || *c == '>' ||
 +		    *c == '\'' || *c == '"' || *c > 0x7e)
 +			sbuf_printf(s, "&#x%X;", *c);
 +		else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
 +			sbuf_putc(s, *c);
 +		else
 +			sbuf_putc(s, '?');
 +	}
 +	sbuf_finish(s);
 +	sbuf_printf(sb, fmt, sbuf_data(s));
 +	sbuf_delete(s);
 +}
 +
 +static void
  g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
  {
  
 @@ -181,7 +203,7 @@ g_conf_provider(struct sbuf *sb, struct 
  	sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  	sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  	    pp->acr, pp->acw, pp->ace);
 -	sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
 +	g_conf_print_escaped(sb, "\t  <name>%s</name>\n", pp->name);
  	sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  	    (intmax_t)pp->mediasize);
  	sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
 @@ -204,7 +226,7 @@ g_conf_geom(struct sbuf *sb, struct g_ge
  
  	sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  	sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
 -	sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
 +	g_conf_print_escaped(sb, "      <name>%s</name>\n", gp->name);
  	sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  	if (gp->flags & G_GEOM_WITHER)
  		sbuf_printf(sb, "      <wither/>\n");
 @@ -233,7 +255,7 @@ g_conf_class(struct sbuf *sb, struct g_c
  	struct g_geom *gp2;
  
  	sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
 -	sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
 +	g_conf_print_escaped(sb, "    <name>%s</name>\n", mp->name);
  	LIST_FOREACH(gp2, &mp->geom, geom) {
  		if (gp != NULL && gp != gp2)
  			continue;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jh 
State-Changed-When: Wed Aug 11 18:20:41 UTC 2010 
State-Changed-Why:  
Fixed in head, stable/8 and stable/7. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=104389 
>Unformatted:
