Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, uint32_t
uint32_t offset; /* read offset in input buffer */
uint32_t len; /* length of the output string (write offset in output buffer) */
uint32_t size = 0; /* size of the output buffer */
uint32_t n, u;
uint32_t n, u, c, parsed;
ly_bool ws = 1;

assert(xmlctx);
Expand Down Expand Up @@ -564,8 +564,10 @@ lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, uint32_t
in += ly_strlen_const("<![CDATA[");
assert(!offset);

/* analyze CDATA for non WS and newline chars */
for (n = 0; n < u; ++n) {
/* check the CDATA characters and analyze them for non WS and newline chars */
for (n = 0; n < u; n += parsed) {
in_aux = &in[n];
LY_CHECK_ERR_GOTO(ly_getutf8(&in_aux, &c, &parsed), LOGVAL(ctx, NULL, LY_VCODE_INCHAR, in[n]), error);
if (in[n] == '\n') {
LY_IN_NEW_LINE(xmlctx->in);
} else if (!is_xmlws(in[n])) {
Expand Down
19 changes: 19 additions & 0 deletions tests/utests/basic/test_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ test_text(void **state)
lyd_free_all(tree);
tree = NULL;

str = "<e xmlns=\"urn:test\"><![CDATA[€𠜎Øn]]></e>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_all(tree);
tree = NULL;

/* CDATA characters are checked the same as text */
str = "<e xmlns=\"urn:test\"><![CDATA[a\x01" "b]]></e>";
assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
CHECK_LOG_CTX("Invalid character 0x1.", NULL, 1);

str = "<e xmlns=\"urn:test\"><![CDATA[a\xff\xfe" "b]]></e>";
assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
CHECK_LOG_CTX("Invalid character 0xff.", NULL, 1);

str = "<e xmlns=\"urn:test\"><![CDATA[a\xf0]]></e>";
assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
CHECK_LOG_CTX("Invalid character 0xf0.", NULL, 1);

/* invalid characters in string */
str = "<e xmlns=\"urn:test\" attr=\'&#x52\'";
assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
Expand Down
Loading