Escape unsafe characters for kern.geom.confxml XML dump

Ivan Voras ivoras at freebsd.org
Mon Mar 15 20:49:26 UTC 2010


Jaakko Heinonen wrote:
> 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.

Go for it!

> +	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, '?');

Wouldn't it be slightly better (it's not important, really), to use HTML 
"entities" instead - &amp; &gt; &lt; &apos; &quot; ? The only benefit 
(which is why it isn't important) is that it would make it more 
human-readable.



More information about the freebsd-geom mailing list