Commit c2ea55aa authored by Nikias Bassen's avatar Nikias Bassen

xplist: Fix numerical character entity conversion

parent be2b1690
...@@ -639,6 +639,7 @@ static int unescape_entities(char *str, size_t *length) ...@@ -639,6 +639,7 @@ static int unescape_entities(char *str, size_t *length)
} }
if (str+i >= entp+1) { if (str+i >= entp+1) {
int entlen = str+i - entp; int entlen = str+i - entp;
int bytelen = 1;
if (!strncmp(entp, "amp", 3)) { if (!strncmp(entp, "amp", 3)) {
/* the '&' is already there */ /* the '&' is already there */
} else if (!strncmp(entp, "apos", 4)) { } else if (!strncmp(entp, "apos", 4)) {
...@@ -682,17 +683,20 @@ static int unescape_entities(char *str, size_t *length) ...@@ -682,17 +683,20 @@ static int unescape_entities(char *str, size_t *length)
*(entp+1) = (char)(0x80 + ((val >> 6) & 0x3F)); *(entp+1) = (char)(0x80 + ((val >> 6) & 0x3F));
*(entp+2) = (char)(0x80 + (val & 0x3F)); *(entp+2) = (char)(0x80 + (val & 0x3F));
entp+=3; entp+=3;
bytelen = 4;
} else if (val >= 0x800) { } else if (val >= 0x800) {
/* three bytes */ /* three bytes */
*(entp-1) = (char)(0xE0 + ((val >> 12) & 0xF)); *(entp-1) = (char)(0xE0 + ((val >> 12) & 0xF));
*(entp+0) = (char)(0x80 + ((val >> 6) & 0x3F)); *(entp+0) = (char)(0x80 + ((val >> 6) & 0x3F));
*(entp+1) = (char)(0x80 + (val & 0x3F)); *(entp+1) = (char)(0x80 + (val & 0x3F));
entp+=2; entp+=2;
bytelen = 3;
} else if (val >= 0x80) { } else if (val >= 0x80) {
/* two bytes */ /* two bytes */
*(entp-1) = (char)(0xC0 + ((val >> 6) & 0x1F)); *(entp-1) = (char)(0xC0 + ((val >> 6) & 0x1F));
*(entp+0) = (char)(0x80 + (val & 0x3F)); *(entp+0) = (char)(0x80 + (val & 0x3F));
entp++; entp++;
bytelen = 2;
} else { } else {
/* one byte */ /* one byte */
*(entp-1) = (char)(val & 0x7F); *(entp-1) = (char)(val & 0x7F);
...@@ -702,8 +706,8 @@ static int unescape_entities(char *str, size_t *length) ...@@ -702,8 +706,8 @@ static int unescape_entities(char *str, size_t *length)
return -1; return -1;
} }
memmove(entp, str+i+1, len - i); memmove(entp, str+i+1, len - i);
i -= entlen; i -= entlen+1 - bytelen;
len -= (entlen+1); len -= entlen+2 - bytelen;
continue; continue;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment