conf: Increase virNetDevBandwidthParse intelligence

There's this function virNetDevBandwidthParse which parses the
bandwidth XML snippet. But it's not clever much. For the
following XML it allocates the virNetDevBandwidth structure even
though it's completely empty:

    <bandwidth>
    </bandwidth>

Later in the code there are some places where we check if
bandwidth was set or not. And since we obtained pointer from the
parsing function we think that it is when in fact it isn't.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik
2015-01-13 18:24:15 +01:00
parent 0ecd685109
commit a605025c21
5 changed files with 42 additions and 32 deletions
+6 -6
View File
@@ -43,6 +43,7 @@ struct testSetStruct {
#define PARSE(xml, var) \
do { \
int rc; \
xmlDocPtr doc; \
xmlXPathContextPtr ctxt = NULL; \
\
@@ -54,11 +55,12 @@ struct testSetStruct {
&ctxt))) \
goto cleanup; \
\
(var) = virNetDevBandwidthParse(ctxt->node, \
VIR_DOMAIN_NET_TYPE_NETWORK); \
rc = virNetDevBandwidthParse(&(var), \
ctxt->node, \
VIR_DOMAIN_NET_TYPE_NETWORK); \
xmlFreeDoc(doc); \
xmlXPathFreeContext(ctxt); \
if (!(var)) \
if (rc < 0) \
goto cleanup; \
} while (0)
@@ -127,9 +129,7 @@ mymain(void)
DO_TEST_SET(NULL, NULL);
DO_TEST_SET(("<bandwidth/>"),
(TC " qdisc del dev eth0 root\n"
TC " qdisc del dev eth0 ingress\n"));
DO_TEST_SET("<bandwidth/>", NULL);
DO_TEST_SET(("<bandwidth>"
" <inbound average='1024'/>"