sync XML fixes - frontends - front-ends for some sites (experiment)
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 3bd1b33c5fd37216f8a721d9fac3148345365c0f
(DIR) parent 3294b8cba72843f441445c1e6608e9d7477453db
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 22 Jan 2021 13:33:48 +0100
sync XML fixes
Diffstat:
M xml.c | 21 +++++++++++----------
M xml.h | 6 ++++--
2 files changed, 15 insertions(+), 12 deletions(-)
---
(DIR) diff --git a/xml.c b/xml.c
@@ -147,7 +147,7 @@ xml_parsecomment(XMLParser *x)
x->xmlcommentstart(x);
while ((c = GETNEXT()) != EOF) {
if (c == '-' || c == '>') {
- if (x->xmlcomment) {
+ if (x->xmlcomment && datalen) {
x->data[datalen] = '\0';
x->xmlcomment(x, x->data, datalen);
datalen = 0;
@@ -196,7 +196,7 @@ xml_parsecdata(XMLParser *x)
x->xmlcdatastart(x);
while ((c = GETNEXT()) != EOF) {
if (c == ']' || c == '>') {
- if (x->xmlcdata) {
+ if (x->xmlcdata && datalen) {
x->data[datalen] = '\0';
x->xmlcdata(x, x->data, datalen);
datalen = 0;
@@ -295,7 +295,7 @@ namedentitytostr(const char *e, char *buf, size_t bufsiz)
return 1;
}
}
- return 0;
+ return -1;
}
static int
@@ -312,12 +312,13 @@ numericentitytostr(const char *e, char *buf, size_t bufsiz)
errno = 0;
/* hex (16) or decimal (10) */
if (*e == 'x')
- l = strtoul(e + 1, &end, 16);
+ l = strtol(++e, &end, 16);
else
- l = strtoul(e, &end, 10);
- /* invalid value or not a well-formed entity or too high codepoint */
- if (errno || *end != ';' || l > 0x10FFFF)
- return 0;
+ l = strtol(e, &end, 10);
+ /* invalid value or not a well-formed entity or invalid code point */
+ if (errno || e == end || *end != ';' || l < 0 || l > 0x10ffff ||
+ (l >= 0xd800 && l <= 0xdffff))
+ return -1;
len = codepointtoutf8(l, buf);
buf[len] = '\0';
@@ -325,13 +326,13 @@ numericentitytostr(const char *e, char *buf, size_t bufsiz)
}
/* convert named- or numeric entity string to buffer string
- * returns byte-length of string. */
+ * returns byte-length of string or -1 on failure. */
int
xml_entitytostr(const char *e, char *buf, size_t bufsiz)
{
/* doesn't start with & */
if (e[0] != '&')
- return 0;
+ return -1;
/* numeric entity */
if (e[1] == '#')
return numericentitytostr(e + 2, buf, bufsiz);
(DIR) diff --git a/xml.h b/xml.h
@@ -1,5 +1,7 @@
-#ifndef _XML_H
-#define _XML_H
+#ifndef _XML_H_
+#define _XML_H_
+
+#include <stdio.h>
typedef struct xmlparser {
/* handlers */