From owner-freebsd-geom@FreeBSD.ORG Wed Mar 7 15:37:08 2007 Return-Path: X-Original-To: freebsd-geom@freebsd.org Delivered-To: freebsd-geom@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 852ED16A401 for ; Wed, 7 Mar 2007 15:37:08 +0000 (UTC) (envelope-from dzs-pr@dzs.fx.org) Received: from eagle.ul.net (dsl081-037-111.lax1.dsl.speakeasy.net [64.81.37.111]) by mx1.freebsd.org (Postfix) with SMTP id 4E2B113C49D for ; Wed, 7 Mar 2007 15:37:08 +0000 (UTC) (envelope-from dzs-pr@dzs.fx.org) Received: (qmail 56910 invoked by uid 1001); 7 Mar 2007 07:10:26 -0800 Date: Wed, 7 Mar 2007 07:10:26 -0800 From: doug steinwand To: Dennis Berger Message-ID: <20070307151026.GA55527@dzs.fx.org> References: <45ED8E88.5080400@nipsi.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="PNTmBPCT7hxwcZjr" Content-Disposition: inline In-Reply-To: <45ED8E88.5080400@nipsi.de> Cc: dzs-pr@dzs.fx.org, bug-followup@FreeBSD.org, freebsd-geom@freebsd.org Subject: Re: kern/104389: [geom] [patch] sys/geom/geom_dump.c doesn't encode XML entities X-BeenThere: freebsd-geom@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: GEOM-specific discussions and implementations List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Mar 2007 15:37:08 -0000 --PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Dennis Berger [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 #include +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 \n", pp->geom); sbuf_printf(sb, "\t r%dw%de%d\n", pp->acr, pp->acw, pp->ace); - sbuf_printf(sb, "\t %s\n", pp->name); + encode_bytes(sb, "\t %s\n", pp->name, -1); sbuf_printf(sb, "\t %jd\n", (intmax_t)pp->mediasize); sbuf_printf(sb, "\t %u\n", pp->sectorsize); @@ -205,7 +230,7 @@ sbuf_printf(sb, " \n", gp); sbuf_printf(sb, " \n", gp->class); - sbuf_printf(sb, " %s\n", gp->name); + encode_bytes(sb, " %s\n", gp->name, -1); sbuf_printf(sb, " %d\n", gp->rank); if (gp->flags & G_GEOM_WITHER) sbuf_printf(sb, " \n"); @@ -234,7 +259,7 @@ struct g_geom *gp2; sbuf_printf(sb, " \n", mp); - sbuf_printf(sb, " %s\n", mp->name); + encode_bytes(sb, " %s\n", mp->name, -1); LIST_FOREACH(gp2, &mp->geom, geom) { if (gp != NULL && gp != gp2) continue; --PNTmBPCT7hxwcZjr--