From owner-freebsd-geom@FreeBSD.ORG Sat Mar 13 08:35:57 2010 Return-Path: Delivered-To: freebsd-geom@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 38BA2106566C; Sat, 13 Mar 2010 08:35:57 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from gw01.mail.saunalahti.fi (gw01.mail.saunalahti.fi [195.197.172.115]) by mx1.freebsd.org (Postfix) with ESMTP id BF8818FC15; Sat, 13 Mar 2010 08:35:56 +0000 (UTC) Received: from a91-153-117-195.elisa-laajakaista.fi (a91-153-117-195.elisa-laajakaista.fi [91.153.117.195]) by gw01.mail.saunalahti.fi (Postfix) with SMTP id 3E46615146B; Sat, 13 Mar 2010 10:35:52 +0200 (EET) Date: Sat, 13 Mar 2010 10:35:52 +0200 From: Jaakko Heinonen To: freebsd-geom@FreeBSD.org Message-ID: <20100313083551.GB966@a91-153-117-195.elisa-laajakaista.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Cc: pjd@FreeBSD.org, phk@FreeBSD.org Subject: Escape unsafe characters for kern.geom.confxml XML dump 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: Sat, 13 Mar 2010 08:35:57 -0000 Hi, I intend to commit following patch unless there are objections. I have seen the problem commonly reported by FreeBSD users. --- 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 Submitter by: Doug Steinwand (original version) %%% Index: sys/geom/geom_dump.c =================================================================== --- sys/geom/geom_dump.c (revision 205081) +++ sys/geom/geom_dump.c (working copy) @@ -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 \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); + g_conf_print_escaped(sb, "\t %s\n", pp->name); sbuf_printf(sb, "\t %jd\n", (intmax_t)pp->mediasize); sbuf_printf(sb, "\t %u\n", pp->sectorsize); @@ -208,7 +230,7 @@ g_conf_geom(struct sbuf *sb, struct g_ge sbuf_printf(sb, " \n", gp); sbuf_printf(sb, " \n", gp->class); - sbuf_printf(sb, " %s\n", gp->name); + g_conf_print_escaped(sb, " %s\n", gp->name); sbuf_printf(sb, " %d\n", gp->rank); if (gp->flags & G_GEOM_WITHER) sbuf_printf(sb, " \n"); @@ -237,7 +259,7 @@ g_conf_class(struct sbuf *sb, struct g_c struct g_geom *gp2; sbuf_printf(sb, " \n", mp); - sbuf_printf(sb, " %s\n", mp->name); + g_conf_print_escaped(sb, " %s\n", mp->name); LIST_FOREACH(gp2, &mp->geom, geom) { if (gp != NULL && gp != gp2) continue; %%% -- Jaakko