[PATCH] 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/8cf51af89d7c1deb5931cb4367f448bfffb33588.1634543920.git.pkrempa@redhat.com
There is a newer version of this series
src/conf/node_device_conf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] 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 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>
---
 src/conf/node_device_conf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 9bbff97ffd..d5e02f623d 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2178,8 +2178,9 @@ virNodeDeviceDefParse(const char *str,
     g_autoptr(virNodeDeviceDef) def = NULL;

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

     if (parserCallbacks) {
-- 
2.31.1

Re: [PATCH] virNodeDeviceDefParse: Don't call post-parse callbacks with NULL def
Posted by Michal Prívozník 2 years, 6 months ago
On 10/18/21 9:58 AM, Peter Krempa wrote:
> When parsing of the node device XML 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>
> ---
>  src/conf/node_device_conf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal