[libvirt PATCH] conf: Avoid NULL-dereference in virDomainObjGetMessages

Jiri Denemark posted 1 patch 2 years, 2 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/59ba4ef9544058844da50eba46019fcc11824304.1644584377.git.jdenemar@redhat.com
src/conf/domain_conf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[libvirt PATCH] conf: Avoid NULL-dereference in virDomainObjGetMessages
Posted by Jiri Denemark 2 years, 2 months ago
All callers currently guarantee flags passed to virDomainObjGetMessages
are either zero or contain at least one of the supported flags. But it
doesn't mean we should not check for the possibility an unknown flag was
the only one passed to virDomainObjGetMessages.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ab8f2a52cc..093b719b2c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31472,7 +31472,8 @@ virDomainObjGetMessages(virDomainObj *vm,
         }
     }
 
-    (*msgs)[nmsgs] = NULL;
+    if (*msgs)
+        (*msgs)[nmsgs] = NULL;
 
     rv = nmsgs;
 
-- 
2.35.0

Re: [libvirt PATCH] conf: Avoid NULL-dereference in virDomainObjGetMessages
Posted by Michal Prívozník 2 years, 2 months ago
On 2/11/22 13:59, Jiri Denemark wrote:
> All callers currently guarantee flags passed to virDomainObjGetMessages
> are either zero or contain at least one of the supported flags. But it
> doesn't mean we should not check for the possibility an unknown flag was
> the only one passed to virDomainObjGetMessages.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/conf/domain_conf.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>  

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

Michal