svn commit: r260480 - stable/9/sys/geom

Alexander Motin mav at FreeBSD.org
Thu Jan 9 11:15:06 UTC 2014


Author: mav
Date: Thu Jan  9 11:15:05 2014
New Revision: 260480
URL: http://svnweb.freebsd.org/changeset/base/260480

Log:
  MFC r258683:
  Escape special XML chars, returned by some devices, confusing XML parsers.

Modified:
  stable/9/sys/geom/geom_disk.c
  stable/9/sys/geom/geom_dump.c
  stable/9/sys/geom/geom_int.h
Directory Properties:
  stable/9/   (props changed)
  stable/9/sys/   (props changed)

Modified: stable/9/sys/geom/geom_disk.c
==============================================================================
--- stable/9/sys/geom/geom_disk.c	Thu Jan  9 11:13:03 2014	(r260479)
+++ stable/9/sys/geom/geom_disk.c	Thu Jan  9 11:15:05 2014	(r260480)
@@ -458,26 +458,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/9/sys/geom/geom_dump.c
==============================================================================
--- stable/9/sys/geom/geom_dump.c	Thu Jan  9 11:13:03 2014	(r260479)
+++ stable/9/sys/geom/geom_dump.c	Thu Jan  9 11:15:05 2014	(r260480)
@@ -153,25 +153,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);
 }
 
@@ -203,7 +206,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);
@@ -228,7 +233,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");
@@ -257,7 +264,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/9/sys/geom/geom_int.h
==============================================================================
--- stable/9/sys/geom/geom_int.h	Thu Jan  9 11:13:03 2014	(r260479)
+++ stable/9/sys/geom/geom_int.h	Thu Jan  9 11:15:05 2014	(r260480)
@@ -54,6 +54,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);
 


More information about the svn-src-stable-9 mailing list