Skip to contentSkip to conversation

mesh: Fix checks when restoring internal model state

PATCH Applied Inga Stotland 2 participants 2 messages Jul 3, 2019 – Jul 4, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mesh: Fix checks when restoring internal model state

This fixes incorrect conditional checks in restore_model_state() which could lead to dereferencing a NULL pointer.

Wrong: if (l_queue_isempty(mod->bindings) || !mod->cbs->bind) ...
Fixed: if (!l_queue_isempty(mod->bindings) && cbs->bind) ...

---
 mesh/model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mesh/model.c +1 -1
index a2b3e5c18..e4a7ba94e 100644
@@ -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)
Signature · 1 line
2.21.0
Applied
#1 lore raw

Applied

Quoted 22 lines · Inga Stotland

This fixes incorrect conditional checks in restore_model_state() which could lead to dereferencing a NULL pointer.

Wrong: if (l_queue_isempty(mod->bindings) || !mod->cbs->bind) ...
Fixed: if (!l_queue_isempty(mod->bindings) && cbs->bind) ...

---
 mesh/model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mesh/model.c +1 -1
index a2b3e5c18..e4a7ba94e 100644
@@ -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)