[PATCH] virdomainjob: check if cb is not NULL before dereferencing

Kristina Hanicova posted 1 patch 1 year, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b3d5926869b9324a76cfb774dd2c562fa9900b12.1664538667.git.khanicov@redhat.com
src/conf/virdomainjob.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] virdomainjob: check if cb is not NULL before dereferencing
Posted by Kristina Hanicova 1 year, 6 months ago
The callback struct does not always have to be set which could
cause a dereferencing of a NULL pointer. This patch adds check
against NULL in missing places before dereferencing.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
---
 src/conf/virdomainjob.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf/virdomainjob.c b/src/conf/virdomainjob.c
index 0c67e84ef1..ca0215bc23 100644
--- a/src/conf/virdomainjob.c
+++ b/src/conf/virdomainjob.c
@@ -626,7 +626,7 @@ virDomainObjEndJob(virDomainObj *obj)
 
     virDomainObjResetJob(obj->job);
 
-    if (virDomainTrackJob(job) &&
+    if (virDomainTrackJob(job) && obj->job->cb &&
         obj->job->cb->saveStatusPrivate)
         obj->job->cb->saveStatusPrivate(obj);
     /* We indeed need to wake up ALL threads waiting because
@@ -662,7 +662,7 @@ virDomainObjEndAsyncJob(virDomainObj *obj)
               obj, obj->def->name);
 
     virDomainObjResetAsyncJob(obj->job);
-    if (obj->job->cb->saveStatusPrivate)
+    if (obj->job->cb && obj->job->cb->saveStatusPrivate)
         obj->job->cb->saveStatusPrivate(obj);
     virCondBroadcast(&obj->job->asyncCond);
 }
-- 
2.37.3
Re: [PATCH] virdomainjob: check if cb is not NULL before dereferencing
Posted by Ján Tomko 1 year, 6 months ago
On a Friday in 2022, Kristina Hanicova wrote:
>The callback struct does not always have to be set which could
>cause a dereferencing of a NULL pointer. This patch adds check
>against NULL in missing places before dereferencing.
>
>Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
>---
> src/conf/virdomainjob.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

I will push this after `aplay victory.wav` exits:
https://gitlab.com/janotomko/libvirt/-/pipelines/655155931

Jano