[PATCH v2] virNodeDeviceDefParse: Don't call post-parse callbacks with NULL def

Peter Krempa posted 1 patch 2 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/83ad21cc65426b973dd2a119538aca0d50971240.1634558849.git.pkrempa@redhat.com
src/conf/node_device_conf.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH v2] virNodeDeviceDefParse: Don't call post-parse callbacks with NULL def
Posted by Peter Krempa 2 years, 6 months ago
When parsing of the node device XML fails we'd still call the post-parse
and validation callbacks which makes no sense. Additionally the
callbacks were expecting a non-NULL pointer which leads to a crash.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2014139
Fixes: d5ae634ba28
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---

v2:
 - Also handle failure of virXMLParse
 - add 'fails' into first sentence of commit message

 src/conf/node_device_conf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 9bbff97ffd..1f39e2cbfd 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2177,10 +2177,10 @@ virNodeDeviceDefParse(const char *str,
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(virNodeDeviceDef) def = NULL;

-    if ((xml = virXMLParse(filename, str, _("(node_device_definition)"), NULL, false))) {
-        def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml),
-                                        create, virt_type);
-    }
+    if (!(xml = virXMLParse(filename, str, _("(node_device_definition)"), NULL, false)) ||
+        !(def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml),
+                                          create, virt_type)))
+        return NULL;

     if (parserCallbacks) {
         int ret = 0;
-- 
2.31.1

Re: [PATCH v2] virNodeDeviceDefParse: Don't call post-parse callbacks with NULL def
Posted by Erik Skultety 2 years, 6 months ago
On Mon, Oct 18, 2021 at 02:08:41PM +0200, Peter Krempa wrote:
> When parsing of the node device XML fails we'd still call the post-parse
> and validation callbacks which makes no sense. Additionally the
> callbacks were expecting a non-NULL pointer which leads to a crash.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2014139
> Fixes: d5ae634ba28
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---

Reviewed-by: Erik Skultety <eskultet@redhat.com>