From 5802a083b48218361c5c59da3cd43c01274b462d Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Tue, 8 Nov 2022 01:44:41 -0500 Subject: [PATCH] scanner: Fail on more invalid XML files These situations can happen if the XML is not valid according to the Wayland DTD. Signed-off-by: Demi Marie Obenour --- src/scanner.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/scanner.c b/src/scanner.c index 92acab1c..6ac67243 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -784,6 +784,9 @@ start_element(void *data, const char *element_name, const char **atts) if (version == 0) fail(&ctx->loc, "no interface version given"); + if (atts[4]) + fail(&ctx->loc, "unexpected attribute on interface"); + validate_identifier(&ctx->loc, name, STANDALONE_IDENT); interface = create_interface(ctx->loc, name, version); ctx->interface = interface; @@ -924,6 +927,9 @@ start_element(void *data, const char *element_name, const char **atts) } else if (strcmp(element_name, "description") == 0) { if (summary == NULL) fail(&ctx->loc, "description without summary"); + /* must be valid since summary attribute present */ + if (atts[2]) + fail(&ctx->loc, "description with non-summary attribute"); description = xzalloc(sizeof *description); description->summary = xstrdup(summary); @@ -939,6 +945,8 @@ start_element(void *data, const char *element_name, const char **atts) else ctx->protocol->description = description; ctx->description = description; + } else { + fail(&ctx->loc, "unknown element %s", element_name); } }