Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
htsbuf_append_and_escape_xml: filter out invalid XML 1.0 characters, …
…fixes #3942
  • Loading branch information
perexg committed Aug 20, 2016
1 parent fb99e1a commit 3de3244
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/htsbuf.c
Expand Up @@ -352,12 +352,16 @@ htsbuf_append_and_escape_xml(htsbuf_queue_t *hq, const char *s)
{
const char *c = s;
const char *e = s + strlen(s);
const char *esc;
int h;

if(e == s)
return;

while(1) {
const char *esc;
switch(*c++) {
h = *c++;

switch(h) {
case '<': esc = "&lt;"; break;
case '>': esc = "&gt;"; break;
case '&': esc = "&amp;"; break;
Expand All @@ -370,6 +374,10 @@ htsbuf_append_and_escape_xml(htsbuf_queue_t *hq, const char *s)
htsbuf_append(hq, s, c - s - 1);
htsbuf_append_str(hq, esc);
s = c;
} else if (h < 0x20 && h != 0x09 && h != 0x0a && h != 0x0d) {
/* allow XML 1.0 valid characters only */
htsbuf_append(hq, s, c - s - 1);
s = c;
}

if(c == e) {
Expand Down

0 comments on commit 3de3244

Please sign in to comment.