mesh: Fix checks when restoring internal model state
authorInga Stotland <inga.stotland@intel.com>
Wed, 3 Jul 2019 20:53:41 +0000 (13:53 -0700)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 15:20:30 +0000 (20:50 +0530)
This fixes incorrect conditional checks in restore_model_state()
which could lead to dereferencing a NULL pointer.

Change-Id: I65631b3cd22c9e5f5e43aa62e093c227182749b8
Wrong: if (l_queue_isempty(mod->bindings) || !mod->cbs->bind) ...
Fixed: if (!l_queue_isempty(mod->bindings) && cbs->bind) ...
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/model.c

index a2b3e5c..e4a7ba9 100644 (file)
@@ -1077,7 +1077,7 @@ static void restore_model_state(struct mesh_model *mod)
        if (!cbs)
                return;
 
-       if (l_queue_isempty(mod->bindings) || !mod->cbs->bind) {
+       if (!l_queue_isempty(mod->bindings) && cbs->bind) {
                for (b = l_queue_get_entries(mod->bindings); b; b = b->next) {
                        if (cbs->bind(L_PTR_TO_UINT(b->data), ACTION_ADD) !=
                                                        MESH_STATUS_SUCCESS)