[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/6] virDomainFormatSchedDef: Handle case when func returns NULL



As unlikely as it might seem, func passed to this function can
return NULL. And in some cases it indeed does so:
virDomainDefGetVcpuSched and virDomainDefGetIOThreadSched.
However, the function I'm fixing blindly dereference value func
returned thus leading to SIGSEGV.

conf/domain_conf.c: In function 'virDomainDefFormatInternal':
conf/domain_conf.c:22155:22: error: potential null pointer dereference [-Werror=null-dereference]
             if (sched->policy == i)
                 ~~~~~^~~~~~~~
conf/domain_conf.c:22184:26: error: potential null pointer dereference [-Werror=null-dereference]
                 priority = sched->priority;
                 ~~~~~~~~~^~~~~~~~~~~~~~~~~
conf/domain_conf.c:22190:30: error: potential null pointer dereference [-Werror=null-dereference]
                     if (sched->priority == priority)
                         ~~~~~^~~~~~~~~~
conf/domain_conf.c:22155:22: error: potential null pointer dereference [-Werror=null-dereference]
             if (sched->policy == i)
                 ~~~~~^~~~~~~~
conf/domain_conf.c:22184:26: error: potential null pointer dereference [-Werror=null-dereference]
                 priority = sched->priority;
                 ~~~~~~~~~^~~~~~~~~~~~~~~~~
conf/domain_conf.c:22190:30: error: potential null pointer dereference [-Werror=null-dereference]
                     if (sched->priority == priority)
                         ~~~~~^~~~~~~~~~

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/conf/domain_conf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 568c699..3daeb1e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -22152,7 +22152,7 @@ virDomainFormatSchedDef(virDomainDefPtr def,
         while ((next = virBitmapNextSetBit(resourceMap, next)) > -1) {
             sched = func(def, next);
 
-            if (sched->policy == i)
+            if (sched && sched->policy == i)
                 ignore_value(virBitmapSetBit(schedMap, next));
         }
 
@@ -22180,14 +22180,17 @@ virDomainFormatSchedDef(virDomainDefPtr def,
                 /* we need to find a subset of vCPUs with the given scheduler
                  * that share the priority */
                 nextprio = virBitmapNextSetBit(schedMap, -1);
-                sched = func(def, nextprio);
+
+                if (!(sched = func(def, nextprio)))
+                    goto cleanup;
+
                 priority = sched->priority;
 
                 ignore_value(virBitmapSetBit(prioMap, nextprio));
 
                 while ((nextprio = virBitmapNextSetBit(schedMap, nextprio)) > -1) {
                     sched = func(def, nextprio);
-                    if (sched->priority == priority)
+                    if (sched && sched->priority == priority)
                         ignore_value(virBitmapSetBit(prioMap, nextprio));
                 }
 
-- 
2.8.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]