From owner-freebsd-geom@FreeBSD.ORG Wed Mar 7 15:40:15 2007 Return-Path: X-Original-To: freebsd-geom@hub.freebsd.org Delivered-To: freebsd-geom@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1058016A402 for ; Wed, 7 Mar 2007 15:40:15 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id B456D13C4A7 for ; Wed, 7 Mar 2007 15:40:14 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l27FeE6G002479 for ; Wed, 7 Mar 2007 15:40:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l27FeEbu002478; Wed, 7 Mar 2007 15:40:14 GMT (envelope-from gnats) Date: Wed, 7 Mar 2007 15:40:14 GMT Message-Id: <200703071540.l27FeEbu002478@freefall.freebsd.org> To: freebsd-geom@FreeBSD.org From: doug steinwand Cc: 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 Reply-To: doug steinwand 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:40:15 -0000 The following reply was made to PR kern/104389; it has been noted by GNATS. From: doug steinwand To: Dennis Berger 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 [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--