summaryrefslogtreecommitdiffstats
path: root/sys/geom/geom_dump.c
diff options
context:
space:
mode:
authorjh <jh@FreeBSD.org>2010-03-20 16:16:13 +0000
committerjh <jh@FreeBSD.org>2010-03-20 16:16:13 +0000
commit8dba506a842e4b01ce43ecec136488b353b2fd1f (patch)
treed01eb2af603cd83a443079506ae64c04b5a9d24c /sys/geom/geom_dump.c
parent73dc33cf71697b5916277aae66615611caf92b28 (diff)
downloadFreeBSD-src-8dba506a842e4b01ce43ecec136488b353b2fd1f.zip
FreeBSD-src-8dba506a842e4b01ce43ecec136488b353b2fd1f.tar.gz
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
Diffstat (limited to 'sys/geom/geom_dump.c')
-rw-r--r--sys/geom/geom_dump.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/sys/geom/geom_dump.c b/sys/geom/geom_dump.c
index c804bab..d1e56d6 100644
--- a/sys/geom/geom_dump.c
+++ b/sys/geom/geom_dump.c
@@ -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 g_provider *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);
+ 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_geom *gp, struct g_provider *pp, struct g_
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_class *mp, struct g_geom *gp, struct g_pr
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;
OpenPOWER on IntegriCloud