From b39e45c48d12538366cb7b27735f3fcdc34c768d Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Sat, 10 Aug 2024 18:57:25 -0400 Subject: [PATCH] scanner: Reject attributes that are not valid for an element This would be caught by the DTD but DTD validation is not fatal by default. Signed-off-by: Demi Marie Obenour --- src/scanner.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/scanner.c b/src/scanner.c index 241755b6..82c51443 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -770,22 +770,27 @@ start_element(void *data, const char *element_name, const char **atts) allow_null = atts[i + 1]; else if (strcmp(atts[i], "enum") == 0) enumeration_name = atts[i + 1]; - else if (strcmp(atts[i], "bitfield") == 0) + else if (strcmp(atts[i], "bitfield") == 0) { + if (strcmp(element_name, "enum")) + fail(&ctx->loc, "bitfield attribute only valid on enum element"); bitfield = atts[i + 1]; - else + } else { fail(&ctx->loc, "invalid attribute name (%s)", atts[i]); + } } ctx->character_data_length = 0; if (strcmp(element_name, "protocol") == 0) { if (name == NULL) fail(&ctx->loc, "no protocol name given"); - + if (atts[2]) + fail(&ctx->loc, "Unexpected attribute for protocol element"); validate_identifier(&ctx->loc, name, STANDALONE_IDENT); ctx->protocol->name = xstrdup(name); ctx->protocol->uppercase_name = uppercase_dup(name); } else if (strcmp(element_name, "copyright") == 0) { - + if (atts[0]) + fail(&ctx->loc, "copyright element takes no attributes"); } else if (strcmp(element_name, "interface") == 0) { if (name == NULL) fail(&ctx->loc, "no interface name given");