[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt PATCH 3/3] cpu: Fail CPU comparison in the presence of unknown elements.



On Wed, Sep 16, 2020 at 15:33:56 +0200, Tim Wiederhake wrote:
> Signed-off-by: Tim Wiederhake <twiederh redhat com>
> ---
>  src/conf/cpu_conf.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
> index dea950ce68..a2ba92ced3 100644
> --- a/src/conf/cpu_conf.c
> +++ b/src/conf/cpu_conf.c
> @@ -659,6 +659,44 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
>          def->cache->mode = mode;
>      }
>  
> +    g_clear_pointer(&nodes, g_free);
> +    if ((n = virXPathNodeSet("./@*", ctxt, &nodes)) < 0)
> +        return -1;
> +
> +    for (i = 0; i < n; i++) {
> +        if (virXMLNodeNameEqual(nodes[i], "check") ||
> +            virXMLNodeNameEqual(nodes[i], "match") ||
> +            virXMLNodeNameEqual(nodes[i], "migratable") ||
> +            virXMLNodeNameEqual(nodes[i], "mode"))
> +            continue;
> +        virReportError(VIR_ERR_XML_ERROR,
> +                       _("unrecognized attribute in cpu element: %s"),
> +                       nodes[i]->name);
> +        return -1;
> +    }
> +
> +    g_clear_pointer(&nodes, g_free);
> +    if ((n = virXPathNodeSet("./*", ctxt, &nodes)) < 0)
> +        return -1;
> +
> +    for (i = 0; i < n; i++) {
> +        if (virXMLNodeNameEqual(nodes[i], "arch") ||
> +            virXMLNodeNameEqual(nodes[i], "cache") ||
> +            virXMLNodeNameEqual(nodes[i], "counter") ||
> +            virXMLNodeNameEqual(nodes[i], "feature") ||
> +            virXMLNodeNameEqual(nodes[i], "model") ||
> +            virXMLNodeNameEqual(nodes[i], "microcode") ||
> +            virXMLNodeNameEqual(nodes[i], "numa") ||
> +            virXMLNodeNameEqual(nodes[i], "pages") ||
> +            virXMLNodeNameEqual(nodes[i], "topology") ||
> +            virXMLNodeNameEqual(nodes[i], "vendor"))
> +            continue;
> +        virReportError(VIR_ERR_XML_ERROR,
> +                       _("unrecognized element in cpu element: %s"),
> +                       nodes[i]->name);

NACK this is ugly and unscalable.

Please implement it via RNG schema validation.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]