Date: Thu, 9 Jan 2014 11:13:04 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r260479 - stable/10/sys/geom Message-ID: <201401091113.s09BD4NU095274@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Thu Jan 9 11:13:03 2014 New Revision: 260479 URL: http://svnweb.freebsd.org/changeset/base/260479 Log: MFC r258683: Escape special XML chars, returned by some devices, confusing XML parsers. Modified: stable/10/sys/geom/geom_disk.c stable/10/sys/geom/geom_dump.c stable/10/sys/geom/geom_int.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/geom/geom_disk.c ============================================================================== --- stable/10/sys/geom/geom_disk.c Thu Jan 9 11:11:47 2014 (r260478) +++ stable/10/sys/geom/geom_disk.c Thu Jan 9 11:13:03 2014 (r260479) @@ -485,26 +485,36 @@ g_disk_dumpconf(struct sbuf *sb, const c bp->bio_length = DISK_IDENT_SIZE; bp->bio_data = buf; res = dp->d_getattr(bp); - sbuf_printf(sb, "%s<ident>%s</ident>\n", indent, + sbuf_printf(sb, "%s<ident>", indent); + g_conf_printf_escaped(sb, "%s", res == 0 ? buf: dp->d_ident); + sbuf_printf(sb, "</ident>\n"); bp->bio_attribute = "GEOM::lunid"; bp->bio_length = DISK_IDENT_SIZE; bp->bio_data = buf; - if (dp->d_getattr(bp) == 0) - sbuf_printf(sb, "%s<lunid>%s</lunid>\n", - indent, buf); + if (dp->d_getattr(bp) == 0) { + sbuf_printf(sb, "%s<lunid>", indent); + g_conf_printf_escaped(sb, "%s", buf); + sbuf_printf(sb, "</lunid>\n"); + } bp->bio_attribute = "GEOM::lunname"; bp->bio_length = DISK_IDENT_SIZE; bp->bio_data = buf; - if (dp->d_getattr(bp) == 0) - sbuf_printf(sb, "%s<lunname>%s</lunname>\n", - indent, buf); + if (dp->d_getattr(bp) == 0) { + sbuf_printf(sb, "%s<lunname>", indent); + g_conf_printf_escaped(sb, "%s", buf); + sbuf_printf(sb, "</lunname>\n"); + } g_destroy_bio(bp); g_free(buf); - } else - sbuf_printf(sb, "%s<ident>%s</ident>\n", indent, - dp->d_ident); - sbuf_printf(sb, "%s<descr>%s</descr>\n", indent, dp->d_descr); + } else { + sbuf_printf(sb, "%s<ident>", indent); + g_conf_printf_escaped(sb, "%s", dp->d_ident); + sbuf_printf(sb, "</ident>\n"); + } + sbuf_printf(sb, "%s<descr>", indent); + g_conf_printf_escaped(sb, "%s", dp->d_descr); + sbuf_printf(sb, "</descr>\n"); } } Modified: stable/10/sys/geom/geom_dump.c ============================================================================== --- stable/10/sys/geom/geom_dump.c Thu Jan 9 11:11:47 2014 (r260478) +++ stable/10/sys/geom/geom_dump.c Thu Jan 9 11:13:03 2014 (r260479) @@ -154,25 +154,28 @@ g_conftxt(void *p, int flag) } -static void -g_conf_print_escaped(struct sbuf *sb, const char *fmt, const char *str) +void +g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...) { struct sbuf *s; const u_char *c; + va_list ap; s = sbuf_new_auto(); + va_start(ap, fmt); + sbuf_vprintf(s, fmt, ap); + va_end(ap); + sbuf_finish(s); - for (c = str; *c != '\0'; c++) { + for (c = sbuf_data(s); *c != '\0'; c++) { if (*c == '&' || *c == '<' || *c == '>' || *c == '\'' || *c == '"' || *c > 0x7e) - sbuf_printf(s, "&#x%X;", *c); + sbuf_printf(sb, "&#x%X;", *c); else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f) - sbuf_putc(s, *c); + sbuf_putc(sb, *c); else - sbuf_putc(s, '?'); + sbuf_putc(sb, '?'); } - sbuf_finish(s); - sbuf_printf(sb, fmt, sbuf_data(s)); sbuf_delete(s); } @@ -204,7 +207,9 @@ 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); - g_conf_print_escaped(sb, "\t <name>%s</name>\n", pp->name); + sbuf_printf(sb, "\t <name>"); + g_conf_printf_escaped(sb, "%s", pp->name); + sbuf_printf(sb, "</name>\n"); sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n", (intmax_t)pp->mediasize); sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize); @@ -229,7 +234,9 @@ 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); - g_conf_print_escaped(sb, " <name>%s</name>\n", gp->name); + sbuf_printf(sb, " <name>"); + g_conf_printf_escaped(sb, "%s", gp->name); + sbuf_printf(sb, "</name>\n"); sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank); if (gp->flags & G_GEOM_WITHER) sbuf_printf(sb, " <wither/>\n"); @@ -258,7 +265,9 @@ g_conf_class(struct sbuf *sb, struct g_c struct g_geom *gp2; sbuf_printf(sb, " <class id=\"%p\">\n", mp); - g_conf_print_escaped(sb, " <name>%s</name>\n", mp->name); + sbuf_printf(sb, " <name>"); + g_conf_printf_escaped(sb, "%s", mp->name); + sbuf_printf(sb, "</name>\n"); LIST_FOREACH(gp2, &mp->geom, geom) { if (gp != NULL && gp != gp2) continue; Modified: stable/10/sys/geom/geom_int.h ============================================================================== --- stable/10/sys/geom/geom_int.h Thu Jan 9 11:11:47 2014 (r260478) +++ stable/10/sys/geom/geom_int.h Thu Jan 9 11:13:03 2014 (r260479) @@ -57,6 +57,7 @@ extern int g_debugflags; /* geom_dump.c */ void g_confxml(void *, int flag); void g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp); +void g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...); void g_confdot(void *, int flag); void g_conftxt(void *, int flag);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401091113.s09BD4NU095274>