Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Apr 2010 14:54:54 +0000 (UTC)
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r207065 - stable/7/sys/geom
Message-ID:  <201004221454.o3MEssYE008949@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004221454.o3MEssYE008949>